/**
  *	@fn send
  *	@short Sends the contact email if validation passes.
  *	@details This method creates a contact email with the post data submitted by the user
  *	and delivers it to the website owner. Cookies are set for the user details if the <tt>remember_me</tt>
  *	flag has been set.
  *	If any of the validation steps fails, it performs a redirection to the action <tt>index</tt>.
  *	A redirection to the action <tt>thank_you</tt> is performed on success.
  */
 public function send()
 {
     if (!$this->request->is_post()) {
         $this->redirect_to(array('action' => 'index'));
     }
     if (!Email::is_valid($_POST['email'])) {
         $this->flash(l('Please enter a valid email address'), 'error');
         $this->redirect_to(array('action' => 'index'));
     }
     if (!Antispam::check_math()) {
         $this->flash(Antispam::random_comment(), 'error');
         $this->redirect_to(array('action' => 'index'));
     }
     // A static class method would be infinitely better...
     $contact_email = new ContactEmail($_POST);
     $contact_email->send();
     if (isset($_POST['remember_me'])) {
         $this->set_credentials($_POST['name'], $_POST['email'], $_POST['URL']);
     }
     $this->redirect_to(array('action' => 'thank_you'));
 }
 /**
  *	@fn post_comment
  *	@short Action method that receives a comment for a software product.
  */
 public function post_comment()
 {
     $conn = Db::get_connection();
     if (!$this->request->is_post()) {
         $this->redirect_to(array('action' => 'index'));
     }
     $software = new Software();
     if ($software->find_by_id($_POST['software_id']) === FALSE) {
         $this->flash(l('No such software'), 'error');
         $this->redirect_to(array('action' => 'index'));
     }
     if (!Email::is_valid($_POST['email'])) {
         $this->flash(l('Please enter a valid email address'), 'error');
         $this->redirect_to($software->comments_permalink());
     }
     if (!Antispam::check_math()) {
         $this->flash(Antispam::random_comment(), 'error');
         $this->redirect_to($software->comments_permalink());
     }
     // A static class method would be infinitely better...
     $comment = new SoftwareComment($_POST);
     $comment->created_at = date('Y-m-d H:i:s');
     $comment->save();
     // Send an email to notify this comment
     $email = new SoftwareCommentEmail(array('comment' => $comment, 'name' => $_POST['author'], 'email' => $_POST['email'], 'URL' => $_POST['URL']));
     $email->send();
     if (isset($_POST['remember_me'])) {
         $this->set_credentials($_POST['author'], $_POST['email'], $_POST['URL']);
     }
     // Expires the cache of Comments feed
     $this->expire_cached_page(array('controller' => 'feed', 'action' => 'software_comments', 'id' => $_POST['software_id']));
     $this->redirect_to_software_page(array('id' => $_POST['software_id'], 'subview' => 'comments', 'hash' => 'comment-' . $comment->id));
     Db::close_connection($conn);
 }
Beispiel #3
0
 /**
  *	@fn post_comment
  *	@short Action method to receive a comment for an article.
  */
 public function post_comment()
 {
     if (!$this->request->is_post()) {
         $this->redirect_to(array('action' => 'index'));
     }
     $post = new DiarioPost();
     if ($post->find_by_id($_POST['post_id']) === FALSE) {
         $this->flash(l('No such article'), 'error');
         $this->redirect_to(array('action' => 'index'));
     }
     if (!Email::is_valid($_POST['email'])) {
         $this->flash(l('Please enter a valid email address'), 'error');
         $this->redirect_to($post->permalink(FALSE));
     }
     if (!Antispam::check_math()) {
         $this->flash(Antispam::random_comment(), 'error');
         $this->redirect_to($post->permalink(FALSE));
     }
     // A static class method would be infinitely better...
     $comment = new DiarioComment($_POST);
     $comment->created_at = date("Y-m-d H:i:s");
     $comment->save();
     // Send an email to notify this comment
     $email = new DiarioCommentEmail(array('comment' => $comment, 'name' => $_POST['author'], 'email' => $_POST['email'], 'URL' => $_POST['URL']));
     $email->send();
     if (isset($_POST['remember_me'])) {
         $this->set_credentials($_POST['author'], $_POST['email'], $_POST['URL']);
     }
     // Expires the cache
     $this->expire_cached_page(array('action' => 'index'));
     $this->expire_cached_page(array('action' => 'read', 'id' => $_POST['post_id']));
     // Expires the cache of Comments feed
     $this->expire_cached_page(array('controller' => 'feed', 'action' => 'diario_comments', 'id' => $_POST['post_id']));
     $this->redirect_to(array('action' => 'read', 'id' => $_POST['post_id'], 'hash' => "comment-{$comment->id}"));
 }
Beispiel #4
0
 /**
  *	@fn request_password
  *	@short Action method to send a new password to a registered user.
  */
 function request_password()
 {
     if (!Antispam::check_math()) {
         $this->flash(Antispam::random_comment(), 'error');
         $this->redirect_to(array('action' => 'lost_password'));
     }
     $user_factory = new User();
     $users = $user_factory->find_all(array('where_clause' => "`email` = '{$_POST['email']}'", 'limit' => 1));
     if (count($users) > 0) {
         $user = $users[0];
         $request = new PasswordRequest();
         $request->user_id = $user->id;
         $request->created_at = date("Y-m-d H:i:s");
         $request->hash = md5($request->created_at . $request->user_id . 'Questa non la sai');
         $request->save();
         $this->redirect_to(array('action' => 'request_sent'));
     }
     $this->flash(l('No such user'), 'error');
     $this->redirect_to(array('action' => 'lost_password'));
 }