Ejemplo n.º 1
0
 /**
  * Create new user.
  *
  * @return mixed
  *
  * @Route("/create", methods={"GET", "POST"}, name="admin-users-create")
  */
 public function createAction()
 {
     $form = new CreateForm();
     $this->view->form = $form;
     if (!$this->request->isPost() || !$form->isValid(null, true)) {
         return;
     }
     $user = $form->getEntity();
     $user->setPassword($user->password);
     $user->role_id = Role::getDefaultRole()->id;
     $user->save();
     $this->flashSession->success('New object created successfully!');
     return $this->response->redirect(['for' => 'admin-users']);
 }
Ejemplo n.º 2
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();
 }