Skip to content

Commit

Permalink
ran php-cs-fixer on everything except extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
nineinchnick committed Feb 20, 2015
1 parent 7a8fe94 commit 2cbf0c3
Show file tree
Hide file tree
Showing 94 changed files with 5,041 additions and 4,834 deletions.
446 changes: 224 additions & 222 deletions UsrModule.php

Large diffs are not rendered by default.

98 changes: 54 additions & 44 deletions commands/UsrCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,26 @@ class UsrCommand extends CConsoleCommand
{
public function actionPassword($count = 1, $length = null, $extra_digit = null, $extra_char = null)
{
$usrModule = Yii::app()->getModule('usr');
if ($length === null)
$length = $usrModule->dicewareLength;
if ($extra_digit === null)
$extra_digit = $usrModule->dicewareExtraDigit;
if ($extra_char === null)
$extra_char = $usrModule->dicewareExtraChar;
$usrModule = Yii::app()->getModule('usr');
if ($length === null) {
$length = $usrModule->dicewareLength;
}
if ($extra_digit === null) {
$extra_digit = $usrModule->dicewareExtraDigit;
}
if ($extra_char === null) {
$extra_char = $usrModule->dicewareExtraChar;
}

require dirname(__FILE__) . '/../extensions/diceware/Diceware.php';
$diceware = new \nineinchnick\diceware\Diceware(Yii::app()->language);
for ($i = 0; $i < $count; $i++)
echo $diceware->get_phrase($length, $extra_digit, $extra_char) . "\n";
}
require dirname(__FILE__).'/../extensions/diceware/Diceware.php';
$diceware = new \nineinchnick\diceware\Diceware(Yii::app()->language);
for ($i = 0; $i < $count; $i++) {
echo $diceware->get_phrase($length, $extra_digit, $extra_char)."\n";
}
}

