/** *This method parses user submitted login info * *@param array $data The user information submitted inthe form data *@return void */ public function postIndex() { //prepare user info to send to the database $data = array('email' => Input::get('email'), 'password' => Input::get('password')); //check if use exists $user = UsersModel::checkUser($data); //check if user was found if ($user) { //check if the passwords do not match if ($user['password'] != md5($data['password'])) { //reload the form with error message $data['error'] = 'Invalid Password. Try again!'; //load the form View::render('login/form', $data); } //password is correct - set user data in session Session::set('userInfo', $user); //check if this is admin user, //redirect to the appropriate user if ($user['user_type'] == 'admin') { Redirect::to($user['user_type']); } //else, redirect to the home controller Redirect::to('home'); } else { //compose the error information $data['error'] = 'User not found!'; //reload the form with the error message View::render('login/form', $data); } }
/** *This method parses user submitted login info * *@param array $data The user information submitted inthe form data *@return void */ public function postIndex() { //check if use exists $user = UsersModel::where('email = ?', Input::get('email'))->all(); //check if user was found if ($userData = $user->result_array()) { $userData = $userData[0]; //check if the passwords do not match if ($userData['password'] != md5(Input::get('password'))) { //reload the form with error message $data['error'] = 'Invalid Password. Try again!'; //load the form View::render('login/form', $data); } elseif ($userData['activated'] !== true) { //reload the form with error message $data['error'] = 'Account is nolonger active! Please contant Admin'; //load the form View::render('login/form', $data); } else { //password is correct - set user data in session Session::set('userInfo', $userData); $ip_address = $_SERVER['SERVER_ADDR']; $geoInfo = json_decode(@file_get_contents("http://ipinfo.io/{$ip_address}/json")); //call model to log user info $data = array('user_id' => $userData['id'], 'name' => $userData['first_name'] . ' ' . $userData['last_name'], 'email' => $userData['email'], 'ip_address' => $ip_address, 'country' => isset($geoInfo->country) ? $geoInfo->country : '', 'state' => isset($geoInfo->region) ? $geoInfo->region : '', 'city' => isset($geoInfo->city) ? $geoInfo->city : '', 'location' => isset($geoInfo->loc) ? $geoInfo->loc : '', 'host_name' => isset($geoInfo->hostname) ? $geoInfo->hostname : '', 'online' => true); $log = LogModel::save($data); UsersModel::where('id = ?', $userData['id'])->save(array('online' => true)); Session::set('log_id', $log->lastInsertId()); //check if this is admin user, //redirect to the appropriate user if ($userData['user_type'] == 'admin') { Redirect::to($userData['user_type']); } else { Redirect::to('home'); } } } else { //compose the error information $data['error'] = 'User not found!'; //reload the form with the error message View::render('login/form', $data); } }
/** * This methods upload a user's profile pic. * @param int $user_id The id of the user whose photo we upload * @return void */ public function saveProfilePic($user_id) { $upload = Upload::doUpload('profile-pic'); if ($upload->success) { $save_pic_path = UsersModel::where('id = ?', $user_id)->save(array('profile_pic' => substr($upload->upload_path_relative, 7))); $userInfo = UsersModel::where('id = ?', $user_id)->all(); $userInfo = $userInfo->result_array(); Session::set('userInfo', $userInfo[0]); if ($save_pic_path->updateSuccess()) { Redirect::to(array('admin')); } } }