/**
  * Authenticates the password.
  * This is the 'authenticate' validator as declared in rules().
  */
 public function uniqueUserDefinedFunc($attribute, $params)
 {
     $record = AUserLogin::model()->findByAttributes(array('login_name' => $this->email));
     if ($record != null) {
         $this->addError("email", UserModule::t("Account with this email already exists.Kindly use a different email."));
         return false;
     } else {
         return false;
     }
 }
 public function checkexists($attribute, $params)
 {
     if (!$this->hasErrors()) {
         $user = AUserLogin::model()->scope_select_all()->findByAttributes(array('login_name' => $this->login_or_email));
         if ($user) {
             $this->user_id = $user->id;
         }
         if ($user === null) {
             $this->addError("login_or_email", UserModule::t("Email is incorrect. No such user exists."));
         }
     }
 }
 /**
  * Recovery password
  */
 public function actionRecovery()
 {
     $form = new UserRecoveryForm();
     if (Yii::app()->user->id) {
         $this->redirect(Yii::app()->controller->module->returnUrl);
     } else {
         $email = isset($_GET['email']) ? $_GET['email'] : '';
         $activkey = isset($_GET['activkey']) ? $_GET['activkey'] : '';
         if ($email && $activkey) {
             $form2 = new UserChangePassword();
             $find = AUserLogin::model()->scope_select_all()->findByAttributes(array('login_name' => $email));
             if (isset($find) && $find->userLogin2userDetails->activkey == $activkey) {
                 if (isset($_POST['UserChangePassword'])) {
                     $form2->attributes = $_POST['UserChangePassword'];
                     if ($form2->validate()) {
                         $find->pwd = Yii::app()->controller->module->encrypting($form2->password);
                         $find->userLogin2userDetails->activkey = Yii::app()->controller->module->encrypting(microtime() . $form2->password);
                         if ($find->userLogin2userDetails->is_active == 0) {
                             $find->userLogin2userDetails->is_active = 1;
                         }
                         $find->save();
                         $find->userLogin2userDetails->save();
                         Yii::app()->user->setFlash('recoveryMessage', UserModule::t("New password is saved."));
                         $this->redirect(Yii::app()->controller->module->recoveryUrl);
                     }
                 }
                 $this->render('changepassword', array('form' => $form2));
             } else {
                 Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Incorrect recovery link."));
                 $this->redirect(Yii::app()->controller->module->recoveryUrl);
             }
         } else {
             if (isset($_POST['UserRecoveryForm'])) {
                 $form->attributes = $_POST['UserRecoveryForm'];
                 if ($form->validate()) {
                     $user = AUserLogin::model()->scope_select_all()->findByAttributes(array('login_name' => $form->login_or_email));
                     $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl(implode(Yii::app()->controller->module->recoveryUrl), array("activkey" => $user->userLogin2userDetails->activkey, "email" => $user->login_name));
                     $subject = UserModule::t("You have requested the password recovery for {site_name}", array('{site_name}' => Yii::app()->name));
                     $message = UserModule::t("Hi, \n You have requested the password recovery for {site_name}. To receive a new password, go to {activation_url}. \n Regards, \n tw.in team", array('{site_name}' => Yii::app()->name, '{activation_url}' => $activation_url));
                     UserModule::sendMail($user->login_name, $subject, $message);
                     Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Please check your email. Instructions has been sent to your email address."));
                     $this->refresh();
                 }
             }
             $this->render('recovery', array('form' => $form));
         }
     }
 }
 /**
  * Activation user account
  */
 public function actionActivation()
 {
     $email = $_GET['email'];
     $activkey = $_GET['activkey'];
     if ($email && $activkey) {
         $record = AUserLogin::model()->scope_select_all()->findByAttributes(array('login_name' => $email));
         $find = $record->userLogin2userDetails;
         if (isset($find) && $find->is_active) {
             $this->render('/user/message', array('title' => UserModule::t("User activation"), 'content' => UserModule::t("You account is active.")));
         } elseif (isset($find->activkey) && $find->activkey == $activkey) {
             $find->activkey = UserModule::encrypting(microtime());
             $find->is_active = 1;
             $find->save();
             $this->render('/user/message', array('title' => UserModule::t("User activation"), 'content' => UserModule::t("You account is activated.")));
         } else {
             $this->render('/user/message', array('title' => UserModule::t("User activation"), 'content' => UserModule::t("Incorrect activation URL.")));
         }
     } else {
         $this->render('/user/message', array('title' => UserModule::t("User activation"), 'content' => UserModule::t("Incorrect activation URL..")));
     }
 }
 /**
  * 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()
 {
     //$this->username represents email and should be email always
     $record = AUserLogin::model()->scope_select_all()->findByAttributes(array('login_name' => $this->username));
     if ($record === null) {
         $this->errorCode = self::ERROR_EMAIL_INVALID;
     } elseif ($record->pwd !== Yii::app()->getModule('user')->encrypting($this->password)) {
         $this->errorCode = self::ERROR_PASSWORD_INVALID;
     } else {
         if ($record->userLogin2userDetails->is_active == 0 && Yii::app()->getModule('user')->loginNotActiv == false) {
             $this->errorCode = self::ERROR_STATUS_NOTACTIV;
         } else {
             if ($record->userLogin2userDetails->is_active == -1) {
                 $this->errorCode = self::ERROR_STATUS_BAN;
             } else {
                 $this->errorCode = self::ERROR_NONE;
             }
         }
     }
     if ($this->errorCode === self::ERROR_NONE) {
         $this->errorCode = $this->setAllProperties($record->userLogin2userDetails);
     }
     return !$this->errorCode;
 }