Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
Public Attributes | Protected Member Functions | List of all members
BadLoginAttemptsFilter Class Reference

Public Attributes

 $blockedVar = 'attemptsEnded'
 $timeRemainsVar = 'timeRemains'
 $attemptsCount = 3
 $blockTime = 360

Protected Member Functions

 preFilter ($filterChain)
 postFilter ($filterChain)

Detailed Description

Checks if user has ability to perform login

Definition at line 6 of file BadLoginAttemptsFilter.php.

Member Function Documentation

BadLoginAttemptsFilter::postFilter (   $filterChain)
protected
If user is guest after login attepmt then it means that password was invalid.

Increment counter in db by ip address

@param CFilterChain $filterChain the filter chain that the filter is on.

Definition at line 69 of file BadLoginAttemptsFilter.php.

{
//if access not blocked
if(Yii::app()->request->isPostRequest && Yii::app()->user->isGuest && $filterChain->controller->{$this->blockedVar} !== true){
$ip = Yii::app()->request->userHostAddress;
$record = LoginAttempt::model()->findByAttributes(array('ip' => $ip));
if($record){
if($record->attempts < $this->attemptsCount){
$record->attempts += 1;
$record->save();
}
} else {
$record = new LoginAttempt();
$record->ip = $ip;
$record->save();
}
}
}
BadLoginAttemptsFilter::preFilter (   $filterChain)
protected

Performs the pre-action filtering.

Parameters
CFilterChain$filterChainthe filter chain that the filter is on.
Returns
boolean whether the filtering process should continue and the action should be executed.

Definition at line 42 of file BadLoginAttemptsFilter.php.

References LoginAttempt\model().

{
if(Yii::app()->request->isPostRequest && Yii::app()->user->isGuest){
$record = LoginAttempt::model()->findByAttributes(array('ip' => Yii::app()->request->userHostAddress));
if($record){
//time eleapsed
$timeRemains = $this->blockTime - (time() - strtotime($record->updated));
$filterChain->controller->{$this->timeRemainsVar} = $timeRemains;
if( $timeRemains <= 0) {
$record->attempts = 0;
$record->save();
} elseif($record->attempts >= $this->attemptsCount){
//block
$filterChain->controller->{$this->blockedVar} = true;
}
}
}
return true;
}

Member Data Documentation

BadLoginAttemptsFilter::$attemptsCount = 3

Number of login attempts

int

Definition at line 27 of file BadLoginAttemptsFilter.php.

BadLoginAttemptsFilter::$blockedVar = 'attemptsEnded'

Controller var for storing flag described if attempts remains

string

Definition at line 13 of file BadLoginAttemptsFilter.php.

BadLoginAttemptsFilter::$blockTime = 360

Time for blicking account

string

Definition at line 34 of file BadLoginAttemptsFilter.php.

BadLoginAttemptsFilter::$timeRemainsVar = 'timeRemains'

Controller var for storing flag showing remained blocking time

string

Definition at line 20 of file BadLoginAttemptsFilter.php.


The documentation for this class was generated from the following file: