/** * Inline validator for password field. * * @param * string * @param * array */ public function authenticate($attribute, $params) { if ($this->hasErrors()) { return; } $user = Yii::app()->user->data(); $this->_identity = new UserIdentity($user->username, $this->password); if ($this->_identity->authenticate()) { return; } $this->addError('password', Yii::t('errors', 'Incorrect password.')); }
/** * Logs in the user using the given username and password in the model. * @return boolean whether login is successful */ public function login() { if ($this->_identity === null) { $this->_identity = new UserIdentity($this->username, $this->password); $this->_identity->authenticate(); } if ($this->_identity->errorCode === UserIdentity::ERROR_NONE) { $duration = $this->rememberMe ? 3600 * 24 : 0; // 30 days Yii::app()->user->login($this->_identity, $duration); return true; } else { return false; } }
/** * Login * * @return bool */ public function signup() { if ($this->hasErrors()) { return false; } try { $this->_user = new User(); $this->_user->username = $this->email; $this->_user->email = $this->email; $this->_user->password = $this->passwordConfirm; $this->_user->password_strategy = 'bcrypt'; $this->_user->login_ip = $_SERVER['REMOTE_ADDR']; //$_user->regenerateValidationKey(); $this->_user->save(); } catch (Exception $e) { Yii::log($e); return false; } if ($this->_identity === null) { $this->_identity = new UserIdentity($this->email, $this->passwordConfirm); $this->_identity->authenticate(); } if ($this->_identity->isAuthenticated) { $duration = 0; Yii::app()->user->login($this->_identity, $duration); return true; } return true; }
/** * Logs in the user using the given username and password in the model. * @return boolean whether login is successful */ public function login() { $usersModule = Yii::app()->getModule("users"); $identityClass = $usersModule->identityClass; if ($this->_identity === null) { $this->_identity = new $identityClass($this->email, $this->password); $this->_identity->authenticate(); } if ($this->_identity->errorCode === $identityClass::ERROR_NONE) { $duration = $this->rememberMe ? $usersModule->autoLoginDuration : 0; Yii::app()->user->login($this->_identity, $duration); return true; } else { return false; } }
/** * Class constructor * * @param type $username username * @param type $password optional */ public function __construct($username, $password = NULL) { if (isset($password)) { parent::__construct($username, $password); } else { $this->username = $username; $this->_isSwap = TRUE; } }
/** * Apply the behavior that corresponds to the configure * authentication method (basic or digest) to $identity * * @param CUserIdentity $identity * @throws Exception when extension is configured with an unsupported authMethod */ public static function apply($identity) { //handle different authentication methods switch (Yii::app()->apiAuth->protocol) { //basic case ApiAuth::AUTH_BASIC: $identity->attachBehavior(self::behaviorName, new AIdentityBehaviorBasic()); break; //digest //digest case ApiAuth::AUTH_DIGEST: $identity->attachBehavior(self::behaviorName, new AIdentityBehaviorDigest()); break; default: //do not allow authentication methods other than the ones specified above. throw new Exception("Behavior not implemented for authentication method: " . Yii::app()->apiAuth->protocol); break; } }
/** * Login * * @return bool */ public function login() { if ($this->_identity === null) { $this->_identity = new UserIdentity($this->username, $this->password); $this->_identity->authenticate(); } if ($this->_identity->isAuthenticated) { $duration = $this->rememberMe ? 3600 * 24 * 30 : 0; // 30 days Yii::app()->user->login($this->_identity, $duration); return true; } return false; }
public function __construct($username, $password = null) { // sets username and password values parent::__construct($username, $password); $this->user = User::model()->find('LOWER(email)=:input OR LOWER(username)=:input', array(':input' => strtolower($this->username))); if ($this->user === null) { $this->errorCode = self::ERROR_USERNAME_INVALID; } elseif ($password === null) { /** * you can set here states for user logged in with oauth if you need * you can also use hoauthAfterLogin() * @link https://github.com/SleepWalker/hoauth/wiki/Callbacks */ $this->beforeAuthentication(); $this->errorCode = self::ERROR_NONE; } }
/** * Authenticates a user. * The example implementation makes sure if the username and password * are both 'demo'. * In practical applications, this should be changed to authenticate * against some persistent user identity storage (e.g. database). * @return boolean whether authentication succeeds. */ public function authenticate() { $model = new Admin('login'); $model->attributes = $_POST['LoginForm']; if ($model->validate()) { $data = $model->find('username=:username', array('username' => $model->username)); if ($data === null) { $this->errorCode = self::ERROR_USERNAME_INVALID; $model->addError('username', '用户不存在'); parent::_backendLogger(array('catalog' => 'login', 'intro' => '登录失败,用户不存在:' . $model->username, 'user_id' => 0)); } elseif (!$this->validatePassword($data->password)) { $this->errorCode = self::ERROR_PASSWORD_INVALID; $model->addError('password', '密码不正确'); parent::_backendLogger(array('catalog' => 'login', 'intro' => '登录失败,密码不正确:' . $model->username . ',使用密码:' . $model->password, 'user_id' => 0)); } elseif ($data->group_id == 2) { $this->errorCode = self::ERROR_UNKNOWN_IDENTITY; $model->addError('username', '用户已经锁定,请联系管理'); } else { $this->errorCode = self::ERROR_NONE; } } return $this->errorCode; }
public function __construct($user = '', $pass = '') { $this->_id = -1; parent::__construct($user, $pass); }
public function __construct($username, $password, $authtip) { parent::__construct($username, $password); $this->authtip = $authtip; $this->objerror = new stdclass(); }
public function __construct($username, $password) { parent::__construct($username, $password); $this->username = $username; }
public function __construct($email, $password, $remember_me = null) { parent::__construct($email, $password); $this->remember_me = $remember_me; }
public function __construct($email, $password, $type) { parent::__construct(trim(strtolower($email)), $password); $this->type = $type; }
/** * Action: Index * * @access public * @return void */ public function actionIndex() { // If the end-user is already logged in, then there is absolutely no point presenting the login form to them // as it will just create confusion as to whether they are logged in or not. Redirect them to the homepage. if (!Yii::app()->user->isGuest) { $this->redirect(Yii::app()->homeUrl); } // Create an instance of the form builder, this controls all of the display logic (inputs). // Load up the form configuration from the path alias, and associate it with the form model. $form = new Form('application.forms.login', new \application\models\form\Login()); // Check that the form has been submitted, and if has, if it passes the models validation rules. if ($form->submitted() && $form->validate()) { // Seeing as the end-user has provided valid input data, create a new user identity with it. $this->identity = new UserIdentity($form->model->username, $form->model->password); // Do the credentials provided by the end-user's input data authenticate them as a valid user? if ($this->identity->authenticate()) { // Great! The end-user provided correct authentication credentials! Log in the user provided by the // user identity created from those credentials. Yii::app()->user->login($this->identity); // Redirect back to where they were (defaults to the homepage if the location to return to has not // been set). $this->redirect(Yii::app()->user->getReturnUrl(Yii::app()->homeUrl)); } else { // Log this failed authentication attempt. Yii::log('User "' . $form->model->username . '" provided incorrect credentials.', 'info', 'application.controllers.LoginController'); // Grab the error code defined by UserIdentity, and add the appropriate error message to the correct // model attribute (form field), so that it may be rendered by the form builder in the view. switch ($this->identity->errorCode) { // The end-user provided a string that does not correspond to any user that we have in the // database. case UserIdentity::ERROR_USERNAME_INVALID: $form->model->addError('username', Yii::t('application', 'The username you entered does not exist.')); break; // The end-user specified a username that is not allowed to login via the current IP address // that the end-user is using. // The end-user specified a username that is not allowed to login via the current IP address // that the end-user is using. case UserIdentity::ERROR_IP_INVALID: $form->model->addError('username', Yii::t('application', 'The username you entered may not login at this IP address.')); break; // The end-user has made too many login attempts in a specified amount of time, inform the user // to wait a while before the next attempt. // The end-user has made too many login attempts in a specified amount of time, inform the user // to wait a while before the next attempt. case UserIdentity::ERROR_THROTTLED: $form->model->addError('username', Yii::t('application', 'The username you entered has been throttled for security reasons. Please try again after a couple of seconds.')); break; // The end-user has specified a password that does not match the one associated with the // username the end-user provided. // The end-user has specified a password that does not match the one associated with the // username the end-user provided. case UserIdentity::ERROR_PASSWORD_INVALID: $form->model->addError('password', Yii::t('application', 'The password you entered was incorrect.')); break; } } } else { // The login form has either not been submitted, or there were validation errors. Either way we don't // need to do anything, other than to carry on as normal to render the form. Yii will deal with all the // error messages for us :) } // Make sure that we do not auto-populate the password field with anything that may have been submitted by // the user; we do not want their password encoded into the HTML of our page. $form->model->password = null; // Pass the form builder to the default login view to render the login HTML form. If it is an AJAX request, // render only the partial "ajax" view. Yii::app()->request->isAjaxRequest ? $this->renderPartial('ajax', array('form' => $form)) : $this->render('index', array('form' => $form)); }
public function __construct($username, $password, $loginType = self::LOGIN_BY_USERNAME) { $this->loginType = (int) $loginType; parent::__construct($username, $password); }
public function __construct($email, $password) { parent::__construct($username, $password); $this->email = $email; }
public function __construct($username, $password, $campus_id) { parent::__construct($username, $password); $this->campus_id = $campus_id; }
/** * Constructor overload for two factor code */ public function __construct($username, $password, $twoFactorCode = false) { parent::__construct($username, $password); $this->twoFactorCode = $twoFactorCode; }
/** * Login function * * @param CUserIdentity $identity user identity * @param int $duration duration of cookie * * @return void */ public function login($identity, $duration) { $userId = $identity->getId(); $name = $identity->getName(); // @todo Implement an ability to get/set persistent states $states = $identity->getPersistentStates(); if ($this->beforeLogin($userId, $states, false)) { $cookieData = array('id' => $userId, 'name' => $name); $this->_userData = $cookieData; $this->setCookie($cookieData, $duration); $this->isGuest = false; $this->afterLogin(false); } }
public function __construct($username, $password, $controller) { parent::__construct($username, $password); $this->controller = $controller; return true; }
public function __construct($email, $password, $usertype) { parent::__construct($email, $password, $usertype); $this->usertype = $usertype; }
/** * perform the login action * @param CUserIdentity $identity * @param int $duration * @see CWebUser::login() */ public function login($identity, $duration = 0) { $id = $identity->getId(); $states = $identity->getPersistentStates(); if ($this->beforeLogin($id, $states, false)) { $this->UGChangeIdentity($id, $identity->getName(), $identity->getGroup(), $identity->getGroupName(), $identity->getLevel(), $identity->getAccessRules(), $identity->getHome(), $identity->getRecovery(), $identity->getProfile(), $states); $this->profileLoad(); if ($duration > 0) { if ($this->allowAutoLogin) { $this->saveToCookie($duration); } else { throw new CException(Yii::t('userGroupsModule.admin', '{class}.allowAutoLogin must be set true in order to use cookie-based authentication.', array('{class}' => get_class($this)))); } } $this->afterLogin(false); } }
public function __construct($usuario, $contrasena) { $this->usuario = strtolower($usuario); $this->contrasena = $contrasena; parent::__construct($this->usuario, $contrasena); }
public function __construct($username = '', $password = '') { parent::__construct($username, $password); }
/** * Constructor Method * * @access public * @return void */ public function __construct($username, $password) { parent::__construct($username, $password); \application\components\EventManager::attach($this); }