Browse files

reduced data stored in 'user_data' session, and removed a bunch of cr…

…uft from social_auth
  • Loading branch information...
1 parent b8278dd commit a95219e3d62924f734847bf3b89361cd7684ecdf @bnvk bnvk committed Apr 16, 2012
View
16 application/config/database.php.TEMPLATE
@@ -49,19 +49,25 @@ $db['dev']['cache_on'] = FALSE;
$db['dev']['cachedir'] = "";
$db['dev']['char_set'] = "utf8";
$db['dev']['dbcollat'] = "utf8_general_ci";
+$db['dev']['swap_pre'] = "";
+$db['dev']['autoinit'] = TRUE;
+$db['dev']['stricton'] = FALSE;
-$db['prod']['hostname'] = "productionhost";
-$db['prod']['username'] = "username";
-$db['prod']['password'] = "password";
-$db['prod']['database'] = "social-igniter";
+$db['prod']['hostname'] = "localhost";
+$db['prod']['username'] = "root";
+$db['prod']['password'] = "";
+$db['prod']['database'] = "database_name";
$db['prod']['dbdriver'] = "mysql";
$db['prod']['dbprefix'] = "";
$db['prod']['pconnect'] = TRUE;
-$db['prod']['db_debug'] = TRUE;
+$db['prod']['db_debug'] = FALSE;
$db['prod']['cache_on'] = FALSE;
$db['prod']['cachedir'] = "";
$db['prod']['char_set'] = "utf8";
$db['prod']['dbcollat'] = "utf8_general_ci";
+$db['prod']['swap_pre'] = "";
+$db['prod']['autoinit'] = TRUE;
+$db['prod']['stricton'] = FALSE;
/* End of file database.php */
/* Location: ./system/application/config/database.php */
View
2 application/config/social_igniter.php.TEMPLATE
@@ -25,7 +25,7 @@ $config['ignore_modules'] = array('text');
$config['site_modules'] = array('site','themes','design','widgets','services');
$config['user_settings'] = array('profile','details','password','contact','connections','advanced');
$config['user_meta_details'] = array('company','location','url','bio');
-$config['user_data'] = array('user_id','username','user_level_id','gravatar','name','image','language','time_zone','geo_enabled','privacy','consumer_key','consumer_secret','token','token_secret');
+$config['user_data'] = array('user_id','username','user_level_id','gravatar','name','image','language','time_zone','geo_enabled','privacy','consumer_key','consumer_secret');
$config['user_data_meta'] = array('location','url');
$config['user_phone_types'] = array('phone' => 'Phone','mobile_phone' => 'Mobile');
$config['user_mobile_verify'] = array('borogoves','gyre','jabberwocky','jubjub','frumious','bandersnatch','vorpal','tumtum','tulgey','burbled','snicker','snack','galumph','callooh','brillig','slithy','gimble');
View
6 application/controllers/site.php
@@ -92,9 +92,9 @@ function logout()
{
$this->data['page_title'] = "Logout";
- $logout = $this->social_auth->logout();
-
- redirect(base_url());
+ $this->social_auth->logout();
+
+ redirect();
}
function signup()
View
94 application/libraries/Social_auth.php
@@ -14,21 +14,13 @@ class Social_auth
{
protected $ci;
protected $status;
- protected $messages;
- protected $errors = array();
- protected $error_start_delimiter;
- protected $error_end_delimiter;
public $config_email = array();
public $_extra_where = array();
public $_extra_set = array();
function __construct()
{
$this->ci =& get_instance();
- $this->message_start_delimiter = config_item('message_start_delimiter');
- $this->message_end_delimiter = config_item('message_end_delimiter');
- $this->error_start_delimiter = config_item('error_start_delimiter');
- $this->error_end_delimiter = config_item('error_end_delimiter');
// Load Models
$this->ci->load->model('auth_model');
@@ -37,11 +29,10 @@ function __construct()
// Auto-login user if they're remembered
if (!$this->logged_in() && get_cookie('email') && get_cookie('remember_code'))
{
+
if ($user = $this->ci->auth_model->login_remembered_user())
{
$this->set_userdata($user);
- $this->set_userdata_meta($user->user_id);
- $this->set_userdata_connections($user->user_id);
}
}
@@ -182,12 +173,10 @@ function activate($id, $code=false)
{
if ($this->ci->auth_model->activate($id, $code))
{
- $this->set_message('activate_successful');
return TRUE;
}
else
{
- $this->set_error('activate_unsuccessful');
return FALSE;
}
}
@@ -196,12 +185,10 @@ function deactivate($id)
{
if ($this->ci->auth_model->deactivate($id))
{
- $this->set_message('deactivate_successful');
return TRUE;
}
else
{
- $this->set_error('deactivate_unsuccessful');
return FALSE;
}
}
@@ -253,7 +240,7 @@ function register($username, $password, $email, $additional_data, $group_name=fa
if ($user_id)
{
- $this->set_message('account_creation_successful');
+ //$this->set_message('account_creation_successful');
// Add Oauth Tokens
$this->oauth_register($email, $user_id, $additional_data['name']);
@@ -290,9 +277,7 @@ function social_register($username, $email, $additional_data)
$user_id = $this->ci->auth_model->social_register($username, $email, $additional_data);
if ($user_id)
- {
- $this->set_message('account_creation_successful');
-
+ {
// Add Oauth Tokens
$this->oauth_register($email, $user_id, $additional_data['name']);
@@ -375,12 +360,7 @@ function social_login($user_id, $connection)
function logout()
{
$this->ci->session->unset_userdata('email');
-
- foreach (config_item('user_data') as $item)
- {
- $this->ci->session->unset_userdata($item);
- }
-
+
if (get_cookie('email'))
{
delete_cookie('email');
@@ -393,7 +373,6 @@ function logout()
$this->ci->session->sess_destroy();
- $this->set_message('logout_successful');
return TRUE;
}
@@ -422,12 +401,10 @@ function update_user($user_id, $data)
{
if ($this->ci->auth_model->update_user($user_id, $data))
{
- $this->set_message('update_successful');
return TRUE;
}
else
{
- $this->set_error('update_unsuccessful');
return FALSE;
}
}
@@ -436,12 +413,10 @@ function delete_user($id)
{
if ($this->ci->auth_model->delete_user($id))
{
- $this->set_message('delete_successful');
return TRUE;
}
else
{
- $this->set_error('delete_unsuccessful');
return FALSE;
}
}
@@ -566,12 +541,7 @@ function set_userdata_connections($user_id)
{
$this->ci->session->set_userdata('user_connections', $this->get_connections_user($user_id));
}
-
- function set_lang($lang='en')
- {
- return $this->ci->auth_model->set_lang($lang);
- }
-
+
/* Crazy function that allows extra where field to be used for user fetching/unique checking etc.
* Basically this allows users to be unique based on one other thing than the identifier which is helpful
* for sites using multiple domains on a single database.
@@ -591,59 +561,7 @@ function extra_set()
$this->_extra_set = count($set) == 1 ? $set[0] : array($set[0] => $set[1]);
}
-
- function set_message_delimiters($start_delimiter, $end_delimiter)
- {
- $this->message_start_delimiter = $start_delimiter;
- $this->message_end_delimiter = $end_delimiter;
-
- return TRUE;
- }
-
- function set_error_delimiters($start_delimiter, $end_delimiter)
- {
- $this->error_start_delimiter = $start_delimiter;
- $this->error_end_delimiter = $end_delimiter;
-
- return TRUE;
- }
-
- function set_message($message)
- {
- $this->messages[] = $message;
-
- return $message;
- }
-
- function messages()
- {
- $_output = '';
- foreach ($this->messages as $message)
- {
- $_output .= $this->message_start_delimiter . $this->ci->lang->line($message) . $this->message_end_delimiter;
- }
-
- return $_output;
- }
-
- function set_error($error)
- {
- $this->errors[] = $error;
-
- return $error;
- }
-
- function errors()
- {
- $_output = '';
- foreach ($this->errors as $error)
- {
- $_output .= $this->error_start_delimiter . $this->ci->lang->line($error) . $this->error_end_delimiter;
- }
-
- return $_output;
- }
-
+
/* Connections Model */
function check_connection_auth($module, $auth_one, $auth_two)
View
141 application/models/auth_model.php
@@ -19,8 +19,6 @@ public function __construct()
{
parent::__construct();
- $this->columns = $this->config->item('columns');
- $this->columns_allowed = $this->config->item('columns_allowed');
$this->store_salt = $this->config->item('store_salt');
$this->salt_length = $this->config->item('salt_length');
}
@@ -406,8 +404,6 @@ function login($email, $password, $remember=FALSE, $session=FALSE)
if ($session)
{
$this->social_auth->set_userdata($user);
- $this->social_auth->set_userdata_meta($user->user_id);
- $this->social_auth->set_userdata_connections($user->user_id);
if ($remember && config_item('remember_users'))
{
@@ -441,15 +437,75 @@ function social_login($user_id, $connection)
{
$this->update_last_login($user->user_id);
$this->social_auth->set_userdata($user);
- $this->social_auth->set_userdata_meta($user->user_id);
- $this->social_auth->set_userdata_connections($user->user_id);
return $user;
}
return FALSE;
}
+ function update_last_login($user_id)
+ {
+ $this->db->update('users', array('last_login' => now()), array('user_id' => $user_id));
+
+ return $this->db->affected_rows() == 1;
+ }
+
+ function login_remembered_user()
+ {
+ if (!get_cookie('email') || !get_cookie('remember_code') || !$this->email_check(get_cookie('email')))
+ {
+ return FALSE;
+ }
+
+ // Get User
+ $this->db->select('*');
+ $this->db->where('email', get_cookie('email'));
+ $this->db->where('remember_code', get_cookie('remember_code'));
+ $this->db->limit(1);
+ $query = $this->db->get('users');
+
+ if ($query->num_rows() == 1)
+ {
+ $user = $query->row();
+
+ $this->update_last_login($user->user_id);
+
+ // WAS borken, seems fixed now
+ // Causesing compression header issue
+ if (config_item('user_extend_on_login'))
+ {
+ $this->remember_user($user);
+ }
+
+ return $user;
+ }
+
+ return FALSE;
+ }
+
+ function remember_user($user)
+ {
+ if (!$user->user_id) return FALSE;
+
+ $salt = sha1(md5(microtime()));
+
+ $this->db->update('users', array('remember_code' => $salt), array('user_id' => $user->user_id));
+
+ if ($this->db->affected_rows() == 1)
+ {
+ $email = array('name' => 'email', 'value' => $user->email, 'expire' => config_item('user_expire'));
+ $remember_code = array('name' => 'remember_code', 'value' => $salt, 'expire' => config_item('user_expire'));
+
+ set_cookie($email);
+ set_cookie($remember_code);
+
+ return TRUE;
+ }
+
+ return FALSE;
+ }
+
function get_users($parameter, $value)
{
if (in_array($parameter, array('user_level_id','active')))
@@ -618,78 +674,5 @@ function delete_user_meta($user_meta_id)
$this->db->delete('users_meta');
return TRUE;
}
-
- /* Remember Login */
- function update_last_login($user_id)
- {
- $this->db->update('users', array('last_login' => now()), array('user_id' => $user_id));
-
- return $this->db->affected_rows() == 1;
- }
-
- function set_lang($lang = 'en')
- {
- set_cookie(array(
- 'name' => 'lang_code',
- 'value' => $lang,
- 'expire' => $this->config->item('user_expire') + time()
- ));
-
- return TRUE;
- }
-
- function login_remembered_user()
- {
- if (!get_cookie('email') || !get_cookie('remember_code') || !$this->email_check(get_cookie('email')))
- {
- return FALSE;
- }
-
- // Get User
- $this->db->select('*');
- $this->db->where('email', get_cookie('email'));
- $this->db->where('remember_code', get_cookie('remember_code'));
- $this->db->limit(1);
- $query = $this->db->get('users');
-
- if ($query->num_rows() == 1)
- {
- $user = $query->row();
-
- $this->update_last_login($user->user_id);
-
- // WAS borken, seems fixed now
- // Causesing compression header issue
- if (config_item('user_extend_on_login'))
- {
- $this->remember_user($user);
- }
-
- return $user;
- }
-
- return FALSE;
- }
-
- function remember_user($user)
- {
- if (!$user->user_id) return FALSE;
-
- $salt = sha1(md5(microtime()));
- $this->db->update('users', array('remember_code' => $salt), array('user_id' => $user->user_id));
-
- if ($this->db->affected_rows() == 1)
- {
- $email = array('name' => 'email', 'value' => $user->email, 'expire' => config_item('user_expire'));
- $remember_code = array('name' => 'remember_code', 'value' => $salt, 'expire' => config_item('user_expire'));
-
- set_cookie($email);
- set_cookie($remember_code);
-
- return TRUE;
- }
-
- return FALSE;
- }
}

0 comments on commit a95219e

Please sign in to comment.