Пример #1
0
 public function register()
 {
     $this->view->title = 'Sign Up';
     if (isset($_POST["signup"])) {
         $form = new \SKS\LIB\Form();
         $form->post('first_name')->addRule('minlength', 2)->post('email')->addRule('email')->post("password")->addRule('minlength', 4);
         $errors = $form->validate();
         if (isset($errors)) {
             $this->view->errors = $errors;
             $this->view->render('user/register');
         } else {
             //save user
             $user = new \SKS\DB\Entity\User();
             $user->setFirstName($this->getPostValue("first_name"));
             $user->setEmail($this->getPostValue("email"));
             $user->setPassword(\SKS\LIB\Hash::create('sha256', $_POST['password'], HASH_PASSWORD_KEY));
             $user->persist(true);
             $login = new Login();
             $login->model = new \SKS\CONTROLLER\Login();
             $login->model->secureLogin($user);
             $this->view->render('user/dashboard');
         }
     } else {
         $this->view->render('user/register');
     }
 }
Пример #2
0
 public function changePassword($id)
 {
     \SKS\LIB\Session::checkAdminPermission();
     $newPassword = $this->getPostValue("new_password");
     $confirmPassword = $this->getPostValue("confirm_password");
     $db = new DB();
     $user = new \SKS\DB\Entity\User();
     $user = $db->findById($user, $id);
     $form = new \SKS\LIB\Form();
     $form->post('new_password')->addRule('minlength', 4);
     $errors = $form->validate();
     if (isset($errors)) {
         $this->view->errors = $errors;
     } else {
         if ($newPassword != $confirmPassword) {
             $this->view->errors = array("New password did not match.");
         } else {
             $this->view->message = "Password is changed successfully!";
         }
     }
     $password = \SKS\LIB\Hash::create('sha256', $_POST['new_password'], HASH_PASSWORD_KEY);
     $user->setPassword($password);
     $db = new DB();
     $user = $db->update($user, true);
     $this->view->user = $user;
     $this->view->render('user/include/password_change_form', false);
 }
Пример #3
0
 public function getUser()
 {
     $password = \SKS\LIB\Hash::create('sha256', $_POST['password'], HASH_PASSWORD_KEY);
     $user = new \SKS\DB\Entity\User();
     $user = $user->getRow(["email" => $_POST['email'], "password" => $password]);
     return $user;
 }
Пример #4
0
 public function getUser()
 {
     $db = new DB();
     $password = \SKS\LIB\Hash::create('sha256', \SKS\UTIL\Request::postValue('login_password'), HASH_PASSWORD_KEY);
     $user = new \SKS\DB\Entity\User();
     $user = $db->getRow($user, ["email" => \SKS\UTIL\Request::postValue('login_email'), "password" => $password]);
     return $user;
 }
Пример #5
0
 function getActivationCode($email)
 {
     $user = $this->getUserByEmail($email);
     if ($user == null) {
         return null;
     } else {
         $code = \SKS\LIB\Hash::create('sha256', rand(9999999, 99999999), HASH_PASSWORD_KEY);
         $user->setActivationCode($code);
         $db = new DB();
         $db->update($user, true);
         return $code;
     }
 }
Пример #6
0
 public function register()
 {
     $this->view->title = 'Sign Up';
     $db = new DB();
     if (isset($_POST["signup"])) {
         //validate the form
         $form = new \SKS\LIB\Form();
         $form->post('first_name')->addRule('minlength', 2)->post('email')->addRule('email')->post('last_name')->addRule('required')->post("password")->addRule('minlength', 4);
         $errors = $form->validate();
         $user = new \SKS\DB\Entity\User();
         $user->setFirstName($this->getPostValue("first_name"));
         $user->setLastName($this->getPostValue("last_name"));
         $user->setEmail($this->getPostValue("email"));
         $user->setRole("AUTHOR");
         $user->setGender($this->getPostValue("gender"));
         //Set the profile Image
         $profileImage = new \SKS\DB\Entity\Image();
         if (isset($_POST["profile_image_id"])) {
             $profileImage = $db->findById($profileImage, $_POST["profile_image_id"]);
         }
         $user->setProfileImage($profileImage);
         $this->view->user = $user;
         //If error occurs
         if (isset($errors)) {
             $this->view->errors = $errors;
             //save user
         } else {
             $_user = $db->find($user, array("email" => $user->getEmail()));
             if ($_user != null) {
                 $this->view->errors = array("Email already exits");
             } else {
                 //Save user
                 $user->setPassword(\SKS\LIB\Hash::create('sha256', $_POST['password'], HASH_PASSWORD_KEY));
                 $db->update($user, true);
                 $login = new Login();
                 $login->model = new \SKS\CONTROLLER\Login();
                 $this->view->user = new \SKS\DB\Entity\User();
                 $this->view->message = "You have registered successfully. You can login now :)";
             }
         }
     }
     $this->setTitle('Register');
     $this->view->render("login/register");
 }
Пример #7
0
 public function changePassword()
 {
     $code = $this->getPostValue("code");
     $newPassword = $this->getPostValue("new_password");
     $confirmPassword = $this->getPostValue("confirm_password");
     $loginModel = new \SKS\MODEL\LoginModel();
     $model = new \SKS\MODEL\UserModel();
     $user = $model->getUserByActivationCode($code);
     $form = new \SKS\LIB\Form();
     $form->post('new_password')->addRule('minlength', 4);
     $errors = $form->validate();
     if (!isset($user)) {
         $this->view->errors = array("Invalid activation code.");
     } else {
         if (isset($errors)) {
             $this->view->errors = $errors;
         } else {
             if ($newPassword != $confirmPassword) {
                 $this->view->errors = array("New password did not match.");
             } else {
                 $password = \SKS\LIB\Hash::create('sha256', $newPassword, HASH_PASSWORD_KEY);
                 $user->setPassword($password);
                 $user->setActivationCode(null);
                 $db = new DB();
                 $user = $db->update($user, true);
                 $this->view->is_password_reset = true;
                 $this->view->message = "Password is changed successfully! You can login now.";
             }
         }
     }
     $this->view->code = $code;
     $this->view->render('login/change_password');
 }