/** * @inheritDoc */ protected function _beforeInsert() { $this->_fields['salt'] = uniqid(); $this->_fields['password'] = Token::cryptPassword($this->_fields['password'], $this->_fields['salt']); $this->_fields['name'] = 'User'; $date = $this->_getCurrentDate(); $this->_fields['created_at'] = $date->format('Y-m-d'); $this->_fields['last_activity'] = $date->format('Y-m-d H:i:s'); }
/** * Renders login form and authenticates user after form submitting * * @return string */ public function loginAction() { $this->_redirectIfLoggedIn(); $errors = array(); if (Request::isPost()) { $model = new SecurityModel(); if ($item = $model->set('email', Request::get('email'))->getItem()) { if (0 === strcmp(Token::cryptPassword(Request::get('password'), $item->salt), $item->password)) { Token::setUser($item); $this->redirect('/'); } } array_push($errors, 'Invalid username or password'); } return $this->_renderView('login.html', array('errors' => $errors)); }