Exemplo n.º 1
0
 /**
  * Send new password to defined E-Mail.
  */
 protected function send()
 {
     if ($crumbComponent = $this->document->componentManager->getBlockByName('breadCrumbs')) {
         $crumbComponent->addCrumb();
     }
     if ($component = $this->document->componentManager->getBlockByName('textBlockRestorePassword')) {
         $component->disable();
     }
     if (!isset($_POST['u_name'])) {
         $message = $this->translate('ERR_NO_U_NAME');
     } else {
         $uName = $_POST['u_name'];
         if (!($UID = $this->dbh->getScalar('user_users', 'u_id', array('u_name' => $uName)))) {
             $message = $this->translate('ERR_NO_U_NAME');
         } else {
             $password = User::generatePassword();
             $this->dbh->modify(QAL::UPDATE, 'user_users', array('u_password' => password_hash($password, PASSWORD_DEFAULT)), array('u_id' => $UID));
             $user = new User($UID);
             $template = new MailTemplate('user_restore_password', ['user_login' => $uName, 'user_name' => $user->getValue('u_fullname'), 'user_password' => $password, 'site_url' => E()->getSiteManager()->getCurrentSite()->base, 'site_name' => $this->translate('TXT_SITE_NAME')]);
             $mailer = new Mail();
             $mailer->setFrom($this->getConfigValue('mail.from'))->setSubject($template->getSubject())->setText($template->getBody())->setHtmlText($template->getHTMLBody())->addTo($uName);
             $message = $this->translate('MSG_PASSWORD_SENT');
             try {
                 $mailer->send();
             } catch (\Exception $e) {
                 $message = $e->getMessage();
             }
         }
     }
     $this->prepare();
     $messageField = new Field('restore_password_result');
     $messageField->setData($message);
     $this->getData()->addField($messageField);
 }
Exemplo n.º 2
0
 /**
  * Save data.
  *
  * @throws SystemException
  */
 protected function saveData()
 {
     $password = $_POST[$this->getTableName()]['u_password'] = User::generatePassword();
     try {
         $result = $this->user->create($_POST[$this->getTableName()]);
         $template = new MailTemplate('user_registration', ['user_login' => $this->user->getValue('u_name'), 'user_name' => $this->user->getValue('u_fullname'), 'user_password' => $password, 'site_url' => E()->getSiteManager()->getCurrentSite()->base, 'site_name' => $this->translate('TXT_SITE_NAME')]);
         $mailer = new Mail();
         $mailer->setFrom($this->getConfigValue('mail.from'));
         $mailer->setSubject($template->getSubject());
         $mailer->setText($template->getBody());
         $mailer->setHtmlText($template->getHTMLBody());
         $mailer->addTo($this->user->getValue('u_name'));
         $mailer->send();
     } catch (\Exception $error) {
         throw new SystemException($error->getMessage(), SystemException::ERR_WARNING);
     }
 }
Exemplo n.º 3
0
                        $vkUser = $res['response'][0];
                        $userInfo = ['u_name' => $vkUser['uid'] . '@vk.com', 'u_vkid' => $vkUser['uid'], 'u_password' => User::generatePassword(), 'u_fullname' => $vkUser['first_name'] . ' ' . $vkUser['last_name'], 'u_avatar_img' => $vkUser['photo']];
                        $user->create($userInfo);
                    } else {
                        throw new SystemException('TXT_CREATE_SOCIAL_USER_ERROR');
                    }
                }
                E()->UserSession->start($user->getID());
            }
        } catch (\Exception $e) {
            $response->addCookie(UserSession::FAILED_LOGIN_COOKIE_NAME, $e->getMessage(), time() + 60);
            goto escape;
        }
    } elseif ($gooAuth && ($appID = Primitive::getConfigValue('auth.goo.appID')) && ($secretKey = Primitive::getConfigValue('auth.goo.secretKey'))) {
        $goo = new \Energine\user\gears\GOOOAuth(['appId' => $appID, 'secret' => $secretKey]);
        try {
            if (!($user = User::getGOOUser($goo->user->id))) {
                //Если нет - создаем
                $user = new User();
                $userInfo = ['u_name' => $goo->user->email, 'u_gooid' => $goo->user->id, 'u_password' => User::generatePassword(), 'u_fullname' => $goo->user->name, 'u_avatar_img' => $goo->user->picture];
                $user->create($userInfo);
            }
            E()->UserSession->start($user->getID());
        } catch (Exception $e) {
            $response->addCookie(UserSession::FAILED_LOGIN_COOKIE_NAME, $e->getMessage(), time() + 60);
            goto escape;
        }
    }
}
escape:
$response->goBack();