コード例 #1
0
ファイル: login.php プロジェクト: anqh/core
 /**
  * Log login attempt
  *
  * @static
  * @param  boolean            $success   Was login succesful
  * @param  string|Model_User  $user      User or username if no user found
  * @param  boolean            $password  Password given
  */
 public static function log($success, $user = null, $password = false)
 {
     $login = new Model_Login();
     try {
         $login->set_fields(array('password' => $password, 'username' => $user instanceof Model_User ? $user->username : $user, 'success' => (bool) $success, 'ip' => Request::$client_ip, 'hostname' => Request::host_name(), 'stamp' => time()));
         if ($user instanceof Model_User) {
             $login->user_id = $user->id;
             $login->username = $user->usernam;
         } else {
             if (is_string($user)) {
                 $login->username = $user;
             }
         }
         $login->save();
     } catch (Database_Exception $e) {
     }
 }
コード例 #2
0
ファイル: contact.php プロジェクト: anqh/anqh
 /**
  * Controller default action
  */
 public function action_index()
 {
     $this->view->title = __('Contact');
     $section = $this->section_contact();
     if (Visitor::$user) {
         $section->name = Visitor::$user->username;
         $section->email = Visitor::$user->email;
     }
     // Handle post
     $errors = array();
     if ($_POST && Security::csrf_valid()) {
         $name = trim(Arr::get($_POST, 'name'));
         $email = trim(Arr::get($_POST, 'email'));
         $subject = trim(Arr::get($_POST, 'subject'));
         $content = trim(Arr::get($_POST, 'content'));
         if (!Valid::email($email)) {
             $errors['email'] = __('Please check the email address');
         }
         if (!$content) {
             $errors['content'] = __('Please say something');
         }
         // Send feedback
         if (!$errors) {
             $topic = __('Feedback') . ': ' . $subject;
             $mail = $content . "\n\n" . Request::$client_ip . ' - ' . Request::host_name();
             if (Anqh_Email::send(Kohana::$config->load('site.email_contact'), array($email, $name), $topic, $mail, false, array($email, $name))) {
                 $this->view->add(View_Page::COLUMN_CENTER, new View_Alert(__('Thank you! We will try to return back to you as soon as possible.'), true, View_Alert::SUCCESS));
             } else {
                 $errors['content'] = __('Could not send feedback');
             }
         }
         if ($errors) {
             $section->errors = $errors;
             $section->name = $name;
             $section->email = $email;
             $section->subject = $subject;
             $section->content = $content;
         }
     }
     $this->view->add(View_Page::COLUMN_CENTER, $section);
 }
コード例 #3
0
ファイル: visitor.php プロジェクト: anqh/core
 /**
  * Complete the login for a user by incrementing the logins and setting
  * session data: user_id, username, roles
  *
  * @param   Model_User  $user
  * @return  boolean
  */
 protected function complete_login(Model_User $user)
 {
     $user->login_count++;
     $user->old_login = $user->last_login;
     $user->last_login = time();
     $user->ip = Request::$client_ip;
     $user->hostname = Request::host_name();
     try {
         $user->save();
     } catch (Validation_Exception $e) {
     }
     // Regenerate session_id and store user id
     $this->_session->regenerate();
     $this->_session->set($this->_config['session_key'], $user->id);
     return true;
 }
