Example #1
0
 /**
  * {@inheritdoc}
  *
  * @param string $module
  * @param string $controller
  * @param array $params
  * @return void
  */
 protected function preDispatch($module, $controller, $params = array())
 {
     // auth as CLI user
     $cliUser = Table::findRowWhere(['login' => 'system']);
     Auth::setIdentity($cliUser);
     parent::preDispatch($module, $controller, $params);
 }
Example #2
0
  */
 $user = Users\Table::findRow($userId);
 if (!$user) {
     throw new NotFoundException('User not found');
 }
 $this->assign('email', $user->email);
 if (Request::isPost()) {
     // process form
     try {
         if (empty($password)) {
             throw new Exception('Password is empty');
         }
         // login/password
         Auth\Table::getInstance()->checkEquals($user->login, $password);
         // check email for unique
         $emailUnique = Users\Table::findRowWhere(['email' => $email]);
         if ($emailUnique && $emailUnique->id != $userId) {
             throw new Exception('User with email "' . htmlentities($email) . '" already exists');
         }
         // generate change mail token and get full url
         $actionRow = UsersActions\Table::getInstance()->generate($userId, Table::ACTION_CHANGE_EMAIL, 5, ['email' => $email]);
         $changeUrl = Router::getFullUrl('users', 'change-email', ['token' => $actionRow->code]);
         $subject = __("Change email");
         $body = $this->dispatch('users', 'mail/template', ['template' => 'change-email', 'vars' => ['user' => $user, 'email' => $email, 'changeUrl' => $changeUrl, 'profileUrl' => Router::getFullUrl('users', 'profile')]])->render();
         try {
             $mail = Mailer::create();
             $mail->Subject = $subject;
             $mail->msgHTML(nl2br($body));
             $mail->addAddress($email);
             Mailer::send($mail);
             Messages::addNotice('Check your email and follow instructions in letter.');
Example #3
0
 if (Request::isPost()) {
     try {
         // check email
         if (empty($email)) {
             throw new Exception('Email can\'t be empty');
         }
         if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
             list(, $domain) = explode("@", $email, 2);
             if (!checkdnsrr($domain, "MX") && !checkdnsrr($domain, "A")) {
                 throw new Exception('Email has invalid domain name');
             }
         } else {
             throw new Exception('Email is invalid');
         }
         // check exists
         $user = Users\Table::findRowWhere(['email' => $email]);
         if (!$user) {
             throw new Exception('Email not found');
         }
         // check status, only for active users
         if ($user->status != Users\Table::STATUS_ACTIVE) {
             throw new Exception('User is inactive');
         }
         // create activation token
         // valid for 5 days
         $actionRow = UsersActions\Table::getInstance()->generate($user->id, UsersActions\Table::ACTION_RECOVERY, 5);
         // send activation email
         // generate restore URL
         $resetUrl = Router::getFullUrl('users', 'recovery-reset', ['code' => $actionRow->code, 'id' => $user->id]);
         $subject = "Password Recovery";
         $body = $this->dispatch('users', 'mail-template', ['template' => 'recovery', 'vars' => ['user' => $user, 'resetUrl' => $resetUrl]])->render();