/** * 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'); } } }
/** * Set data in user object and returns errors if data doesn't fit * * @access private * @return boolean */ private function check_post_data() { $results = array(); $errors = array(); array_push($results, $this->_profile->__set('_firstname', VPost::firstname())); array_push($results, $this->_profile->__set('_lastname', VPost::lastname())); array_push($results, $this->_profile->__set('_nickname', VPost::nickname())); array_push($results, $this->_profile->__set('_publicname', VPost::public_name())); if (VPost::role(false)) { //don't set when update own profile array_push($results, $this->_profile->__set('_role', VPost::role())); } array_push($results, $this->_profile->__set('_email', VPost::email())); array_push($results, $this->_profile->__set('_website', VPost::website())); array_push($results, $this->_profile->__set('_msn', VPost::msn())); array_push($results, $this->_profile->__set('_twitter', VPost::twitter())); array_push($results, $this->_profile->__set('_facebook', VPost::fb())); array_push($results, $this->_profile->__set('_google', VPost::google())); array_push($results, $this->_profile->__set('_avatar', VPost::avatar())); array_push($results, $this->_profile->__set('_bio', VPost::bio())); if (VPost::new_pwd(false) && VPost::new_pwd() == VPost::re_new_pwd()) { array_push($results, $this->_profile->__set('_password', Helper::make_password($this->_profile->_username, VPost::new_pwd()))); } elseif (VPost::new_pwd(false) && VPost::new_pwd() != VPost::re_new_pwd()) { array_push($results, 'Passwords does\'t match'); } foreach ($results as $result) { if ($result !== true) { //so it contains an error message array_push($errors, '<li>- ' . $result . '<li>'); } } if (!empty($errors)) { $error_msg = 'Check your informations:<br/><ul>' . implode('', $errors) . '</ul>'; $this->_action_msg = ActionMessages::custom_wrong($error_msg); return false; } else { return true; } }
/** * Create method to add a row in user table * * After creation success, the id of the row is inserted in id attribute * * @access public */ public function create() { $to_create['table'] = $this->_sql_table; $to_create['columns'] = array(':name' => 'user_username', ':nname' => 'user_nickname', ':fname' => 'user_firstname', ':lname' => 'user_lastname', ':pname' => 'user_publicname', ':pwd' => 'user_password', ':mail' => 'user_email', ':web' => 'user_website', ':msn' => 'user_msn', ':tweet' => 'user_twitter', ':fb' => 'user_facebook', ':gg' => 'user_google', ':av' => 'user_avatar', ':bio' => 'user_bio', ':role' => 'user_role'); $to_create['values'] = array(':name' => $this->_username, ':nname' => $this->_nickname, ':fname' => $this->_firstname, ':lname' => $this->_lastname, ':pname' => $this->_publicname, ':pwd' => Helper::make_password($this->_username, $this->_password), ':mail' => $this->_email, ':web' => $this->_website, ':msn' => $this->_msn, ':tweet' => $this->_twitter, ':fb' => $this->_facebook, ':gg' => $this->_google, ':av' => $this->_avatar, ':bio' => $this->_bio, ':role' => $this->_role); $to_create['types'] = array(':name' => 'str', ':nname' => 'str', ':fname' => 'str', ':lname' => 'str', ':pname' => 'str', ':pwd' => 'str', ':mail' => 'str', ':web' => 'str', ':msn' => 'str', ':tweet' => 'str', ':fb' => 'str', ':gg' => 'str', ':av' => 'int', ':bio' => 'str', ':role' => 'str'); $is_int = $this->_db->create($to_create); if (is_int($is_int)) { $this->_id = $is_int; $this->_result_action = true; } else { throw new Exception('There\'s a problem creating your ' . __CLASS__); } }