Exemplo n.º 1
0
 /**
  * Renders registration form and registers user in the system after form submitting
  *
  * @return string
  */
 public function signinAction()
 {
     $this->_redirectIfLoggedIn();
     $errors = array();
     if (Request::isPost()) {
         $model = new SecurityModel();
         $model->set('email', Request::get('email'))->set('password', Request::get('password'));
         if ($model->isValid()) {
             try {
                 $model->insert();
                 $this->redirect('/login');
             } catch (DatabaseException $e) {
                 $errors['email'] = 'Email already exists!';
             }
         } else {
             $errors = $model->getErrors();
         }
     }
     return $this->_renderView('signin.html', array('errors' => $errors));
 }
Exemplo n.º 2
0
 /**
  * Updates user's profile
  *
  * @return string
  */
 public function updateAction()
 {
     if (!$this->getUser()) {
         $this->redirect('/login', 'Please, login first!');
     }
     $errors = array();
     $model = new SecurityModel();
     $model->setItem($this->getUser());
     $model->set('email', Request::get('email'))->set('name', Request::get('name'));
     if ($model->isValid()) {
         try {
             $model->update();
             $this->redirect('/', 'Data has been saved successfully');
         } catch (DatabaseException $e) {
             $errors['email'] = 'Email already exists!';
         }
     } else {
         $errors = $model->getErrors();
     }
     return $this->_renderView('form.html', array('user' => $this->getUser(), 'errors' => $errors));
 }