Exemplo n.º 1
0
Arquivo: User.php Projeto: sks40gb/sks
 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');
     }
 }
Exemplo n.º 2
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");
 }