/**
  * 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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();
 }
Ejemplo n.º 4
0
 /**
  * Create action.
  *
  * @return void
  *
  * @Route("/create", methods={"GET", "POST"}, name="admin-user-create")
  */
 public function createAction()
 {
     $formData = [];
     $message = '';
     if ($this->request->hasPost('fsubmit')) {
         if ($this->security->checkToken()) {
             $formData = array_merge($formData, $this->request->getPost());
             $myUser = new UserModel();
             $myUser->assign($formData);
             $myUser->password = $this->security->hash($formData['password']);
             if ($myUser->create()) {
                 $this->flash->success(str_replace('###name###', $myUser->name, $this->lang->_('message-create-user-success')));
             } else {
                 foreach ($myUser->getMessages() as $msg) {
                     $message .= $this->lang->_($msg->getMessage()) . '<br />';
                 }
                 $this->flash->error($message);
             }
         } else {
             $this->flash->error($this->lang->_('default.message-csrf-protected'));
         }
     }
     $this->bc->add($this->lang->_('title-index'), 'admin/user');
     $this->bc->add($this->lang->_('title-create'), '');
     $this->view->setVars(['formData' => $formData, 'bc' => $this->bc->generate(), 'statusList' => UserModel::getStatusList(), 'roleList' => UserModel::getRoleList()]);
 }