public function __construct() { $this->_display_html = false; if (VGet::loggedout()) { $this->_msg = ActionMessages::custom_good('You\'ve been logged out'); } try { $this->_session = new Session(); if (VPost::login(false)) { $this->_session->login(); } } catch (Exception $e) { $this->_msg = ActionMessages::custom_wrong($e->getMessage()); } }
/** * Log in the user if credentials are correct * * @access public */ public function login() { $to_read['table'] = 'user'; $to_read['columns'] = array('USER_ID', 'user_username', 'user_password'); $to_read['condition_columns'][':name'] = 'user_username'; $to_read['condition_types'][':name'] = 'AND'; $to_read['condition_select_types'][':name'] = '='; $to_read['condition_values'][':name'] = VPost::login(); $to_read['value_types'][':name'] = 'str'; $user = $this->_db->read($to_read); if ($user === false || empty($user)) { throw new Exception('Invalid Username'); } else { if ($user[0]['user_username'] == VPost::login() && $user[0]['user_password'] == Helper::make_password(VPost::login(), VPost::password())) { $_SESSION['username'] = $user[0]['user_username']; $_SESSION['user_id'] = $user[0]['USER_ID']; header('Location: index.php'); } else { throw new Exception('Invalid Password'); } } }