/** * {@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); }
*/ $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.');
// change layout $this->useLayout('small.phtml'); $actionRow = UsersActions\Table::findRow(['userId' => $id, 'code' => $code]); $datetime1 = new \DateTime(); // now $datetime2 = new \DateTime($actionRow->expired); $interval = $datetime1->diff($datetime2); if (!$actionRow or $actionRow->action !== UsersActions\Table::ACTION_RECOVERY) { Messages::addError('Invalid code'); Response::redirectTo('index', 'index'); } elseif ($interval->invert) { Messages::addError('The activation code has expired'); $actionRow->delete(); Response::redirectTo('index', 'index'); } else { $user = Users\Table::findRow($id); $this->assign('user', $user); $this->assign('code', $code); if (Request::isPost()) { try { if (empty($password) or empty($password2)) { throw new Exception('Please enter your new password'); } if ($password != $password2) { throw new Exception('Please repeat your new password'); } // remove old auth record if ($oldAuth = Auth\Table::getInstance()->getAuthRow(Auth\Table::PROVIDER_EQUALS, $user->login)) { $oldAuth->delete(); } // create new auth record
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();
/** * authenticate user by token * * @param string $token * @throws \Bluz\Auth\AuthException * @return void */ public function authenticateToken($token) { $authRow = $this->checkToken($token); // get user profile $user = Users\Table::findRow($authRow->userId); // try to login $user->tryLogin(); }
/** * @param $auth * @return mixed */ public function alreadyRegisteredLogic($auth) { $user = Users\Table::findRow($auth->userId); if ($user->status != Users\Table::STATUS_ACTIVE) { Messages::addError('User is not active'); } $user->login(); $this->response->redirectTo('index', 'index'); }
use Bluz\Auth\AuthException; use Bluz\Application\Exception\BadRequestException; use Bluz\Application\Exception\NotFoundException; use Bluz\Proxy\Messages; use Bluz\Proxy\Request; return function ($password, $new_password, $new_password2) use($view) { /** * @var Bootstrap $this */ // change layout $this->useLayout('small.phtml'); $userId = $this->user()->id; /** * @var Users\Row $user */ $user = Users\Table::findRow($userId); if (!$user) { throw new NotFoundException('User not found'); } if (Request::isPost()) { // process form try { if (empty($password)) { throw new BadRequestException('Please input current password'); } if (empty($new_password)) { throw new BadRequestException('Please input new password'); } if (empty($new_password2)) { throw new BadRequestException('Please repeat new password'); }
<?php /** * Example of DB\Table usage * * @author Anton Shevchuk * @created 18.07.13 13:35 */ namespace Application; use Application\Test; return function () { /** * @var Bootstrap $this */ $table = Test\Table::getInstance(); debug($table->saveTestRow()); debug($table->saveTestRow()); debug($table->updateTestRows()); debug($table->updateTestRows()); debug($table->deleteTestRows()); debug($table->deleteTestRows()); $table = Users\Table::getInstance(); var_dump($table->getColumns()); return false; };