/**
  * Processing of change user password form
  *
  * @param \Nette\Application\UI\Form $form
  *
  * @Privilege("default")
  */
 public function changePasswordSucceded(\Nette\Application\UI\Form $form)
 {
     $values = $form->getValues(TRUE);
     $row = $this->users->get($this->user->id);
     if (!\Nette\Security\Passwords::verify($values['oldpassword'], $row->password)) {
         $form->addError('Nesprávné heslo.');
     } else {
         $this->users->updatePassword($row->id, $values['password']);
         $this->flashMessage('Heslo bylo změněno');
     }
     $this->redirect('this');
 }
 public function comment($section, $newsId)
 {
     $comment = Input::get('comment');
     $user = User::get();
     Comment::Insert(array('newsId' => $newsId, 'userId' => $user->id, 'comment' => $comment));
     Response::redirect('/' . $section . '/' . $newsId);
 }
 public function seedImage(User $user)
 {
     $file = $this->faker->imageUrl(600, 400, 'people');
     Debugger::debug($file, 'image url');
     $image = new Image($file);
     Debugger::debug($image, 'image class');
     $filename = md5($file . $user->get('id')) . '.jpg';
     $imageDir = 'assets/images/profile-pics/original/';
     $imageDir .= substr($filename, 0, 1) . '/';
     $imageDir .= substr($filename, 1, 1) . '/';
     $imageDir .= substr($filename, 2, 1) . '/';
     if (!is_dir(PUBLIC_ROOT . $imageDir)) {
         mkdir(PUBLIC_ROOT . $imageDir, 0777, true);
     }
     $saveName = PUBLIC_ROOT . $imageDir . $filename;
     Debugger::debug($saveName, 'save name');
     $image->save($imageDir . $filename);
     $thumbnail = $this->seedThumbnail($image, $imageDir, $user);
     // update the database
     $userImage = new UserImage();
     $userImage->set('user_id', $user->get('id'));
     $userImage->set('image_url', '/' . $imageDir . $filename);
     $userImage->set('thumbnail', '/' . $thumbnail);
     $userImage->set('main_image', 1);
     $userImage->save();
 }
Exemple #4
0
 public function seedEmail(User $user)
 {
     Debugger::debug('Seeding email');
     $userEmail = new Email();
     $userEmail->set('user_id', $user->get('id'));
     $userEmail->set('email', $this->faker->freeEmail);
     $userEmail->set('primary', 1);
     $userEmail->save();
 }
Exemple #5
0
 public function signup($slug = null)
 {
     $this->data['title'] = 'Join Us';
     // $module_slug = $slug[0];
     $role = new \models\userrole();
     $user = new User();
     $this->data['user_role'] = $role->all();
     //PULL DATA FROM SITESETTINGS
     $document = new \Helpers\Document();
     $details = $document->siteSettings();
     //GET NEW USER STATUS ID
     $this->model->table('user_status');
     $user_status = $this->model->get_row(array("title" => "inactive"));
     $this->data['reg_form'] = $details['reg_form'];
     if (isset($_POST) && !empty($_POST)) {
         if ($_POST['password'] == $_POST['password2']) {
             $encrypted = md5($_POST['password']);
             $row_count = $user->get(array("email" => $_POST['email']));
             if (count($row_count) >= 1) {
                 $this->data['error'] = 'Email exists in our records, please use a different email';
             } else {
                 $insert_array = array('firstname' => $_POST['fname'], 'lastname' => $_POST['lname'], 'email' => $_POST['email'], 'password' => $encrypted, 'role' => $_POST['role'], 'status' => $user_status->id);
                 $hash = $user->register($insert_array);
                 if ($hash != '') {
                     //SEND ACCOUNT DETAILS TO USER
                     $fullname = $_POST['fname'] . ' ' . $_POST['lname'];
                     $subject = 'New Account';
                     $mail = new \helpers\phpmailer\mail();
                     $mail->template('welcome');
                     $mail->generalEmail($_POST['email'], $subject, $fullname, $hash);
                     $this->data['success'] = 'A link has been sent to your email, please click to activate your account';
                 } else {
                     $this->data['error'] = 'Operation Fails, Please contact admin';
                 }
             }
         } else {
             $this->data['error'] = 'Password does not match!';
         }
     }
     View::rendertemplate('header', $this->data);
     View::render('account/signup', $this->data);
     View::rendertemplate('footer', $this->data);
 }
Exemple #6
0
 public function password()
 {
     $this->data['title'] = 'Change Password';
     $userModel = new User();
     $user_id = Session::get('user')->user_id;
     $user_details = $userModel->get(array('user_id' => $user_id, 'user_password' => md5($_POST['old_password'])));
     if (isset($_POST['password1']) && !empty($_POST['password1'])) {
         if (count($user_details) > 0) {
             if ($_POST['password1'] == $_POST['password2']) {
                 //update user db
                 $update_array = array('user_password' => md5($_POST['password1']));
                 $update_array = Gump::xss_clean($update_array);
                 $update_array = Gump::sanitize($update_array);
                 $update_id = $user_model->updateId($update_array, $user_id);
                 if ($update_id > 0) {
                     Session::set('success', 'Password Changed');
                 } else {
                     Session::set('error', 'Operation Fails!');
                 }
             } else {
                 Session::set('error', 'Incorrect match, password change fails!');
             }
         } else {
             Session::set('error', 'Incorrect match, password change fails!');
         }
     }
     View::rendertemplate('header', $this->data);
     View::render('workspace/workspace.password', $this->data);
     View::rendertemplate('footer', $this->data);
 }
 public function base($template, $data = array())
 {
     return View::build($template, array_merge($data, array('user' => User::get())));
 }
Exemple #8
0
 public static function createSecret(User $user)
 {
     $keystring = $user->get('username') . $user->get('created_ts') . self::$salt;
     return self::encode($keystring);
 }