/**
  * Called when a user wants a password reset email sent, is passed in the user's email address.
  */
 public function forgot_password()
 {
     $loginData['success'] = 0;
     $error = Loader::helper('validation/error');
     $vs = Loader::helper('validation/strings');
     $em = $this->post('uEmail');
     try {
         if (!$vs->email($em)) {
             throw new \Exception(t('Invalid email address.'));
         }
         $oUser = UserInfo::getByEmail($em);
         if (!$oUser) {
             throw new \Exception(t('We have no record of that email address.'));
         }
         $mh = Loader::helper('mail');
         //$mh->addParameter('uPassword', $oUser->resetUserPassword());
         if (Config::get('concrete.user.registration.email_registration')) {
             $mh->addParameter('uName', $oUser->getUserEmail());
         } else {
             $mh->addParameter('uName', $oUser->getUserName());
         }
         $mh->to($oUser->getUserEmail());
         //generate hash that'll be used to authenticate user, allowing them to change their password
         $h = new \Concrete\Core\User\ValidationHash();
         $uHash = $h->add($oUser->uID, intval(UVTYPE_CHANGE_PASSWORD), true);
         $changePassURL = BASE_URL . View::url('/login', 'callback', $this->getAuthenticationType()->getAuthenticationTypeHandle(), 'change_password', $uHash);
         $mh->addParameter('changePassURL', $changePassURL);
         if (defined('EMAIL_ADDRESS_FORGOT_PASSWORD')) {
             $mh->from(EMAIL_ADDRESS_FORGOT_PASSWORD, t('Forgot Password'));
         } else {
             $adminUser = UserInfo::getByID(USER_SUPER_ID);
             if (is_object($adminUser)) {
                 $mh->from($adminUser->getUserEmail(), t('Forgot Password'));
             }
         }
         $mh->load('forgot_password');
         @$mh->sendMail();
     } catch (\Exception $e) {
         $error->add($e);
     }
     if (!$error->has()) {
         $this->redirect('/login', $this->getAuthenticationType()->getAuthenticationTypeHandle(), 'password_sent');
     } else {
         $this->set('authType', $this->getAuthenticationType());
         $this->set('authTypeElement', 'forgot_password');
     }
 }
示例#2
0
 /**
  * Called when a user wants a password reset email sent, is passed in the user's email address.
  */
 public function forgot_password()
 {
     $loginData['success'] = 0;
     $error = Core::make('helper/validation/error');
     $vs = Core::make('helper/validation/strings');
     $em = $this->post('uEmail');
     if ($em) {
         try {
             if (!$vs->email($em)) {
                 throw new \Exception(t('Invalid email address.'));
             }
             $oUser = UserInfo::getByEmail($em);
             if (!$oUser) {
                 throw new \Exception(t('We have no record of that email address.'));
             }
             $mh = Core::make('helper/mail');
             //$mh->addParameter('uPassword', $oUser->resetUserPassword());
             if (Config::get('concrete.user.registration.email_registration')) {
                 $mh->addParameter('uName', $oUser->getUserEmail());
             } else {
                 $mh->addParameter('uName', $oUser->getUserName());
             }
             $mh->to($oUser->getUserEmail());
             //generate hash that'll be used to authenticate user, allowing them to change their password
             $h = new \Concrete\Core\User\ValidationHash();
             $uHash = $h->add($oUser->uID, intval(UVTYPE_CHANGE_PASSWORD), true);
             $changePassURL = View::url('/login', 'callback', $this->getAuthenticationType()->getAuthenticationTypeHandle(), 'change_password', $uHash);
             $mh->addParameter('changePassURL', $changePassURL);
             $fromEmail = (string) Config::get('concrete.email.forgot_password.address');
             if (!strpos($fromEmail, '@')) {
                 $adminUser = UserInfo::getByID(USER_SUPER_ID);
                 if (is_object($adminUser)) {
                     $fromEmail = $adminUser->getUserEmail();
                 } else {
                     $fromEmail = '';
                 }
             }
             if ($fromEmail) {
                 $fromName = (string) Config::get('concrete.email.forgot_password.name');
                 if ($fromName === '') {
                     $fromName = t('Forgot Password');
                 }
                 $mh->from($fromEmail, $fromName);
             }
             $mh->addParameter('siteName', Config::get('concrete.site'));
             $mh->load('forgot_password');
             @$mh->sendMail();
         } catch (\Exception $e) {
             $error->add($e);
         }
         $this->redirect('/login', $this->getAuthenticationType()->getAuthenticationTypeHandle(), 'password_sent');
     } else {
         $this->set('authType', $this->getAuthenticationType());
     }
 }