/**
* usr.manage
* usr.manage
* |-usr.create
* |-usr.read
* |-usr.update
Expand All @@ -32,15 +36,15 @@ public function actionPassword($count = 1, $length = null, $extra_digit = null,
public function getTemplateAuthItems()
{
return array(
array('name'=> 'usr.manage', 'child' => null, 'type'=>CAuthItem::TYPE_TASK),
array('name'=> 'usr.create', 'child' => 'usr.manage'),
array('name'=> 'usr.read', 'child' => 'usr.manage'),
array('name'=> 'usr.update', 'child' => 'usr.manage'),
array('name'=> 'usr.update.status', 'child' => 'usr.update'),
array('name'=> 'usr.update.auth', 'child' => 'usr.update'),
array('name'=> 'usr.update.attributes','child' => 'usr.update'),
array('name'=> 'usr.update.password', 'child' => 'usr.update'),
array('name'=> 'usr.delete', 'child' => 'usr.manage'),
array('name' => 'usr.manage', 'child' => null, 'type' => CAuthItem::TYPE_TASK),
array('name' => 'usr.create', 'child' => 'usr.manage'),
array('name' => 'usr.read', 'child' => 'usr.manage'),
array('name' => 'usr.update', 'child' => 'usr.manage'),
array('name' => 'usr.update.status', 'child' => 'usr.update'),
array('name' => 'usr.update.auth', 'child' => 'usr.update'),
array('name' => 'usr.update.attributes','child' => 'usr.update'),
array('name' => 'usr.update.password', 'child' => 'usr.update'),
array('name' => 'usr.delete', 'child' => 'usr.manage'),
);
}

Expand All @@ -61,50 +65,51 @@ public function getTemplateAuthItemDescriptions()

public function actionCreateAuthItems()
{
$auth = Yii::app()->authManager;
$auth = Yii::app()->authManager;

$newAuthItems = array();
$descriptions = $this->getTemplateAuthItemDescriptions();
foreach($this->getTemplateAuthItems() as $template) {
foreach ($this->getTemplateAuthItems() as $template) {
$newAuthItems[$template['name']] = $template;
}
$existingAuthItems = $auth->getAuthItems();
foreach($existingAuthItems as $name=>$existingAuthItem) {
if (isset($newAuthItems[$name]))
$existingAuthItems = $auth->getAuthItems();
foreach ($existingAuthItems as $name => $existingAuthItem) {
if (isset($newAuthItems[$name])) {
unset($newAuthItems[$name]);
}
}
foreach($newAuthItems as $template) {
$type = isset($template['type']) ? $template['type'] : CAuthItem::TYPE_OPERATION;
$bizRule = isset($template['bizRule']) ? $template['bizRule'] : null;
foreach ($newAuthItems as $template) {
$type = isset($template['type']) ? $template['type'] : CAuthItem::TYPE_OPERATION;
$bizRule = isset($template['bizRule']) ? $template['bizRule'] : null;
$auth->createAuthItem($template['name'], $type, $descriptions[$template['name']], $bizRule);
if (isset($template['child']) && $template['child'] !== null) {
$auth->addItemChild($template['child'], $template['name']);
}
}
}
}

public function actionRemoveAuthItems()
{
$auth = Yii::app()->authManager;
$auth = Yii::app()->authManager;

foreach($this->getTemplateAuthItems() as $template) {
foreach ($this->getTemplateAuthItems() as $template) {
$auth->removeAuthItem($template['name']);
}
}

/**
* Creating users using this command DOES NOT send the activation email.
* @param string $profile a POST (username=XX&password=YY) or JSON object with the profile form, can contain the password field
* @param string $authItems a comma separated list of auth items to assign
* @param string $profile a POST (username=XX&password=YY) or JSON object with the profile form, can contain the password field
* @param string $authItems a comma separated list of auth items to assign
* @param boolean $generatePassword if true, a random password will be generated even if profile contains one
*/
public function actionRegister($profile, $authItems = null, $generatePassword = false, $unlock = false)
{
$module = Yii::app()->getModule('usr');
/** @var ProfileForm */
$model = $module->createFormModel('ProfileForm', 'register');
/** @var PasswordForm */
$passwordForm = $module->createFormModel('PasswordForm', 'register');
/** @var ProfileForm */
$model = $module->createFormModel('ProfileForm', 'register');
/** @var PasswordForm */
$passwordForm = $module->createFormModel('PasswordForm', 'register');

if (($profileData = json_decode($profile)) === null) {
parse_str($profile, $profileData);
Expand All @@ -114,7 +119,7 @@ public function actionRegister($profile, $authItems = null, $generatePassword =
$passwordForm->setAttributes(array('newPassword' => $profile['password'], 'newVerify' => $profile['password']));
}
if ($generatePassword) {
require dirname(__FILE__) . '/../extensions/diceware/Diceware.php';
require dirname(__FILE__).'/../extensions/diceware/Diceware.php';
$diceware = new \nineinchnick\diceware\Diceware(Yii::app()->language);
$password = $diceware->get_phrase($module->dicewareLength, $module->dicewareExtraDigit, $module->dicewareExtraChar);
$passwordForm->setAttributes(array('newPassword' => $password, 'newVerify' => $password));
Expand All @@ -125,28 +130,33 @@ public function actionRegister($profile, $authItems = null, $generatePassword =
if (!$model->save() || !$passwordForm->resetPassword($model->getIdentity())) {
$trx->rollback();
echo Yii::t('UsrModule.usr', 'Failed to register a new user.')."\n";

return false;
} else {
$trx->commit();
echo $model->username.' '.$passwordForm->newPassword."\n";
$identity = $model->getIdentity();
if ($authItems !== null) {
$authItems = array_map('trim', explode(',', trim($authItems," \t\n\r\b\x0B,")));
$authItems = array_map('trim', explode(',', trim($authItems, " \t\n\r\b\x0B,")));
$authManager = Yii::app()->authManager;
foreach($authItems as $authItemName) {
foreach ($authItems as $authItemName) {
$authManager->assign($authItemName, $identity->getId());
}
}
if ($unlock) {
if (!$identity->isActive())
if (!$identity->isActive()) {
$identity->toggleStatus($identity::STATUS_IS_ACTIVE);
if ($identity->isDisabled())
}
if ($identity->isDisabled()) {
$identity->toggleStatus($identity::STATUS_IS_DISABLED);
}
}

return true;
}
}
echo "Invalid data: ".print_r($model->getErrors(), true)."\n";

return false;
}
}
43 changes: 22 additions & 21 deletions components/CaptchaFormBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,28 @@
*/
class CaptchaFormBehavior extends FormModelBehavior
{
public $verifyCode;
public $verifyCode;

/**
* @inheritdoc
*/
public function filterRules($rules = array())
{
$module = Yii::app()->controller !== null ? Yii::app()->controller->module : null;
$behaviorRules = array(
array('verifyCode', 'captcha', 'captchaAction'=>($module !== null ? $module->getId() : 'usr').'/default/captcha'),
);
return array_merge($rules, $this->applyRuleOptions($behaviorRules));
}
/**
* @inheritdoc
*/
public function filterRules($rules = array())
{
$module = Yii::app()->controller !== null ? Yii::app()->controller->module : null;
$behaviorRules = array(
array('verifyCode', 'captcha', 'captchaAction' => ($module !== null ? $module->getId() : 'usr').'/default/captcha'),
);

/**
* @inheritdoc
*/
public function attributeLabels()
{
return array(
'verifyCode' => Yii::t('UsrModule.usr','Verification code'),
);
}
return array_merge($rules, $this->applyRuleOptions($behaviorRules));
}

/**
* @inheritdoc
*/
public function attributeLabels()
{
return array(
'verifyCode' => Yii::t('UsrModule.usr', 'Verification code'),
);
}
}
37 changes: 19 additions & 18 deletions components/DicewareAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@
*/
class DicewareAction extends CAction
{
/**
* @var integer Number of words in password generated using the diceware component.
*/
public $length;
/**
* @var boolean Should an extra digit be added in password generated using the diceware component.
*/
public $extraDigit;
/**
* @var integer Should an extra random character be added in password generated using the diceware component.
*/
public $extraChar;
/**
* @var integer Number of words in password generated using the diceware component.
*/
public $length;
/**
* @var boolean Should an extra digit be added in password generated using the diceware component.
*/
public $extraDigit;
/**
* @var integer Should an extra random character be added in password generated using the diceware component.
*/
public $extraChar;

public function run() {
require dirname(__FILE__) . '/../extensions/diceware/Diceware.php';
$diceware = new \nineinchnick\diceware\Diceware(Yii::app()->language);
$password = $diceware->get_phrase($this->length, $this->extraDigit, $this->extraChar);
echo json_encode($password);
}
public function run()
{
require dirname(__FILE__).'/../extensions/diceware/Diceware.php';
$diceware = new \nineinchnick\diceware\Diceware(Yii::app()->language);
$password = $diceware->get_phrase($this->length, $this->extraDigit, $this->extraChar);
echo json_encode($password);
}
}
Loading

0 comments on commit 2cbf0c3

Please sign in to comment.