/**
  * Register new user
  *
  * @param array $values
  * @return User
  * @throws Exception
  */
 public function registerUser(array $values = [])
 {
     $user = new User();
     $user->dateCreated = new RawValue('NOW()');
     $user->dateModified = new RawValue('NOW()');
     $user->publish = true;
     $user->deleted = false;
     $user->group_id = 1;
     $result = $user->save($values);
     if ($result === false) {
         throw new Exception(implode(', ', $user->getMessages()));
     }
     return $user;
 }
Beispiel #2
0
 /**
  * Installation finish.
  *
  * @return mixed
  *
  * @Route("/finish", methods={"GET", "POST"}, name="install-finish")
  */
 public function finishAction()
 {
     if (!$this->_isPassed('databaseAction')) {
         return $this->_selectAction();
     }
     $form = new FinishForm();
     if ($this->request->isPost() && $form->isValid()) {
         $password = $this->request->getPost('password', 'string');
         $repeatPassword = $this->request->getPost('repeatPassword', 'string');
         if ($password != $repeatPassword) {
             $form->addError("Passwords doesn't match!");
             $this->view->form = $form;
             return;
         }
         // Setup database.
         $this->_setupDatabase();
         $user = new User();
         $data = $form->getValues();
         $user->role_id = Role::getRoleByType('admin')->id;
         if (!$user->save($data)) {
             foreach ($user->getMessages() as $message) {
                 $form->addError($message);
             }
             $this->view->form = $form;
             return;
         }
         $this->_setPassed(__FUNCTION__, true);
         return $this->response->redirect(['for' => 'install-save']);
     }
     $this->view->form = $form;
 }
Beispiel #3
0
 /**
  * Register action.
  *
  * @return mixed
  *
  * @Route("/register", methods={"GET", "POST"}, name="register")
  */
 public function registerAction()
 {
     if (User::getViewer()->id) {
         return $this->response->redirect();
     }
     $form = new RegisterForm();
     if (!$this->request->isPost() || !$form->isValid()) {
         $this->view->form = $form;
         return;
     }
     $password = $form->getValue('password');
     $repeatPassword = $form->getValue('repeatPassword');
     if ($password != $repeatPassword) {
         $form->addError("Passwords doesn't match!", 'password');
         $this->view->form = $form;
         return;
     }
     $user = new User();
     $data = $form->getValues();
     $user->role_id = Role::getDefaultRole()->id;
     if (!$user->save($data)) {
         foreach ($user->getMessages() as $message) {
             $form->addError($message);
         }
         $this->view->form = $form;
         return;
     }
     $this->core->auth()->authenticate($user->id);
     return $this->response->redirect();
 }