Beispiel #1
0
 /**
  * Displays the login page
  */
 public function actionLogin()
 {
     $form = new LoginForm();
     // collect user input data
     if (isset($_POST['LoginForm'])) {
         if (isset($_POST['LoginForm']['loginWithField'])) {
             // if user is logging with email, but param changed to username,
             // we should try to log him in with email.
             // if login attempt is unsuccessful, he will have to try again with username
             LoginForm::$loginWithField = $_POST['LoginForm']['loginWithField'];
             unset($_POST['LoginForm']['loginWithField']);
         }
         $form->attributes = $_POST['LoginForm'];
         // validate user input and redirect to return page if valid
         if ($form->validate()) {
             // set the welcome message
             MUserFlash::setTopSuccess(Yii::t('hint', '{screenName}, you have been successfully logged in.', array('{screenName}' => MHtml::wrapInTag(Yii::app()->user->screenName, 'strong'))));
             // user was just authenticated, but let's check anyway
             if (!Yii::app()->user->isGuest) {
                 // update user stats
                 if (($userDetails = UserDetails::model()->findByPk(Yii::app()->user->id)) !== null) {
                     $userDetails->saveAttributes(array('lastLoginTime' => time(), 'lastVisitTime' => time(), 'totalTimeLoggedIn' => $userDetails->totalTimeLoggedIn + 60));
                 } else {
                     // hmmm, user details does not exists
                     Yii::log(W3::t('system', 'Member with ID {userId} has no UserDetails record associated. Method called: {method}.', array('{userId}' => Yii::app()->user->id, '{method}' => __METHOD__ . '()')), 'error', 'w3');
                 }
             }
             // go to previous/profile page
             $url = Yii::app()->homeUrl == Yii::app()->user->returnUrl ? array('site/index') : Yii::app()->user->returnUrl;
             $this->redirect($url);
         }
     }
     if (!Yii::app()->user->isGuest) {
         // warn user if already logged in
         MUserFlash::setTopInfo(Yii::t('hint', '{screenName}, this action will log you out from your current account.', array('{screenName}' => MHtml::wrapInTag(Yii::app()->user->screenName, 'strong'))));
     }
     // display the login form
     $this->render($this->action->id, array('form' => $form));
 }
Beispiel #2
0
 public function __construct($scenario = '')
 {
     parent::__construct($scenario);
     self::$loginWithField = $this->getLoginWithField();
 }