Permalink
Browse files

Merge remote-tracking branch 'jaytaph/JI-162' into JI-162

  • Loading branch information...
2 parents 71db711 + e729627 commit 8ba033e154d54296a95db0e8f25875abc269c015 @lornajane lornajane committed May 5, 2012
Showing with 34 additions and 1 deletion.
  1. +27 −0 src/system/application/controllers/user.php
  2. +7 −1 src/system/application/models/user_model.php
@@ -296,6 +296,7 @@ function register()
'user' => 'required|trim|callback_usern_check|xss_clean',
'pass' => 'required|trim|matches[passc]|md5',
'passc' => 'required|trim',
+ 'twitter_username' => 'required|trim|callback_twitter_check',
'email' => 'required|trim|valid_email',
'cinput'=> 'required|callback_cinput_check'
);
@@ -468,6 +469,7 @@ function manage()
'email' => 'required',
'pass' => 'trim|matches[pass_conf]|md5',
'pass_conf' => 'trim',
+ 'twitter_username' => 'required|trim|callback_twitter_check['.$uid.']',
);
$this->validation->set_rules($rules);
$this->validation->set_fields($fields);
@@ -621,6 +623,31 @@ function usern_check($str)
return true;
}
+ /**
+ * Validates whether the twitter name already exists.
+ *
+ * @param string $str The twitter name to check
+ *
+ * @return bool
+ */
+ function twitter_check($str, $uid = -1)
+ {
+ // Strip away the @ if found
+ if ($str[1] == '@') {
+ $str = substr($str, 1);
+ }
+ $user = $this->user_model->getUserbyTwitter($str);
+ if (empty($user)) return true;
+
+ if ($uid == -1 || $user[0]->ID != $uid) {
+ $this->validation->_error_messages['twitter_check']
+ = "This twitter name is already used!";
+ return false;
+ }
+
+ return true;
+ }
+
/**
* Validates whether the given mail address is not already in use.
*
@@ -189,7 +189,13 @@ function getUser($in) {
* @return array User details
*/
function getUserByTwitter($screenName) {
- $q = $this->db->get_where('user', array('twitter_username' => (string)$screenName));
+ // Strip @ sign if needed
+ if ($screenName[0] == '@') {
+ $screenName = substr($screenName, 1);
+ }
+ $this->db->where('twitter_username', (string)$screenName);
+ $this->db->orwhere('twitter_username', (string)'@'.$screenName);
+ $q = $this->db->get('user');
$result = $q->result();
return $result ? $result : false;

0 comments on commit 8ba033e

Please sign in to comment.