Ejemplo n.º 1
0
 public function userMailChangeFormSubmitted($button)
 {
     $values = $button->getForm()->getValues();
     //Nacitanie hodnot formulara
     $this->clen = $this->user_profiles->find($values->id);
     //Najdenie clena
     if (!$this->hasser->CheckPassword($values->heslo, $this->clen->users->password)) {
         $this->flashRedirect('this', $this->trLang('pass_incorect'), 'danger');
     }
     // Over, ci dany email uz existuje. Ak ano konaj.
     if ($this->users->testEmail($values->email)) {
         $this->flashMessage(sprintf($this->trLang('mail_change_email_duble'), $values->email), 'danger');
         return;
     }
     //Vygeneruj kluc pre zmenu e-mailu
     $email_key = $this->hasser->HashPassword($values->email . StrFTime("%Y-%m-%d %H:%M:%S", Time()));
     $clen = $this->user_profiles->find(1);
     //Najdenie odosielatela emailu
     $templ = new Latte\Engine();
     $params = ["site_name" => $this->nazov_stranky, "nadpis" => sprintf($this->trLang('email_change_mail_nadpis'), $this->nazov_stranky), "email_change_mail_txt" => sprintf($this->trLang('email_change_mail_txt'), $this->nazov_stranky), "email_change_mail_txt1" => $this->trLang('email_change_mail_txt1'), "email_nefunkcny_odkaz" => $this->trLang('email_nefunkcny_odkaz'), "email_pozdrav" => $this->trLang('email_pozdrav'), "nazov" => $this->trLang('mail_change'), "odkaz" => 'http://' . $this->nazov_stranky . $this->link("UserLog:activateNewEmail", $this->clen->id, $email_key)];
     $mail = new Message();
     $mail->setFrom($this->nazov_stranky . ' <' . $clen->users->email . '>')->addTo($values->email)->setSubject($this->trLang('mail_change'))->setHtmlBody($templ->renderToString(__DIR__ . '/templates/UserLog/email_change-html.latte', $params));
     try {
         $sendmail = new SendmailMailer();
         $sendmail->send($mail);
         $this->users->find($this->clen->id_users)->update(['new_email' => $values->email, 'new_email_key' => $email_key]);
         $this->flashRedirect('UserLog:', $this->trLang('mail_change_send_ok'), 'success');
     } catch (Exception $e) {
         $this->flashMessage($this->trLang('mail_change_send_err') . $e->getMessage(), 'danger');
     }
 }
Ejemplo n.º 2
0
 /** Spracovanie reistracneho formulara
  * @param Nette\Application\UI\Form $button Data formulara
  */
 public function userRegisterFormSubmitted($button)
 {
     // Inicializacia
     $values = $button->getForm()->getValues();
     //Nacitanie hodnot formulara
     // Over, ci dane username uz existuje. Ak ano vypis a skonc.
     if ($this->users->testUsername($values->username)) {
         $this->flashMessage($this->trLang('registracia_username_duble'), 'danger');
         return;
     }
     // Over, ci dany email uz existuje. Ak ano vypis a skonc.
     if ($this->users->testEmail($values->email)) {
         $this->flashMessage(sprintf($this->trLang('registracia_email_duble'), $values->email, $this->link('User:forgotPassword')), 'danger,n');
         return;
     }
     $new_password_key = $this->hasser->HashPassword($values->heslo . StrFTime("%Y-%m-%d %H:%M:%S", Time()));
     $uloz_data_user_profiles = ['meno' => $values->meno, 'priezvisko' => $values->priezvisko, 'pohl' => isset($values->pohl) ? $values->pohl : 'Z', 'modified' => StrFTime("%Y-%m-%d %H:%M:%S", Time()), 'created' => StrFTime("%Y-%m-%d %H:%M:%S", Time())];
     $uloz_data_users = ['username' => $values->username, 'password' => $this->hasser->HashPassword($values->heslo), 'email' => $values->email, 'activated' => 0];
     //Uloz info do tabulky users
     if (($uloz_users = $this->users->uloz($uloz_data_users)) !== FALSE) {
         //Ulozenie v poriadku
         $uloz_data_user_profiles['id_users'] = $uloz_users['id'];
         //nacitaj id ulozeneho clena
         $uloz_user_profiles = $this->user_profiles->uloz($uloz_data_user_profiles);
     }
     if ($uloz_user_profiles !== FALSE) {
         //Ulozenie v poriadku
         $this->flashMessage($this->trLang('base_save_ok'), 'success');
         $templ = new Latte\Engine();
         $params = ["site_name" => $this->nazov_stranky, "nadpis" => sprintf($this->trLang('email_activate_nadpis'), $this->nazov_stranky), "email_activate_txt" => $this->trLang('email_activate_txt'), "email_nefunkcny_odkaz" => $this->trLang('email_nefunkcny_odkaz'), "email_pozdrav" => $this->trLang('email_pozdrav'), "nazov" => $this->trLang('register_aktivacia'), "odkaz" => 'http://' . $this->nazov_stranky . $this->link("User:activateUser", $uloz_user_profiles['id'], $new_password_key)];
         $mail = new Message();
         $mail->setFrom($this->nazov_stranky . ' <' . $this->clen->users->email . '>')->addTo($values->email)->setSubject($this->trLang('register_aktivacia'))->setHtmlBody($templ->renderToString(__DIR__ . '/templates/User/email_activate-html.latte', $params));
         try {
             $sendmail = new SendmailMailer();
             $sendmail->send($mail);
             $this->users->find($uloz_users['id'])->update(['new_password_key' => $new_password_key]);
             $this->flashMessage($this->trLang('register_email_ok'), 'success');
         } catch (Exception $e) {
             $this->flashMessage($this->trLang('send_email_err') . $e->getMessage(), 'danger,n');
         }
         $this->redirect('Homepage:');
     } else {
         $this->flashMessage($this->trLang('register_save_err'), 'danger');
     }
     //Ulozenie sa nepodarilo
 }