コード例 #1
0
 public function actionConfirm()
 {
     if (!isset($_GET['email']) && !isset($_GET['key'])) {
         $this->redirect(array('index/index'));
     }
     switch (EmailVerification::model()->confirm($_GET['email'], $_GET['key'])) {
         case EmailVerification::CONFIRM_ALREADY_ACTIVE:
             echo UserModule::t('This email address has already been verified. Thank you!');
             break;
         case EmailVerification::CONFIRM_INVALID_KEY:
             echo UserModule::t('The confirmation key is invalid!');
             break;
         case EmailVerification::CONFIRM_KEY_NOT_ACTIVE:
             echo UserModule::t('This key is no longer active');
             break;
         case EmailVerification::CONFIRM_USER_BLOCKED:
             echo UserModule::t('This account is currently blocked');
             break;
         case EmailVerification::CONFIRM_SUCCESS:
             echo UserModule::t('This email is now verified. You can log in your account using this email. Thank you!');
             break;
         case EmailVerification::CONFIRM_ERROR:
         default:
             echo UserModule::t('Oops, an error has occurred! Please try again.');
     }
 }
コード例 #2
0
ファイル: User.php プロジェクト: redlaw/lintinzone
 public static function sendRegisterVerification($email, $username)
 {
     if (empty($email)) {
         return false;
     }
     $key = sha1(uniqid(rand()));
     $data = array('verification_key' => $key);
     $model = EmailVerification::model()->get($email);
     if ($model === null) {
         /*$model = new EmailVerification();
         		$model->email = $email;
         		$model->verification_key = $key;*/
         $mailParams = array('from' => Yii::app()->params['adminEmail'], 'fromName' => 'LintinZone', 'to' => $email, 'subject' => 'LintinZone ' . UserModule::t('Xác nhận đăng ký thành viên'), 'body' => array('{receiver}' => empty($username) ? UserModule::t('my friend') : $username, '{confirm_link}' => Yii::app()->createAbsoluteUrl('user/registration/confirm', array('key' => $key, 'email' => $email)), '{support_link}' => Yii::app()->createAbsoluteUrl('site/contact', array('email' => $email)), '{home_link}' => Yii::app()->createAbsoluteUrl('')));
         if (MailSender::sendSMTP($mailParams, 'register', 'text/html')) {
             /*$model->sent_date = new CDbExpression('NOW()');
             		$model->save();*/
             $data['sent'] = true;
             $data['active'] = true;
             $data['verified'] = false;
             EmailVerification::model()->insert($email, $data);
             return true;
         }
         //$model->save();
         $data['sent'] = false;
         $data['active'] = true;
         $data['verified'] = false;
         EmailVerification::model()->insert($email, $data);
         return false;
     } else {
         if (!$model->verified) {
             //$model->verification_key = $key;
             $mailParams = array('from' => Yii::app()->params['adminEmail'], 'fromName' => 'LintinZone', 'to' => $email, 'subject' => 'LintinZone ' . UserModule::t('Xác nhận đăng ký thành viên'), 'body' => array('{receiver}' => empty($username) ? UserModule::t('my friend') : $username, '{confirm_link}' => Yii::app()->createAbsoluteUrl('user/registration/confirm', array('key' => $key, 'email' => $email)), '{support_link}' => Yii::app()->createAbsoluteUrl('site/contact', array('email' => $email)), '{home_link}' => Yii::app()->createAbsoluteUrl('')));
             if (MailSender::sendSMTP($mailParams, 'register', 'text/html')) {
                 $data['sent'] = true;
                 $data['active'] = true;
                 $data['verified'] = false;
                 EmailVerification::model()->insert($email, $data);
                 return true;
             }
             $data['sent'] = false;
             $data['active'] = true;
             $data['verified'] = false;
             EmailVerification::model()->insert($email, $data);
             return false;
         } else {
             return true;
         }
     }
 }
コード例 #3
0
ファイル: UserService.php プロジェクト: kelliany/TestZilla
 /**
  * Send the verification email to the user.
  * @param  String $subject      - the subject of the email
  * @param  String $templateName - the template name of the email
  * @param  String $username     - the username of the user
  * @param  String $email        - the email of the user
  * @return whether the mail is successfully sent
  */
 private function sendVerificationEmail($subject, $templateName, $username, $email)
 {
     $token = uniqid();
     $tomorrowDateTime = date('Y-m-d H:i:s', strtotime('+1 day'));
     $emailVerification = EmailVerification::findFirst(array('conditions' => 'email = ?1', 'bind' => array(1 => $email)));
     if ($emailVerification != NULL) {
         $emailVerification->delete();
     }
     $emailVerification = new EmailVerification();
     $emailVerification->setEmail($email);
     $emailVerification->setToken($token);
     $emailVerification->setExpireTime($tomorrowDateTime);
     $emailVerification->create();
     $parameters = array('username' => $username, 'email' => $email, 'token' => $token);
     return $this->mailSender->sendMail($email, $subject, $templateName, $parameters);
 }