Skip to content

Commit

Permalink
Merge pull request #34 from elfarqy/develop
Browse files Browse the repository at this point in the history
Develop - enhance code
  • Loading branch information
haqqi authored Feb 6, 2017
2 parents 8697000 + 26569ec commit 3b432a9
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 38 deletions.
16 changes: 0 additions & 16 deletions api/forms/LoginForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,4 @@ public function login()
}
return false;
}

/**
* This class permits its instance to get the login column.
*
* @author Muhammad Yahya Muhaimin <myahyamuhaimin@yahoo.com>
*/
public function getLoginColumn()
{
try {
$loginColumn = parent::getLoginColumn();
} catch (InvalidConfigException $e) {
return $e->getMessage();
}

return $loginColumn;
}
}
17 changes: 1 addition & 16 deletions api/modules/v1/controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,9 @@ public function actionLogin()
*/
$user = \Yii::$app->user->getIdentity();

$msgLoginBy = '';
$loginColumn = $loginForm->getLoginColumn();

switch ($loginColumn) {
case 'username':
$msgLoginBy = 'username ' . $user->username;
break;
case 'email':
$msgLoginBy = 'email ' . $user->email;
break;
default:
$msgLoginBy = $loginColumn;
break;
}

return [
'name' => 'Success',
'message' => 'Login by ' . $msgLoginBy . ' success.',
'message' => 'Login by ' . $loginForm->loginColumn . ' success.',
'code' => ApiCode::LOGIN_SUCCESS,
'status' => 200,
'data' => $user->toArray([
Expand Down
2 changes: 0 additions & 2 deletions common/config/params.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
'supportEmail' => 'support@example.com',
/** set password reset token expired 60 sec * 60 Min */
'user.passwordResetTokenExpire' => 3600,
/** set login params. If value is true, then should login by email. else, login by username. */
'loginByEmail' => false,
/**
* Is user must be use strong password?
* there is only 5 choices : simple | normal | fair | medium | strong
Expand Down
5 changes: 1 addition & 4 deletions common/forms/LoginForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,7 @@ protected function getUser()
$loginColumn = $this->getLoginColumn();

$this->_user = $class::findOne([$loginColumn => $this->username]);

if (!($this->_user instanceof IdentityInterface)) {
throw new InvalidConfigException('User class must implement IdentityInterface');
}

}

return $this->_user;
Expand Down

0 comments on commit 3b432a9

Please sign in to comment.