Exemplo n.º 1
0
Arquivo: Post.php Projeto: sks40gb/jnv
 function addComment()
 {
     \SKS\LIB\Session::checkUserPermission();
     $db = new DB();
     $post = new \SKS\DB\Entity\Post();
     $post = $db->findById($post, $_POST["post_id"]);
     if (isset($_POST["action"])) {
         $form = new \SKS\LIB\Form();
         $form->post("comment")->addRule("required")->addRule("minlength", 5);
         $errors = $form->validate();
         //set the comment
         $comment = new \SKS\DB\Entity\Comment();
         $comment->setComment($_POST["comment"]);
         $user = $db->findById(Session::getLoggedInUser(), Session::getLoggedInUser()->getId());
         $comment->setCommentedBy($user);
         if (isset($errors)) {
             $this->view->comment = $comment;
             $this->view->errors = $errors;
         } else {
             //Set the post
             $post->addComment($comment);
             $comment->setPost($post);
             $post = $db->update($post, true);
             $comment = $db->update($comment, true);
             $this->view->message = 'Commented Successfully';
         }
     }
     $this->view->post = $post;
     $this->view->title = 'Post';
     $this->view->render('post/addComment', false);
 }
Exemplo n.º 2
0
 function contactMe()
 {
     $form = new \SKS\LIB\Form();
     $form->post('name')->addRule('minlength', 2)->post('email')->addRule('email')->post("message")->addRule('minlength', 20);
     $errors = $form->validate();
     $email = new \SKS\DB\Entity\Email();
     $email->setName($this->getPostValue("name"));
     $email->setFrom($this->getPostValue("email"));
     $email->setContent($this->getPostValue("message"));
     $this->view->email = $email;
     if (isset($errors)) {
         $this->view->errors = $errors;
         $this->view->render('index/contactMe', false);
     } else {
         $email->persist(true);
         $sent = \EmailUtil::contact_us($email->getContent());
         if ($sent) {
             $this->view->message = "Thank you for contacting me, will get back to you soon..";
             $this->view->render('index/contactMe', false);
         } else {
             $this->view->error = "Error occured while sending email ..";
             $this->view->render('index/contactMe', false);
         }
     }
 }
Exemplo n.º 3
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.º 4
0
 function savePost()
 {
     Session::checkAuthorPermission();
     //execute this line for save and update else create form.
     $db = new DB();
     if (isset($_POST["action"])) {
         //Form validation
         $form = new \SKS\LIB\Form();
         $form->post("title")->addRule("required")->post("post")->addRule("required")->post("post_type")->addRule("required")->post("category_id")->addRule("required")->post("banner_image_id")->addRule("required");
         $errors = $form->validate();
         // Get Post
         $post = new \SKS\DB\Entity\Post();
         if (isset($_POST["post_id"]) && \Text::not_empty($_POST["post_id"])) {
             $post = $db->findById($post, $_POST["post_id"]);
         }
         //Get Category
         $postCategory = new PostCategory();
         $postCategory = $db->findById($postCategory, $_POST["category_id"]);
         //Get Image
         $image = new \SKS\DB\Entity\Image();
         $image = $db->findById($image, $_POST["banner_image_id"]);
         //Set the field value
         $post->setTitle($_POST["title"]);
         $post->setPost($_POST["post"]);
         $user = $db->findById(Session::getLoggedInUser(), Session::getLoggedInUser()->getId());
         $post->setUser($user);
         $post->setPostCategory($postCategory);
         $post->setBannerImage($image);
         // Set view variable
         $this->view->title = 'Post';
         $this->view->post = $post;
         $this->view->postType = $_POST["post_type"];
         //If no error encoutered
         if (isset($errors)) {
             $this->view->errors = $errors;
         } else {
             $post = $db->update($post, true);
             $post->setPostCategory($postCategory);
             $this->view->message = "Posted saved successfully";
         }
     }
     $this->view->post = $post;
     $this->view->categories = $this->getCategories();
     $this->view->render('publish/post');
 }
Exemplo n.º 5
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");
 }
Exemplo n.º 6
0
Arquivo: Role.php Projeto: sks40gb/sks
 function save()
 {
     if (isset($_POST["action"])) {
         $form = new \SKS\LIB\Form();
         $form->post("name")->addRule("minlength", 2);
         $errors = $form->validate();
         $role = new \SKS\DB\Entity\Role();
         $role->setName($_POST["name"]);
         $exists = $role->exist(array("name" => $role->getName()));
         if ($exists) {
             $errors = array("Role already exits");
         }
         if (isset($errors)) {
             $this->view->errors = $errors;
         } else {
             $role->persist(true);
             $this->view->message = 'Saved Successfully';
         }
         $this->view->role = $role;
     }
     $this->view->title = 'Role';
     $this->view->render('role/role');
 }
Exemplo n.º 7
0
 public function updateUser($id = null)
 {
     \SKS\LIB\Session::checkAdminPermission();
     $db = new DB();
     $this->view->title = 'Update Profile';
     //validate the form
     $form = new \SKS\LIB\Form();
     $form->post('first_name')->addRule('minlength', 2)->post('email')->addRule('email')->post('last_name')->addRule('required');
     $errors = $form->validate();
     $user = new \SKS\DB\Entity\User();
     if ($id != null) {
         $user = $db->findById($user, $id);
     }
     $current_email = $user->getEmail();
     $user->setFirstName($this->getPostValue("first_name"));
     $user->setLastName($this->getPostValue("last_name"));
     $user->setEmail($this->getPostValue("email"));
     //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);
     //set the User
     $this->view->user = $user;
     //If error occurs
     if (isset($errors)) {
         $this->view->errors = $errors;
         //save user
     } else {
         $is_same = $user->getEmail() == $current_email;
         $exists = $is_same ? false : $user->exist(array("email" => $user->getEmail()));
         if ($exists) {
             $this->view->errors = array("Email already exits");
         } else {
             // Save the user
             $user = $db->update($user, true);
             $this->view->user = $user;
             $this->view->message = "Profile is updated successfully.";
         }
     }
     $this->view->render('user/include/user_form', false);
 }
Exemplo n.º 8
0
Arquivo: User.php Projeto: sks40gb/jnv
 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');
 }
Exemplo n.º 9
0
Arquivo: Post.php Projeto: sks40gb/sks
 function addCategory()
 {
     \SKS\LIB\Session::checkAdminPermission();
     if (isset($_POST["action"])) {
         $form = new \SKS\LIB\Form();
         $form->post("name")->addRule("minlength", 2)->post("post_type")->addRule("required");
         $errors = $form->validate();
         $category = new \SKS\DB\Entity\PostCategory();
         $category->setName($_POST["name"]);
         $category->setType($_POST["post_type"]);
         $exists = $category->exist(array("name" => $category->getName()));
         if ($exists) {
             $errors = array("Category already exits");
         }
         if (isset($errors)) {
             $this->view->errors = $errors;
         } else {
             $category->persist(true);
             $this->view->message = 'Saved Successfully';
         }
         $this->view->category = $category;
     }
     $this->view->title = 'Post';
     $this->view->render('post/addCategory');
 }