/** * Create a new session. * * @param int $user_id * Optional user ID if the user is already known. * @param bool $remember * Optional remember flag to remember the user after they have logged out. * * @return session */ public static function create($user_id = 0, $remember = false) { $session_details = array(); $new_sess_key = static::getNewSessionId(); $new_token = Random::getInstance()->get(64, Random::HEX); if (empty($new_sess_key) || empty($new_token)) { Messenger::error('Session error.'); } $session_details['session_key'] = $new_sess_key; $session_details['last_ping'] = time(); $session_details['session_ip'] = LightningRequest::server('ip_int'); $session_details['user_id'] = $user_id; $session_details['state'] = 0 | ($remember ? static::STATE_REMEMBER : 0); $session_details['form_token'] = $new_token; $session_details['session_id'] = Database::getInstance()->insert('session', $session_details); $session = new static($session_details); $session->setCookie(); return $session; }
public function post() { $blog_id = Request::get('id', 'int') | Request::get('blog_id', 'int'); $action = Request::get('action'); // AUTHORIZE A BLOG COMMENT. switch ($action) { case 'post_comment_check': echo md5($_POST['email'] . $_POST['name'] . $_POST['comment']); exit; case 'post_comment': // FIRST CHECK FOR SPAM if ($_POST['check_val'] == md5($_POST['email'] . $_POST['name'] . $_POST['comment'])) { $values = array('blog_id' => $blog_id, 'ip_address' => Request::server('ip_int'), 'email_address' => Request::post('email', 'email'), 'name' => Request::post('name'), 'comment' => Request::post('comment'), 'time' => time()); Database::getInstance()->insert('blog_comment', $values); echo "success"; } else { echo "spam error"; } exit; case 'remove_blog_comment': $user = ClientUser::getInstance(); if ($user->isAdmin() && $_POST['blog_comment_id'] > 0) { Database::getInstance()->delete('blog_comment', array('blog_comment_id' => Request::post('blog_comment_id', 'int'))); echo "ok"; } else { echo "access denied"; } exit; case 'approve_blog_comment': $user = ClientUser::getInstance(); if ($user->isAdmin() && $_POST['blog_comment_id'] > 0) { Database::getInstance()->update('blog_comment', array('approved' => 1), array('blog_comment_id' => Request::post('blog_comment_id', 'int'))); echo "ok"; exit; } } }