コード例 #4
0
ファイル: topic.php プロジェクト: anqh/forum
 /**
  * Edit forum topic
  *
  * @param  integer  $area_id
  * @param  integer  $topic_id
  *
  * @throws  Model_Exception           invalid area, invalid topic
  * @throws  InvalidArgumentException  missing area and topic
  */
 protected function _edit_topic($area_id = null, $topic_id = null)
 {
     $this->history = false;
     $this->view = new View_Page();
     if ($area_id && !$topic_id) {
         // Start new topic
         $mode = View_Forum_PostEdit::NEW_TOPIC;
         /** @var  Model_Forum_Private_Area|Model_Forum_Area  $area */
         $area = $this->private ? Model_Forum_Private_Area::factory($area_id) : Model_Forum_Area::factory($area_id);
         if (!$area->loaded()) {
             throw new Model_Exception($area, $area_id);
         }
         Permission::required($area, Model_Forum_Area::PERMISSION_POST, self::$user);
         $this->view->title = HTML::chars($area->name);
         if ($this->private) {
             $topic = new Model_Forum_Private_Topic();
             $post = new Model_Forum_Private_Post();
             $cancel = Route::url('forum_area', array('id' => 'private', 'action' => ''));
             $recipients = array();
         } else {
             $topic = new Model_Forum_Topic();
             $post = new Model_Forum_Post();
             $cancel = Route::model($area);
         }
     } else {
         if ($topic_id) {
             // Edit old topic
             $mode = View_Forum_PostEdit::EDIT_TOPIC;
             /** @var  Model_Forum_Private_Topic|Model_Forum_Topic  $topic */
             $topic = $this->private ? Model_Forum_Private_Topic::factory($topic_id) : Model_Forum_Topic::factory($topic_id);
             if (!$topic->loaded()) {
                 throw new Model_Exception($topic, $topic_id);
             }
             Permission::required($topic, Model_Forum_Topic::PERMISSION_UPDATE, self::$user);
             // Build recipients list
             if ($this->private) {
                 $recipients = $topic->find_recipient_names();
             }
             $this->view->title_html = Forum::topic($topic);
             $cancel = Route::model($topic);
             // Set actions
             if (Permission::has($topic, Model_Forum_Topic::PERMISSION_DELETE, self::$user)) {
                 $this->view->actions[] = array('link' => Route::model($topic, 'delete') . '?' . Security::csrf_query(), 'text' => '<i class="icon-trash icon-white"></i> ' . __('Delete topic'), 'class' => 'btn btn-danger topic-delete');
             }
         } else {
             throw new InvalidArgumentException('Topic and area missing');
         }
     }
     $errors = array();
     if ($_POST && Security::csrf_valid()) {
         // Get recipients
         if ($this->private) {
             $post_recipients = array();
             foreach (explode(',', Arr::get_once($_POST, 'recipients')) as $recipient) {
                 if ($user = Model_User::find_user_light(trim($recipient))) {
                     $post_recipients[$user['id']] = $user['username'];
                 }
             }
             // Make sure author is included
             $post_recipients[self::$user->id] = self::$user->username;
         }
         if (isset($post)) {
             // New topic
             $post->post = $_POST['post'];
             $post->forum_area_id = $area->id;
             $post->author_id = self::$user->id;
             $post->author_name = self::$user->username;
             $post->author_ip = Request::$client_ip;
             $post->author_host = Request::host_name();
             $post->created = time();
             try {
                 $post->is_valid();
             } catch (Validation_Exception $e) {
                 $errors += $e->array->errors('validate');
             }
             $topic->author_id = self::$user->id;
             $topic->author_name = self::$user->username;
             $topic->name = $_POST['name'];
             $topic->forum_area_id = $area->id;
             $topic->created = time();
             try {
                 $topic->is_valid();
             } catch (Validation_Exception $e) {
                 $errors += $e->array->errors('validate');
             }
             // If no errors found, save models
             if (empty($errors)) {
                 $topic->save();
                 // Recipients
                 if ($this->private) {
                     $topic->set_recipients($post_recipients);
                 }
                 // Post
                 $post->forum_topic_id = $topic->id;
                 $post->save();
                 // Topic
                 $topic->first_post_id = $topic->last_post_id = $post->id;
                 $topic->last_poster = self::$user->username;
                 $topic->last_posted = time();
                 $topic->post_count = 1;
                 $topic->save();
                 // Area, only public forums
                 if (!$this->private) {
                     $area->last_topic_id = $topic->id;
                     $area->post_count++;
                     $area->topic_count++;
                     $area->save();
                 }
                 // User
                 self::$user->post_count++;
                 self::$user->save();
                 // News feed
                 if (!$this->private) {
                     NewsfeedItem_Forum::topic(self::$user, $topic);
                 }
                 $this->request->redirect(Route::model($topic));
             }
             isset($post_recipients) and $recipients = $post_recipients;
         } else {
             // Old topic
             $topic->set_fields(Arr::intersect($_POST, array('name', 'status', 'sticky')));
             try {
                 $topic->save();
                 // Recipients
                 if ($this->private) {
                     $topic->set_recipients($post_recipients);
                 }
                 $this->request->redirect(Route::model($topic));
             } catch (Validation_Exception $e) {
                 $errors = $e->array->errors('validate');
             }
         }
     }
     $form['errors'] = $errors;
     $section = $this->section_post_edit($mode, isset($post) ? $post : null);
     $section->forum_topic = $topic;
     $section->errors = $errors;
     $section->cancel = $cancel;
     $section->recipients = isset($recipients) ? implode(', ', $recipients) : null;
     $this->view->add(View_Page::COLUMN_MAIN, $section);
 }
