-
-
Save drizzentic/4328298 to your computer and use it in GitHub Desktop.
Revisions
-
jamband renamed this gist
Dec 13, 2012 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
jamband renamed this gist
Dec 13, 2012 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
jamband revised this gist
Apr 12, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,7 +11,7 @@ class LoginAttempt extends ActiveRecord protected function beforeSave() { $this->create_time = time(); $this->expiration_time = strtotime(self::BANNED_IP_EXPIRATION_TIME, $this->create_time); return true; } -
jamband revised this gist
Apr 8, 2012 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ protected function beforeSave() public function isBanned($ip) { $c = $this->getCriteriaByIp($ip); if ($this->count($c) >= self::LOGIN_ATTEMPT_LIMIT) return true; return false; @@ -37,7 +37,7 @@ public function isBanned($ip) public function purgeBannedIp($ip) { $c = $this->getCriteriaByIp($ip); if ($this->count($c) >= self::LOGIN_ATTEMPT_LIMIT) { $c->order = 't.create_time DESC'; $model = $this->find($c); -
jamband revised this gist
Apr 8, 2012 . No changes.There are no files selected for viewing
-
jamband revised this gist
Apr 8, 2012 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,6 @@ class LoginController extends Controller public function init() { $this->_ip = Yii::app()->request->userHostAddress; } /** -
jamband revised this gist
Apr 8, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -41,7 +41,7 @@ public function purgeBannedIp($ip) { $c->order = 't.create_time DESC'; $model = $this->find($c); if (time() > $model->expiration_time) $this->deleteAll('ip = :ip', array(':ip' => $ip)); } } -
jamband revised this gist
Apr 8, 2012 . 1 changed file with 27 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ <?php if (!$isBanned): ?> <div class="form"> <?php echo CHtml::form(); ?> <?php echo CHtml::errorSummary($model, false); ?> <div class="row"> <?php echo CHtml::activeLabel($model, 'login'); ?> <?php echo CHtml::activeTextField($model, 'login', array('maxlength' => 64)); ?> </div> <div class="row"> <?php echo CHtml::activeLabel($model, 'password'); ?> <?php echo CHtml::activePasswordField($model, 'password', array('maxlength' => 64)); ?> </div> <div class="row"> <?php echo CHtml::submitButton('ログイン'); ?> <?php echo CHtml::activeCheckBox($model, 'rememberMe'); ?> <?php echo CHtml::activeLabel($model, 'rememberMe'); ?> </div> </form> </div><!-- /.form --> <?php else: ?> <div class="flash-error"> ログイン試行回数が制限を越えてしまいました。時間をおいて、再度ログインを試してください </div> <?php endif; ?> -
jamband revised this gist
Apr 8, 2012 . 1 changed file with 51 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ <?php class LoginController extends Controller { private $_ip; /** * @see CController::defaultAction */ public $defaultAction = 'login'; /** * @see CController::init() */ public function init() { $this->_ip = Yii::app()->request->userHostAddress; return parent::init(); } /** * ユーザのログイン */ public function actionLogin() { if (Yii::app()->user->id) $this->redirect('/'); $loginAttempt = new LoginAttempt; $loginAttempt->purgeBannedIp($this->_ip); if (!$isBanned = $loginAttempt->isBanned($this->_ip)) { $model = new Login; if (isset($_POST['Login'])) { $model->attributes = $_POST['Login']; if ($model->validate()) $this->redirect(Yii::app()->user->returnUrl); if (!empty($model->login)) { $loginAttempt->login = $model->login; $loginAttempt->ip = $this->_ip; $loginAttempt->save(false); } } } $this->render('/user/login', compact('model', 'isBanned')); } } -
jamband revised this gist
Apr 8, 2012 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,8 @@ <?php class LoginAttempt extends ActiveRecord { const LOGIN_ATTEMPT_LIMIT = 5; // ログイン試行回数のリミット const BANNED_IP_EXPIRATION_TIME = '+1 hour'; // この場合は禁止されてから一時間経たないとログインできない ... /** @@ -24,7 +24,7 @@ protected function beforeSave() public function isBanned($ip) { $c = $this->getCriteriaByIp($ip); if ($this->count($c) > self::LOGIN_ATTEMPT_LIMIT) return true; return false; @@ -37,7 +37,7 @@ public function isBanned($ip) public function purgeBannedIp($ip) { $c = $this->getCriteriaByIp($ip); if ($this->count($c) > self::LOGIN_ATTEMPT_LIMIT) { $c->order = 't.create_time DESC'; $model = $this->find($c); -
jamband created this gist
Apr 8, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ <?php class LoginAttempt extends ActiveRecord { const LOGIN_ATTEMPT_LIMIT = 5; const BANNED_IP_EXPIRATION_TIME = '+1 minute'; ... /** * @see CActiveRecord::beforeSave() */ protected function beforeSave() { $this->create_time = time(); $this->expiration_time = strtotime(self::BANNED_IP_EXPIRATION_TIME, time()); return true; } /** * ログインが禁止されたIPアドレスか、そうでないか * @param string $ip ip address * @return boolean */ public function isBanned($ip) { $c = $this->getCriteriaByIp($ip); if ($this->count($c) >= self::LOGIN_ATTEMPT_LIMIT) return true; return false; } /** * ログインが禁止されたIPアドレスを期限切れの場合は削除する * @param string $ip ip address */ public function purgeBannedIp($ip) { $c = $this->getCriteriaByIp($ip); if ($this->count($c) >= self::LOGIN_ATTEMPT_LIMIT) { $c->order = 't.create_time DESC'; $model = $this->find($c); if (time() >= $model->expiration_time) $this->deleteAll('ip = :ip', array(':ip' => $ip)); } } /** * IPを条件にしたcriteriaを取得する * @param string $ip ip address * @return object criteria */ protected function getCriteriaByIp($ip) { $c = new CDbCriteria; $c->condition = 't.ip = :ip'; $c->params[':ip'] = $ip; return $c; } ...