Ejemplo n.º 1
0
 /**
  * @param UI\Form $form
  *
  * @throws \Aprila\DuplicateEntryException
  */
 public function userFormSucceeded(UI\Form $form)
 {
     try {
         $values = $form->getValues();
         // if we not use images
         if (!isset($values->avatar)) {
             $values['avatar'] = NULL;
         }
         if (isset($values->id) && $values->id > 0) {
             $this->canUser('edit');
             // edit
             $this->userManager->edit($values->id, $values);
             $this->flashMessage('User was updated');
             $this->redirect('edit', $values->id);
         } else {
             $this->canUser('add');
             // add
             $person = $this->userManager->add($values);
             $this->flashMessage('User was added');
             $this->redirect('edit', $person->id);
         }
     } catch (DuplicateEntryException $e) {
         $form->addError('Duplicate username or email.');
     }
 }
 /**
  * @param UI\Form $form
  */
 public function changeEmailStepTwoFormSucceeded(UI\Form $form)
 {
     $values = $form->getValues();
     $newEmail = $this->userManager->changeEmailStepTwo($this->user->id, $values->code_one, $values->code_two);
     if ($newEmail) {
         // change identity email
         $this->user->identity->email = $newEmail;
         $this->flashMessage("Your email was changed");
     } else {
         $this->flashMessage("Ups... Something's wrong", 'error');
     }
 }
 /**
  * @param Form $form
  */
 public function recoveryStepTwoFormSucceeded(Form $form)
 {
     $values = $form->getValues();
     $user = $this->users->getBy(['email' => $values->email]);
     $verifed = $this->users->verifyToken($values->token, $user->id);
     if ($verifed) {
         $newPassword = Random::generate(22);
         $this->users->setUserPassword($newPassword, $user->id);
         $this->getUser()->login($user->username, $newPassword);
         $this->flashMessage('Set your new password.');
         $session = $this->session->getSection('forgotPassword');
         $session->password = $newPassword;
         $this->redirect('UserSettings:password');
     } else {
         $this->flashMessage('Problem with security code. Try again.', 'error');
     }
 }
Ejemplo n.º 4
0
 public function handleDeleteAvatar()
 {
     $status = $this->mainManager->removeAvatar($this->user->getId());
     if ($status) {
         $this->user->identity->avatar_filename = '';
         $this->user->identity->avatar_namespace = '';
         $this->flashMessage('Photo was removed');
     } else {
         $this->flashMessage('Problem with photo removing', 'error');
     }
     $this->detailObject = $this->mainManager->get($this->getUser()->getId());
     if ($this->isAjax()) {
         $this->redrawControl('profilePhoto');
         $this->redrawControl('layoutAvatar');
     } else {
         $this->redirect('this');
     }
 }
Ejemplo n.º 5
0
 /**
  * User form factory.
  *
  * @return \Nette\Application\UI\Form
  */
 protected function createComponentUserForm()
 {
     $userRoleArray = $this->mainManager->findUserRoles($this->getUser());
     $form = BaseFormRenderer::factory();
     $form->addText('username', 'Username:'******'Please enter username.');
     $password = $form->addPassword('password', 'Password:'******'class', 'b-password-input--with-strength')->addCondition(Form::FILLED)->addRule(Form::MIN_LENGTH, 'Password min length is %d chars', 6);
     if (!$this->detailObject) {
         $password->setRequired('Please enter password.');
     }
     $form->addText('email', 'E-mail:')->setRequired('Please enter e-mail.')->addRule(Form::EMAIL, 'This is not valid e-mail.');
     $form->addText('name', 'Name:');
     $form->addUpload('avatar', 'Avatar:')->addCondition(Form::FILLED)->addRule(Form::IMAGE, 'Please select image file');
     $form->addSelect("role", "User role:", $userRoleArray)->setRequired('Select user role.');
     if ($this->detailObject) {
         $form->addHidden('id');
         $form->setDefaults($this->detailObject);
     } else {
         $form->addCheckbox("sendInstructions", "Send instructions?");
     }
     $form->addSubmit('send', $this->detailObject ? 'Save user' : 'Add user');
     $form->onSuccess[] = $this->objectFormSucceeded;
     return $form;
 }