コード例 #5
0
ファイル: user.php プロジェクト: anqh/anqh
 /**
  * Complete login.
  *
  * @param   boolean  $autologin
  * @return  boolean  User updated
  */
 public function complete_login($autologin = false)
 {
     if (!$autologin) {
         $this->login_count++;
     }
     $this->last_login = Date::format(Date::TIME_SQL);
     $this->ip = Request::$client_ip;
     $this->hostname = Request::host_name();
     // Load session settings
     $session = Session::instance();
     $session->set('theme', $this->setting('ui.theme'));
     try {
         $this->save();
     } catch (Validation_Exception $e) {
         return false;
     }
     return true;
 }
コード例 #6
0
ファイル: visitor.php プロジェクト: netbiel/core
 /**
  * Complete the login for a user by incrementing the logins and setting
  * session data: user_id, username, roles
  *
  * @param   Model_User  $user
  * @return  boolean
  */
 protected function complete_login(Model_User $user)
 {
     $user->logins += 1;
     $user->old_login = $user->last_login;
     $user->last_login = time();
     $user->ip = Request::$client_ip;
     $user->hostname = Request::host_name();
     $user->save();
     // Regenerate session_id and store user
     $this->_session->regenerate();
     $this->_session->set($this->_config['session_key'], $user);
     return true;
 }
