Наследование: extends Nette\Object, implements Nette\Security\IAuthenticator
 /**
  * Callback for Account Settings Form onSuccess event.
  * @param Form      $form
  * @param ArrayHash $values
  */
 public function formSucceeded(Form $form, $values)
 {
     if (!$this->userManager->checkPassword($this->user->getId(), $values->current)) {
         $form->addError("Invalid current password");
     }
     $this->userManager->setNewPassword($this->user->getId(), $values->new);
 }
Пример #2
0
 public function actionDetail($id = '')
 {
     if (!$id) {
         throw new \Nette\Application\BadRequestException();
     }
     $this->userDat = $this->userManager->getUserData($id);
 }
 /**
  * Callback for ForgottenPasswordForm onSuccess event.
  * @param Form      $form
  * @param ArrayHash $values
  */
 public function formSucceeded(Form $form, $values)
 {
     $user = $this->userManager->findByEmail($values->email);
     if (!$user) {
         $form->addError('No user with given email found');
         return;
     }
     $password = Nette\Utils\Random::generate(10);
     $this->userManager->setNewPassword($user->id, $password);
     try {
         // !!! Never send passwords through email !!!
         // This is only for demonstration purposes of Notejam.
         // Ideally, you can create a unique link where user can change his password
         // himself for limited amount of time, and then send the link.
         $mail = new Nette\Mail\Message();
         $mail->setFrom('*****@*****.**', 'Notejamapp');
         $mail->addTo($user->email);
         $mail->setSubject('New notejam password');
         $mail->setBody(sprintf('Your new password: %s', $password));
         $this->mailer->send($mail);
     } catch (Nette\Mail\SendException $e) {
         Debugger::log($e, Debugger::EXCEPTION);
         $form->addError('Could not send email with new password');
     }
 }
Пример #4
0
 public function succeeded(Form $form, $values)
 {
     try {
         $this->userManager->updatePassword($values, $this->userId);
     } catch (Nette\Security\AuthenticationException $e) {
         $form->addError($e->getMessage());
     }
 }
Пример #5
0
 /**
  * Callback for SignUpForm onSuccess event.
  * @param Form      $form
  * @param ArrayHash $values
  */
 public function formSucceeded(Form $form, $values)
 {
     try {
         $this->userManager->add($values->email, $values->password);
     } catch (DuplicateNameException $e) {
         $form->addError($e->getMessage());
     }
 }
 public function formSucceeded(Form $form, $values)
 {
     try {
         $userManager = new Model\UserManager($this->user, $this->database);
         $userManager->saveprofile($form->getHttpData($form::DATA_TEXT, 'profile_email_input'), $form->getHttpData($form::DATA_TEXT, 'profile_telephone_input'), $form->getHttpData($form::DATA_TEXT, 'profile_address_input'), $form->getHttpData($form::DATA_TEXT | $form::DATA_KEYS, 'profile_comment_input'));
     } catch (Nette\Security\AuthenticationException $e) {
         $form->addError($e->getMessage());
     }
 }
Пример #7
0
 /**
  * Form sent
  * @param Form $form
  * @param $values
  */
 public function succeeded(Form $form, $values)
 {
     $id = explode('/', $this->request->url->path);
     try {
         $this->userManager->newPassword($id[3], $values->mail, $values->password);
     } catch (\Exception $e) {
         $form->addError($e->getMessage());
     }
 }
Пример #8
0
 public function registerFormSucceeded($form, $values)
 {
     try {
         $this->userManager->registerNew($values->mail, $values->password, isset($values->nickName) ? $values->nickName : '');
     } catch (\Exception $e) {
         $form->addError($e->getMessage());
     }
     $this->goHome('Registrace byla úspěšná, vyčkejte na ověřovací mail. Sdělte heslo majiteli', 'this');
 }
Пример #9
0
 /**
  * @param Form $form
  * @param $values
  */
 function registerFormSucceeded(Form $form, $values)
 {
     try {
         $this->userManager->add($values->username, $values->password, $values->email, UserManager::ROLE_USER, $values->name);
         $this->flashMessage('Your account has been successfully created. You can now login.', 'success');
         $this->redirect('in');
     } catch (DuplicateNameException $e) {
         $this->flashMessage('User with this username or e-mail address already exists.', 'warning');
     }
 }
Пример #10
0
 public function registerFormSucceeded($form)
 {
     $values = $form->values;
     if ($values->password == $values->password2) {
         $this->userManager->add($values->login, $values->password, $values->email);
         $this->flashMessage('You have been successfully registered.');
     } else {
         $this->flashMessage('Both passwords must match.');
     }
 }
 public function formSucceeded(Form $form, $values)
 {
     $userManager = new Model\UserManager($this->user, $this->database);
     $error = $userManager->changePassword($this->id, $values);
     if ($error != null) {
         $form->addError($error);
     }
     if ($form->getPresenter()->isAjax()) {
         $form->getPresenter()->redrawControl('password');
     }
 }
