Beispiel #1
0
 /**
  * Displays the contact page
  */
 public function actionContact()
 {
     $contact = new ContactForm();
     if (isset($_POST['ContactForm'])) {
         $contact->attributes = $_POST['ContactForm'];
         if ($contact->validate()) {
             $headers = "From: {$contact->email}\r\nReply-To: {$contact->email}";
             @mail(MParams::getAdminEmailAddress(), $contact->subject, $contact->content, $headers);
             MUserFlash::setTopInfo(Yii::t('hint', 'Thank you for contacting us. We will respond to you as soon as possible.'));
             $this->refresh();
         }
     }
     $this->render($this->action->id, array('contact' => $contact));
 }
Beispiel #2
0
 /**
  * Register a new member account.
  * If creation is successful, the browser will be redirected to the 'login' page.
  */
 public function actionRegister()
 {
     $model = new User($this->action->id);
     // collect user input data
     if (isset($_POST['User'])) {
         // collect user input data
         $model->attributes = $_POST['User'];
         // instantiate a new user details object
         $model->details = new UserDetails($this->action->id);
         $model->details->emailConfirmationKey = $model->details->generateConfirmationKey();
         if (isset($_POST['UserDetails'])) {
             $model->details->attributes = $_POST['UserDetails'];
         }
         // validate with the current action as scenario
         if (($validated = $model->validate()) !== false) {
             // if user is logged in
             if (!Yii::app()->user->isGuest) {
                 // if you place this code before validate() then verifyCode will be invalid
                 // log user out from the current account
                 Yii::app()->user->logout();
                 if (!Yii::app()->getSession()->getIsStarted()) {
                     // restore http session. this is necessary for user flash messages
                     Yii::app()->getSession()->open();
                 }
             }
             // create user record (without validation)
             if (($saved = $model->save(false)) !== false) {
                 // save user details record
                 $model->details->userId = $model->id;
                 if ($model->details->save(false) === false) {
                     // hmmm, what could be the problem?
                     Yii::log(W3::t('system', 'Failed creating UserDetails record. Member ID: {userId}. Method called: {method}.', array('{userId}' => $model->id, '{method}' => __METHOD__ . '()')), 'error', 'w3');
                 }
                 // set success message
                 MUserFlash::setTopSuccess(Yii::t('hint', '{screenName}, your member account has been successfully created.', array('{screenName}' => MHtml::wrapInTag($model->screenName, 'strong'))));
                 // send welcome email
                 $headers = "From: " . MParams::getAdminEmailAddress() . "\r\nReply-To: " . MParams::getAdminEmailAddress();
                 $content = Yii::t('email', 'Content(New member account)', array('{siteTitle}' => MParams::getSiteTitle(), '{screenName}' => $model->screenName, '{emailConfirmationKey}' => $model->details->emailConfirmationKey, '{emailConfirmationLink}' => Yii::app()->createAbsoluteUrl($this->id . '/confirmEmail', array('email' => $model->email, 'key' => $model->details->emailConfirmationKey))));
                 $sent = @mail($model->email, Yii::t('email', 'New member account'), $content, $headers);
                 // log email
                 Yii::log($model->email . ' ' . "\t" . 'New member account', $sent ? 'sent' : 'not-sent', 'email');
                 Yii::log($model->email . "\n" . 'Subject: New member account' . "\n" . 'Content: ' . $content . "\n" . 'Headers: ' . $headers, $sent ? 'sent' : 'not-sent', 'email-details');
                 // go to login page
                 $this->redirect($this->getGotoUrl());
             }
         }
     } else {
         // pre-assigned attributes (default values for a new record)
         $model->screenNameSame = true;
         $model->language = MParams::getLanguage();
         $model->interface = MParams::getInterface();
     }
     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'))));
     }
     if (!isset($model->details)) {
         // new associated user details
         $model->details = new UserDetails($this->action->id);
     }
     // render the view file
     $this->render($this->action->id, array('model' => $model));
 }
Beispiel #3
0
 /**
  * Logout the current user and redirect to homepage.
  */
 public function actionLogout()
 {
     $isLoggedIn = !Yii::app()->user->isGuest;
     $screenName = $isLoggedIn ? Yii::app()->user->screenName : '';
     // log user out and destroy all session data
     // if you want to keep the session alive, then use Yii::app()->user->logout(false) instead
     Yii::app()->user->logout();
     // if user was logged in, we should notify about logout
     if ($isLoggedIn) {
         if (!Yii::app()->getSession()->getIsStarted()) {
             // if session is destroyed, we need to re-open it. this is necessary for user flash
             Yii::app()->getSession()->open();
         }
         // set the goodbye message
         MUserFlash::setTopInfo(Yii::t('hint', '{screenName}, you have been successfully logged out.', array('{screenName}' => MHtml::wrapInTag($screenName, 'strong'))));
     }
     // go to home page
     $this->redirect(Yii::app()->homeUrl);
 }