function work(Request $request) { $user = Auth::get_user(); if ($user->is_exists()) { if (!$user->confirm->is_draft()) { //новый и еще неактивный $this->_result = 5; } else { //Есть такой активный пользователь $this->_result = 4; } //пользователя еще нет } else { if ($request['REQUEST']['form']) { //Присвоим email новому пользователю и проверим уникальность $user->email->value($request['REQUEST']['email']); if ($request['REQUEST']['call'] == 'check') { if (!$user->check()) { if ($user->errors()->email->value->duplicate) { $this->_result = 2; } else { //Другая ошибка $this->_result = 3; } } else { //все корректно $this->_result = 1; } $session['result'] = $this->_result; Session::set('form', array($this->uri() . $this->getToken() => $session)); setcookie('token', $this->getToken(), 0, '/'); return $session; } else { if (isset($request['COOKIE']['token']) && Session::is_exist('form')) { $form = Session::get('form'); if (isset($form[$this->uri() . $request['COOKIE']['token']])) { $form = $form[$this->uri() . $request['COOKIE']['token']]; Session::remove('form'); } if (isset($form['result'])) { $this->_result = $form['result']; } } if ($this->_result == 1 && isset($user)) { $user->password->value($request['REQUEST']['password']); $user->title->value($request['REQUEST']['email']); $user->confirm->proto("/vendor/boolive/basic/string"); $user->confirm->value(uniqid('', true)); Data::write($user); //Теперь у нас есть такой пользователь $this->_result = 5; $this->mailSender->sendMail($to = $user->email->value(), $subject = 'Подтвержление регистрации на ' . $this->mailSender->domain->value(), $message = 'Здравствйте, вы зарегистрировались на ' . $this->mailSender->domain->value() . ' , для подтверждения актуальности электронного адреса, перейдите, пожалуйста по <a href="' . $this->mailSender->domain->value() . '/profile?confirm=' . $user->confirm->value() . '">ссылке</a>'); $request->redirect('profile?confirm=0'); } } } } return parent::work($request); }
function work(Request $request) { $user = Auth::get_user(); if ($user->uri() != '/system/users/admin') { $request->redirect('sign-in'); } $request->mix(['REQUEST' => ['object' => mb_substr($request['REQUEST']['path'], mb_strlen($this->path))]]); return parent::work($request); }
function work(Request $request) { if ($request['REQUEST']['form']) { if ($request['REQUEST']['agree']) { $request->redirect('ask'); } } else { return parent::work($request); } }
function work(Request $request) { if ($request['REQUEST']['form']) { $session = array(); try { self::$config = Config::read('auth'); $result = Data::find(array('from' => self::$config['users-list'], 'select' => 'children', 'depth' => 'max', 'where' => array(['child', 'email', array('value', '=', $request['REQUEST']['email'])], ['child', 'password', array('value', '=', $request['REQUEST']['password'])]), 'key' => false, 'limit' => array(0, 1), 'comment' => 'sign-in user by email and password'), false); if (!empty($result)) { $user = $result[0]; Auth::set_user($user); if ($request['REQUEST']['remember-me']) { Auth::set_user($user, 1234565); } $request->redirect(self::$config['redirect']); } else { $this->_result = 0; } } catch (\Exception $error) { $this->_result = 0; } $session['result'] = $this->_result; Session::set('form', array($this->uri() . $this->getToken() => $session)); setcookie('token', $this->getToken(), 0, '/'); return $session; } else { // Отображение формы $v = array(); if (isset($request['COOKIE']['token']) && Session::is_exist('form')) { $form = Session::get('form'); if (isset($form[$this->uri() . $request['COOKIE']['token']])) { $form = $form[$this->uri() . $request['COOKIE']['token']]; Session::remove('form'); } if (isset($form['result'])) { $this->_result = $form['result']; } } $this->res->start($request); return $this->show($v, $request); } }