Пример #12
0
 public function formSucceeded($form, $values)
 {
     // $stop();
     $user = $this->userManager->add($values->fullname, $values->role, $values->email, $values->password);
     if ($user == false) {
         $form->addError('Tento email je již používán!');
     } else {
         $this->user->login($values->email, $values->password);
         $this->user->setExpiration('14 days', FALSE);
     }
 }
 public function formSucceeded(Form $form, $values)
 {
     try {
         $userManager = new Model\UserManager($this->user, $this->database);
         $userManager->register($values->username, $values->password, $values->repassword);
     } catch (Nette\Security\AuthenticationException $e) {
         $form->addError($e->getMessage());
     }
     if ($form->getPresenter()->isAjax()) {
         $form->getPresenter()->redrawControl('register');
     }
 }
Пример #14
0
 public function userFormSucceeded($button)
 {
     $values = $button->getForm()->getValues();
     $id = (int) $this->getParameter('id');
     if ($id) {
         $this->database->table('users')->get($id)->update(array('username' => $values->username, 'password' => Passwords::hash($values->password), 'email' => $values->email));
         $this->flashMessage('User has been updated.');
     } else {
         $this->userManager->add($values->username, $values->password, $values->email);
         $this->flashMessage('User has been added.');
     }
     $this->redirect('Homepage:');
 }
Пример #15
0
 public function formSucceeded(RegistrationForm $form)
 {
     if ($form['remember']->getValue()) {
         $this->user->setExpiration('14 days', false);
     } else {
         $this->user->setExpiration('20 minutes', true);
     }
     $date = DateTime::createFromFormat('Y-m-d', date("Y-m-d"));
     try {
         $this->manager->add($form['username']->getValue(), $form['password']->getValue(), $form['email']->getValue(), $date);
         $this->user->login($form['username']->getValue(), $form['password']->getValue());
     } catch (Nette\Security\AuthenticationException $e) {
         $form->addError($e->getMessage());
     }
 }
Пример #16
0
 public function enterCodeSucceeded(Form $form, $values)
 {
     if ($form['check']->isSubmittedBy()) {
         $code = $values->checkCode;
         try {
             $this->userManager->changeMailOk($this->user->getIdentity(), $code);
             $this->goHome('Mail úspěšně změnen', 'Setting:');
         } catch (\Exception $e) {
             $form->addError($e->getMessage());
         }
     } else {
         $this->userManager->changeMailFail($this->user->getIdentity());
         $this->goHome('Zkontrolujete si mail ' . $this->user->getIdentity()->mail . ' a znovu ho ověřte.');
     }
 }
Пример #17
0
 public function formSucceeded(Form $form, $values)
 {
     try {
         $user = $this->um->add($values->email, $values->password, $values->name);
         if ($user) {
             $this->user->login($values->email, $values->password);
             $this->onSuccess();
         } else {
             $form->addError('Oops! Your account could not be created for some reason :-(');
             $this->redrawControl('form');
         }
     } catch (\App\Model\DuplicateEmailException $e) {
         $form->addError('Sorry, this email address is already registered. Sign in or use another one.');
         $this->redrawControl('form');
     }
 }
Пример #18
0
 public function formSucceeded(Form $form, $values)
 {
     if ($values->remember) {
         $this->user->setExpiration('14 days', FALSE);
     } else {
         $this->user->setExpiration('20 minutes', TRUE);
     }
     try {
         $userManager = new Model\UserManager($this->user, $this->database);
         $userManager->login($values->username, $values->password);
     } catch (Nette\Security\AuthenticationException $e) {
         $form->addError($e->getMessage());
     }
     if ($form->getPresenter()->isAjax()) {
         $form->getPresenter()->redrawControl('sign');
     }
 }
Пример #19
0
 public function actionChangePassword($id)
 {
     $item = $this->item->get($id);
     if (!$item) {
         $this->error('Data pod ID ' . $id . ' nebyla nalezena v databázi.', 404);
     }
     // TODO: udělat
     $this->redirect('default');
 }
