Exemplo n.º 1
0
 public function signUpAction()
 {
     $this->view->error = '';
     if ($this->getRequest()->isMethod('POST')) {
         $data = $this->getRequest()->request->get('user', null);
         if (is_array($data)) {
             if ($data['password1'] == $data['password2']) {
                 $user = new User();
                 $user->setEmail($data['email'])->setFirstname($data['firstname'])->setSurname($data['surname'])->setPassword($data['password1']);
                 $this->getRepository('users')->save($user);
                 return $this->app->redirect('/user/login');
             } else {
                 $this->view->error = 'Two passwords must match';
             }
         }
     }
     return $this->view->render();
 }
Exemplo n.º 2
0
 public function save(User $user)
 {
     $data = ['id' => $user->getId(), 'firstname' => $user->getFirstname(), 'surname' => $user->getSurname(), 'email' => $user->getEmail()];
     if (strlen($user->getPassword()) != 88) {
         $data['salt'] = uniqid(mt_rand());
         $data['password'] = $this->encoder->encodePassword($user->getPassword(), $data['salt']);
     }
     if ($user->getId()) {
         $this->db->update('users', $data, ['id' => $user->getId()]);
     } else {
         $data['c_date'] = date('Y-m-d H:i:s');
         $this->db->insert('users', $data);
         $user->setCDate($data['c_date']);
         $id = $this->db->lastInsertId();
         $user->setId($id)->setSalt($data['salt'])->setPassword($data['password']);
     }
 }