/**
  * Edit the active user profile
  */
 public function editAction()
 {
     // Get session info
     $auth = $this->session->get('auth');
     /** @var Users $user */
     $user = Users::findFirst($auth['id']);
     if ($user == false) {
         return $this->forward('index/index');
     }
     if (!$this->request->isPost()) {
         $this->tag->setDefault('name', $user->name);
         $this->tag->setDefault('email', $user->email);
     } else {
         $name = $this->request->getPost('name', array('string', 'striptags'));
         $email = $this->request->getPost('email', 'email');
         $user->name = $name;
         $user->email = $email;
         if ($user->save() == false) {
             foreach ($user->getMessages() as $message) {
                 $this->flash->error((string) $message);
             }
         } else {
             $this->flash->success('Your profile information was updated successfully');
             $auth = ['id' => $user->id, 'name' => $user->name];
             $this->session->set('auth', $auth);
         }
     }
 }
 /**
  * This action authenticate and logs an user into the application
  */
 public function startAction()
 {
     if ($this->request->isPost()) {
         $email = $this->request->getPost('email');
         $password = $this->request->getPost('password');
         /** @var Users $user */
         $user = Users::findFirst(array("(email = :email: OR username = :email:) AND password = :password: AND active = 'Y'", 'bind' => ['email' => $email, 'password' => sha1($password)]));
         if ($user != false) {
             $this->registerSession($user);
             $this->flash->success('Welcome ' . $user->name);
             return $this->forward('invoices/index');
         }
         $this->flash->error('Wrong email/password');
     }
     return $this->forward('session/index');
 }