Пример #20
0
 /**
  * @return Form
  */
 public function create(callable $onSuccess)
 {
     $form = $this->factory->create();
     $form->addText('username', 'Pick a username:'******'Please pick a username.');
     $form->addEmail('email', 'Your e-mail:')->setRequired('Please enter your e-mail.');
     $form->addPassword('password', 'Create a password:'******'description', sprintf('at least %d characters', self::PASSWORD_MIN_LENGTH))->setRequired('Please create a password.')->addRule($form::MIN_LENGTH, NULL, self::PASSWORD_MIN_LENGTH);
     $form->addSubmit('send', 'Sign up');
     $form->onSuccess[] = function (Form $form, $values) use($onSuccess) {
         try {
             $this->userManager->add($values->username, $values->email, $values->password);
         } catch (Model\DuplicateNameException $e) {
             $form['username']->addError('Username is already taken.');
             return;
         }
         $onSuccess();
     };
     return $form;
 }
Пример #21
0
 public function actionDelete($id, $backlink = NULL)
 {
     $d = $this->uzivateleModel->odstran($id);
     if ($d) {
         $this->flashMessage("Odstraněno", 'success');
     } else {
         $this->flashMessage("Nezdařilo se odstranit", 'error');
     }
     $this->restoreRequest($backlink);
     $this->redirect("uzivatele");
 }
Пример #22
0
 private function create()
 {
     $form = new Form();
     $form->addText('title', 'Titulek')->setRequired('Zadejte titulek')->setAttribute('placeholder', 'Zadejte titulek');
     if ($this->user->isAllowed(self::RES, 'moderate')) {
         $users = $this->userManager->getUserList();
         $form->addSelect('byUser', 'Za uživatele', ['0' => 'Neregistrovaný'] + $users['deleted'] + $users['allowed'])->setValue($this->user->id);
         $form->addText('byUnregUser', 'Za neregistrovaného uživatele');
     }
     $form->addTextArea('description', 'Popis')->setRequired('Zadejte popis');
     $form->addTextArea('text', 'Článek')->setRequired('Zadejte článek');
     $form->addText('keyWords', 'Klíčová slova');
     $form->addCheckbox('commentsAllow', 'Povolit komentáře');
     $form->addCheckbox('voteAllow', 'Povolit hlasování');
     $form->addUpload('photo', 'Náhledová fotka');
     if ($this->setSection) {
         $form->addSelect('underSection', 'Hlavní sekce', $this->articleManager->getMainSectionList())->setValue($this->setSection);
         if ($this->setSubsection) {
             $form->addSelect('underSubSection', 'Podsekce', $this->articleManager->getSubSectionList($this->setSection))->setValue($this->setSubsection);
             if ($this->setSerial) {
                 $form->addSelect('underSerial', 'Serial', $this->articleManager->getSerialList($this->setSubsection))->setValue($this->setSerial);
             } else {
                 $form->addSelect('underSerial', 'Serial', $this->articleManager->getSerialList($this->setSubsection))->setPrompt('Vyberte');
             }
         } else {
             $form->addSelect('underSubSection', 'Podsekce', $this->articleManager->getSubSectionList($this->setSection))->setPrompt('Vyberte podsekci');
             $form->addSelect('underSerial', 'Serial')->setPrompt('Vyberte podsekci');
         }
     } else {
         $form->addSelect('underSection', 'Hlavní sekce', $this->articleManager->getMainSectionList())->setPrompt('Vyberte hlavní sekci');
         $form->addSelect('underSubSection', 'Podsekce')->setPrompt('Vyberte hlavní sekci');
         $form->addSelect('underSerial', 'Serial')->setPrompt('Vyberte hlavní sekci');
     }
     if ($this->user->isAllowed('Section', 'moderate')) {
     }
     if ($this->user->isAllowed(self::RES, 'publish')) {
         $form->addCheckbox('published', 'Publikovaný ihned');
     }
     $form->addSubmit('submitArticle', 'Odeslat')->setValidationScope(false);
     return $form;
 }
Пример #23
0
 /**
  * First step to make new password
  * @param type $id
  */
 public function actionNewPass($id)
 {
     if (empty($id)) {
         $this->goHome();
     }
     $this->isLoggedLogoutUser();
     $name = $this->userManager->newPasswordCheck($id);
     if (!$name) {
         $this->goHome('Tento odkaz je starý, prosím požádejte o heslo znovu.', 'Log:lostPass', [], 'waring');
     }
     $this->template->name = $name;
 }