コード例 #7
0
ファイル: topic.php プロジェクト: anqh/anqh
 /**
  * Edit forum post
  *
  * @param  integer  $topic_id  When replying to a topic
  * @param  integer  $post_id   When editing a post
  * @param  integer  $quote_id  When quoting a post
  *
  * @throws  Model_Exception  missing topic, missing post
  */
 protected function _edit_post($topic_id, $post_id = null, $quote_id = null)
 {
     $this->history = false;
     // Topic is always loaded, avoid haxing attempts to edit posts from wrong topics
     $topic = $this->private ? Model_Forum_Private_Topic::factory($topic_id) : Model_Forum_Topic::factory($topic_id);
     if (!$topic->loaded()) {
         throw new Model_Exception($topic, $topic_id);
     }
     Permission::required($topic, Model_Forum_Topic::PERMISSION_POST);
     if ($post_id) {
         // Editing a post
         $post = $this->private ? Model_Forum_Private_Post::factory($post_id) : Model_Forum_Post::factory($post_id);
         if (!$post->loaded() || $post->forum_topic_id != $topic->id) {
             throw new Model_Exception($post, $post_id);
         }
         Permission::required($post, Model_Forum_Post::PERMISSION_UPDATE);
     } else {
         // New reply
         $post = $this->private ? Model_Forum_Private_Post::factory() : Model_Forum_Post::factory();
     }
     // Quoting a post
     if ($quote_id) {
         $quote = $this->private ? Model_Forum_Private_Post::factory() : Model_Forum_Post::factory($quote_id);
         if (!$quote->loaded() || $quote->forum_topic_id != $topic->id) {
             throw new Model_Exception($quote, $quote_id);
         }
         Permission::required($quote, Model_Forum_Post::PERMISSION_READ);
         if (!$post->loaded()) {
             $post->post = '[quote author="' . $quote->author_name . '" post="' . $quote->id . '"]' . $quote->post . "[/quote]\n\n";
         }
         $post->parent_id = $quote_id;
     }
     // Handle post
     $errors = array();
     if ($_POST && Security::csrf_valid()) {
         $post->post = Arr::get($_POST, 'post');
         $post->author_ip = Request::$client_ip;
         $post->author_host = Request::host_name();
         if (!$post->loaded()) {
             // New post
             $post->forum_topic_id = $topic->id;
             $post->forum_area_id = $topic->forum_area_id;
             $post->author_id = Visitor::$user->id;
             $post->author_name = Visitor::$user->username;
             $post->created = time();
             $increase = true;
         } else {
             // Old post
             $post->modify_count++;
             $post->modified = time();
             $increase = false;
         }
         // Preview
         if (isset($_POST['preview'])) {
             if ($this->ajax) {
                 $this->response->body($this->section_post($topic, $post));
             }
             return;
         }
         // Save
         try {
             $post->save();
             if ($increase) {
                 // Quote, only for public topics
                 if (!$this->private && $quote_id && $quote->author_id) {
                     $quoted = $quote->author_id;
                     $quote = new Model_Forum_Quote();
                     $quote->user_id = $quoted;
                     $quote->author_id = Visitor::$user->id;
                     $quote->forum_topic_id = $topic->id;
                     $quote->forum_post_id = $post->id;
                     $quote->created = time();
                     $quote->save();
                 }
                 // Notify recipients
                 if ($this->private) {
                     $topic->notify_recipients(Visitor::$user);
                 }
                 // Topic
                 $topic->post_count++;
                 $topic->last_post_id = $post->id;
                 $topic->last_poster = $post->author_name;
                 // If current topic is set to sink, don't update last posted date
                 if ($topic->status != Model_Forum_Topic::STATUS_SINK) {
                     $topic->last_posted = $post->created;
                 }
                 $topic->save();
                 // Area, only for public topics
                 if (!$this->private) {
                     $area = $topic->area();
                     $area->post_count++;
                     $area->last_topic_id = $topic->id;
                     $area->save();
                 }
                 // User
                 Visitor::$user->post_count++;
                 Visitor::$user->save();
                 // News feed
                 if (!$this->private) {
                     NewsfeedItem_Forum::reply(Visitor::$user, $post);
                 }
             }
             if ($this->ajax) {
                 $post_route = Route::url($this->private ? 'forum_private_post' : 'forum_post', array('topic_id' => Route::model_id($topic), 'id' => $post->id));
                 $post_response = Request::factory($post_route)->execute();
                 $this->response->body($post_response->body());
                 return;
             }
             $this->request->redirect(Route::model($topic, '?page=last#last'));
         } catch (Validation_Exception $e) {
             $errors = $e->array->errors('validate');
         }
     }
     // Common attributes
     if ($quote_id) {
         $mode = View_Forum_PostEdit::QUOTE;
     } else {
         if ($post_id) {
             $mode = View_Forum_PostEdit::EDIT_POST;
         } else {
             $mode = View_Forum_PostEdit::REPLY;
         }
     }
     $section = $this->section_post_edit($mode, $post);
     $section->forum_topic = $topic;
     $section->errors = $errors;
     $section->cancel = $this->ajax ? Route::url($this->private ? 'forum_private_post' : 'forum_post', array('topic_id' => Route::model_id($topic), 'id' => $quote_id ? $quote_id : $post->id)) : Request::back(Route::model($topic), true);
     if ($this->ajax) {
         $this->response->body($mode == View_Forum_PostEdit::EDIT_POST ? $section->content() : $section);
         return;
     }
     // Build page
     $this->view = new View_Page();
     $this->view->title = $topic->name;
     $this->view->title_html = Forum::topic($topic);
     $this->view->add(View_Page::COLUMN_CENTER, $section);
 }
コード例 #8
0
ファイル: topic.php プロジェクト: anqh/anqh
 /**
  * Add a post to topic.
  *
  * @param   string            $content
  * @param   Model_User|array  $author
  * @return  Model_Forum_Post|Model_Forum_Private_Post
  */
 public function create_post($content, $author)
 {
     $this->unsaved_post = $post = $this instanceof Model_Forum_Private_Topic ? new Model_Forum_Private_Post() : new Model_Forum_Post();
     $post->post = $content;
     if (is_array($author)) {
         $post->author_id = $author['id'];
         $post->author_name = $author['username'];
     } else {
         if (is_object($author)) {
             $post->author_id = $author->id;
             $post->author_name = $author->username;
         }
     }
     $post->author_ip = Request::$client_ip;
     $post->author_host = Request::host_name();
     $post->created = time();
     $post->forum_topic_id = $this->id;
     $post->forum_area_id = $this->forum_area_id;
     return $post;
 }