public function userprofile_interface() { parent::userprofile(); }
/** * Function get login with the Facebook * and save the session of the logged in user */ public function fbLogin() { //load the models $this->load->model(array('users', 'userprofile', 'userprofilequery', 'usersquery')); //get the Facebook appId and app secret from facebook.php which located in config directory for the creating the object for Facebook class $facebook = new Facebook(array('appId' => $this->config->item('appID'), 'secret' => $this->config->item('appSecret'), 'access_token' => $this->config->item('appID') . '|' . $this->config->item('appSecret'))); $user = $facebook->getUser(); // Get the facebook user id if ($user) { try { $userData = $facebook->api('/me'); //Get the facebook user profile data $auth = $this->encrypt->encode(strrev(random_string('unique', 16)) . '_' . strrev(now())); //Set the values of the user $checkUser = $this->userprofilequery->filterByemail($userData['email'])->findOne(); if (empty($checkUser)) { $data['fb_user_data'] = base64_encode(json_encode($userData)); //set the rules for the form validation $this->form_validation->set_rules('username', $this->lang->line('username'), 'trim|required|min_length[6]|xss_clean|callback_check_whitespaces|callback_check_user'); $this->form_validation->set_rules('password', $this->lang->line('password'), 'trim|required|min_length[6]|max_length[32]'); $this->form_validation->set_rules('confirm_password', $this->lang->line('confirm_password'), 'trim|required|matches[password]'); //Form validation if ($this->form_validation->run() == FALSE) { $this->stencil->title($this->lang->line('create_account')); $this->stencil->paint('user/fblogin'); } else { $post = $this->input->post(); $auth = $this->encrypt->encode(strrev(random_string('unique', 16)) . '_' . strrev(now())); //save the user detail $user = new users(); $user->setusername($post['username']); $user->setpassword($this->encrypt->encode($post['password'])); $user->setusertype('0'); $user->setstatus('0'); $user->setauthtoken($auth); $user->save(); //User profile data $userprofile = new userprofile(); $userprofile->setuserid($user->getid()); $userprofile->setfirstname($userData['first_name']); $userprofile->setlastname($userData['last_name']); $userprofile->setemail($userData['email']); $userprofile->setdob($userData['birthday']); $userprofile->setregisteron(now()); $userprofile->setlastlogin(now()); $userprofile->setlastip($_SERVER['SERVER_ADDR']); $userprofile->save(); //send the verification mail $this->sendVerificationMail($userData['email'], $user->getusername(), $auth); //redirect to thanks page $this->thanks($userData['email']); } } else { $profile = userprofilequery::create()->filterByemail($userData['email'])->findOne(); $users = usersquery::create()->filterByPrimaryKey($profile->getuserid())->findOne(); //Set the session data $data['username'] = $users->getusername(); $data['user_id'] = $profile->getuserid(); $data['auth'] = $users->getauthtoken(); $data['valid'] = $users->getstatus(); $data['first_name'] = $profile->getfirstname(); $data['last_name'] = $profile->getlastname(); $data['email'] = $profile->getemail(); $data['last_login'] = $profile->getlastlogin(); $data['ip'] = $_SERVER['SERVER_ADDR']; $data['is_logged_in'] = TRUE; //Set the session of the user $this->session->set_userdata($data); $this->session->set_flashdata('info', '<div class="alert alert-info top_buffer">Hi ' . $this->users->getUsername() . '! you have logged in successfully.</div>'); redirect('user/dashboard', 'refresh'); } } catch (FacebookApiException $e) { error_log($e); } } }
include_once $_SERVER['DATING_ROOT'] . '/lib/init-global.php'; abstract class userprofile extends \lib\actions { public static function get() { $vars = self::get_path_variables(); if (count($vars) == 1) { $user_profile = \lib\user_profile::get(reset($vars)); // data massaging for frontend $user_profile['birthday_year'] = $user_profile['birthday_month'] = $user_profile['birthday_day'] = ''; if (isset($user_profile['birthday'])) { $birthday_parsed = date_parse($user_profile['birthday']); $user_profile['birthday_year'] = $birthday_parsed['year'] ? $birthday_parsed['year'] : ''; $user_profile['birthday_month'] = $birthday_parsed['month'] ? $birthday_parsed['month'] : ''; $user_profile['birthday_day'] = $birthday_parsed['day'] ? $birthday_parsed['day'] : ''; unset($user_profile['birthday']); } return $user_profile; } } public static function put() { $data = self::get_data(); // data massaging from frontend $data['birthday'] = sprintf('%4d-%02d-%02d', $data['birthday_year'], $data['birthday_month'], $data['birthday_day']); unset($data['birthday_year'], $data['birthday_month'], $data['birthday_day']); \lib\user_profile::set($data); } } userprofile::run();