Пример #24
0
 public function authenticate(array $credentials)
 {
     list($username, $password) = $credentials;
     $mcrypt = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CBC, '');
     $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($mcrypt), MCRYPT_DEV_RANDOM);
     mcrypt_generic_init($mcrypt, $this->authKey, $iv);
     $url = $this->buildAuthUrl($username, $password, $mcrypt, $iv);
     list($code, $body) = $this->httpGet($url);
     if ($code === 404) {
         throw new Nette\Security\AuthenticationException("User '{$username}' not found.", self::IDENTITY_NOT_FOUND);
     } elseif ($code === 403) {
         throw new Nette\Security\AuthenticationException('Invalid password.', self::INVALID_CREDENTIAL);
     } elseif ($code !== 200) {
         throw new Nette\Security\AuthenticationException("Nette.org endpoint hung with code {$code}.");
     }
     $json = Json::decode(trim(mdecrypt_generic($mcrypt, $body)));
     $user = $this->userManager->signInUpdate($json->id, ['username' => $username, 'email' => $json->email, 'name' => $json->realname]);
     if (!$user) {
         $user = $this->userManager->create(['id' => $json->id, 'username' => $username, 'password' => '', 'email' => $json->email, 'role' => 'user', 'active' => TRUE, 'name' => $json->realname, 'avatar' => '']);
     }
     return new Nette\Security\Identity($user->id, $user->role, ['username' => $user->username, 'name' => $user->name, 'email' => $user->email]);
 }
Пример #25
0
 public function formSucceeded(Form $form, $values)
 {
     if ($this->id == null) {
         try {
             $userManager = new Model\UserManager($this->user, $this->database);
             try {
                 $new_user = $userManager->register($values);
                 if (!$new_user) {
                     $form->addError('Registrace z neznámého důvodu selhala. Zkuste se prosím zaregistrovat znovu a pokud problémy přetrvají, kontaktujete helpdesk.');
                 }
             } catch (\PDOException $e) {
                 if ($e->getCode() == 23000) {
                     $form->addError('Zájemce s tímto nickem už je zaregistrován, zvolte prosím jiný nick.');
                 } else {
                     $form->addError($e->getMessage());
                 }
             }
         } catch (Nette\Security\AuthenticationException $e) {
             $form->addError($e->getMessage());
         }
         if ($form->getPresenter()->isAjax()) {
             $form->getPresenter()->redrawControl('registration');
         }
     } else {
         $database = new Model\Database($this->database);
         $user = $database->findById('user', $this->id);
         if ($user) {
             $user->update($values);
             $this->user->identity->name = $values->name;
         } else {
             $form->addError('Uživatel, kterého se snažíte upravit, neexistuje. Je možné, že ho někdo smazal.');
         }
         if ($form->getPresenter()->isAjax()) {
             $form->getPresenter()->redrawControl('profile');
         }
     }
 }
Пример #26
0
 /**
  * Form OK
  * @param Form $form
  */
 public function formSucceeded(Form $form)
 {
     $values = $form->getValues(TRUE);
     if (!$values['photo']->isImage() && $values['photo']->isOK()) {
         $form->addError('Toto není obrázek');
     } else {
         $date = $this->parseDateDatabase($values['year'], $values['month'], $values['day']);
         if ($date === false) {
             $form->addError('Takové datum neexistuje');
         } else {
             $values['born'] = $date;
             try {
                 if (isset($values['privileges'])) {
                     $privileges = $this->parsePrivileges($values['privileges']);
                     unset($values['privileges']);
                     $values['permissions'] = $privileges;
                 }
                 $this->userManager->updateUser($values, isset($values['id']) ? $values['id'] : $this->user);
             } catch (\Exception $e) {
                 $form->addError($e->getMessage());
             }
         }
     }
 }
Пример #27
0
 /**
  * Show view from browser or console.
  *
  * @param bool $console
  */
 public function run(bool $console)
 {
     $this->userManager->register()->view($console);
 }
Пример #28
0
 public function osobaCreateFormSucceeded(Form $form, $values)
 {
     if (!$this->user->loggedIn) {
         $this->error('Pro tuto akci musí být uživatel přihlášen.');
     }
     if (!$this->user->isInRole('spravce')) {
         $this->error('Omlouváme se, ale tato funkce je pouze pro správce.');
     }
     $osoby = $this->parseOsoby($values->osoby);
     foreach ($osoby as &$osoba) {
         $heslo = Model\UserManager::genPassword(10);
         $osoba['heslo'] = sha1($heslo);
         $osoba['chceMaily'] = 1;
         $this->mailer->sendRegistrace($osoba['jmeno'], $heslo, $osoba['email']);
         $id = $this->uzivatel->insert($osoba);
         $this->role->insert(array('role' => 1, 'uzivatel_id' => $id));
     }
     $this->flashMessage('Uživatelé byli úspěšně zaregistrováni. Heslo jim bylo zasláno na uvedený email.', 'success');
     $this->log->l('uzivatel.masscreate', count($osoby));
     $this->redirect('Osoby:default');
 }