Skip to content

Commit

Permalink
Merge branch 'master' of github.com:nineinchnick/yii-usr
Browse files Browse the repository at this point in the history
  • Loading branch information
nineinchnick committed Feb 20, 2015
2 parents 0515012 + efb5d12 commit 7a8fe94
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 8 deletions.
6 changes: 3 additions & 3 deletions models/ExampleUserLoginAttempt.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ public static function hasTooManyFailedAttempts($username, $count_limit = 5, $ti
{
$since = new DateTime;
$since->sub(new DateInterval("PT{$time_limit}S"));
$subquery = self::model()->dbConnection->createCommand()
$subquery = UserLoginAttempt::model()->dbConnection->createCommand()
->select('is_successful')
->from(self::model()->tableName())
->from(UserLoginAttempt::model()->tableName())
->where('username = :username AND performed_on > :since')
->order('performed_on DESC')
->limit($count_limit)->getText();
return $count_limit <= (int)self::model()->dbConnection->createCommand()
return $count_limit <= (int)UserLoginAttempt::model()->dbConnection->createCommand()
->select('COUNT(NOT is_successful OR NULL)')
->from("({$subquery}) AS t")
->queryScalar(array(':username'=>$username, ':since' => $since->format('Y-m-d H:i:s')));
Expand Down
11 changes: 11 additions & 0 deletions tests/UserLoginAttempt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

Yii::import('vendors.nineinchnick.yii-usr.models.ExampleUserLoginAttempt');

class UserLoginAttempt extends ExampleUserLoginAttempt
{
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}
13 changes: 12 additions & 1 deletion tests/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,19 @@
'usr'=>array(
'class'=>'vendors.nineinchnick.yii-usr.UsrModule',
'userIdentityClass' => 'UserIdentity',
'oneTimePasswordMode' => 'time',
'captcha' => array('clickableImage'=>true,'showRefreshButton'=>false),
'loginFormBehaviors' => array(
'expiredPasswordBehavior' => array(
'class' => 'ExpiredPasswordBehavior',
'passwordTimeout' => 10,
),
'oneTimePasswordBehavior' => array(
'class' => 'OneTimePasswordFormBehavior',
'mode' => 'time', // cannot use OneTimePasswordFormBehavior::OTP_TIME here as it hasn't been loaded yet
'required' => true,
'timeout' => 123,
),
),
),
),
'components'=>array(
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/BehaviorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public function testOTP()
$this->assertEquals(array('oneTimePassword'), $otp->attributeNames());
$this->assertEquals(array('oneTimePassword'), $otp->attributeNames());
$this->assertEquals(array('oneTimePassword' => Yii::t('UsrModule.usr','One Time Password')), $otp->attributeLabels());
$rules = $otp->rules();
$rules = $otp->filterRules();

$ruleOptions = array('on'=>'reset');
$otp->setRuleOptions($ruleOptions);
$this->assertEquals($ruleOptions, $otp->getRuleOptions());

$modifiedRules = $otp->rules();
$modifiedRules = $otp->filterRules();
foreach($modifiedRules as $rule) {
foreach($ruleOptions as $key=>$value) {
$this->assertEquals($value, $rule[$key]);
Expand Down Expand Up @@ -94,7 +94,7 @@ public function testCaptcha()

$this->assertEquals(array('verifyCode'), $captcha->attributeNames());
$this->assertEquals(array('verifyCode' => Yii::t('UsrModule.usr','Verification code')), $captcha->attributeLabels());
$this->assertEquals(array(array('verifyCode', 'captcha', 'captchaAction' => 'usr/default/captcha')), $captcha->rules());
$this->assertEquals(array(array('verifyCode', 'captcha', 'captchaAction' => 'usr/default/captcha')), $captcha->filterRules());
}

public function testExpiredPassword()
Expand Down
1 change: 1 addition & 0 deletions tests/unit/LoginFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Yii::import('vendors.nineinchnick.yii-usr.tests.User');
Yii::import('vendors.nineinchnick.yii-usr.tests.UserIdentity');
Yii::import('vendors.nineinchnick.yii-usr.tests.UserLoginAttempt');
Yii::import('vendors.nineinchnick.yii-usr.models.BaseUsrForm');
Yii::import('vendors.nineinchnick.yii-usr.models.LoginForm');

Expand Down
7 changes: 6 additions & 1 deletion tests/unit/ModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ class ModuleTest extends CTestCase
public function testCreateForm()
{
$module = new UsrModule('usr',Yii::app());
$module->passwordTimeout = 300;
$module->loginFormBehaviors = array(
'expiredPasswordBehavior' => array(
'class' => 'ExpiredPasswordBehavior',
'passwordTimeout' => 300,
),
);
$form = $module->createFormModel('LoginForm');
$this->assertTrue($form->asa('expiredPasswordBehavior') instanceof ExpiredPasswordBehavior);
}
Expand Down

0 comments on commit 7a8fe94

Please sign in to comment.