still working at OpenID
authorCalin Burloiu <calin.burloiu@gmail.com>
Fri, 14 Oct 2011 14:00:11 +0000 (17:00 +0300)
committerCalin Burloiu <calin.burloiu@gmail.com>
Fri, 14 Oct 2011 14:00:11 +0000 (17:00 +0300)
application/config/openid.php
application/controllers/user.php
application/libraries/Openid.php
application/models/users_model.php
data/user_pictures/admin-.jpg [new file with mode: 0644]
data/user_pictures/admin-.jpg-thumb.jpg [new file with mode: 0644]

index 2dc2630..176a648 100644 (file)
@@ -2,7 +2,7 @@
 
 $config['openid_storepath'] = './tmp';
 $config['openid_required'] = array('nickname');
-$config['openid_optional'] = array('fullname', 'email');
+$config['openid_optional'] = array('fullname', 'email', 'dob', 'country');
 $config['openid_pape_policies'] = array();
 
 // OBSOLETE
index 5a9b779..2e4b4ee 100644 (file)
@@ -157,6 +157,8 @@ class User extends CI_Controller {
 
                        //echo 'nickname('. $sreg_resp->get('nickname'). ')';
                        echo var_dump($obj->data);
+                       echo '<br />';
+                       echo var_dump($sreg);
 //                     foreach ($sreg as $key => $value)
 //                     {
 //                             $data['success'] .= $this->_set_message('openid_content', array($key, $value), array('%s', '%t'));
index 0ac29e4..7fd12fd 100644 (file)
@@ -122,9 +122,12 @@ class Openid {
                // Create attribute request object
                // See http://code.google.com/apis/accounts/docs/OpenID.html#Parameters for parameters
                // Usage: make($type_uri, $count=1, $required=false, $alias=null)
-               $attribute[] = Auth_OpenID_AX_AttrInfo::make('http://axschema.org/contact/email',2,1, 'email');
-               $attribute[] = Auth_OpenID_AX_AttrInfo::make('http://axschema.org/namePerson/first',1,1, 'firstname');
-               $attribute[] = Auth_OpenID_AX_AttrInfo::make('http://axschema.org/namePerson/last',1,1, 'lastname');
+               $attribute[] = Auth_OpenID_AX_AttrInfo::make(
+                               'http://axschema.org/contact/email', 1, TRUE);
+               $attribute[] = Auth_OpenID_AX_AttrInfo::make(
+                               'http://axschema.org/namePerson/first', 1, TRUE);
+               $attribute[] = Auth_OpenID_AX_AttrInfo::make(
+                               'http://axschema.org/namePerson/last', 1, TRUE);
 
                // Create AX fetch request
                $ax = new Auth_OpenID_AX_FetchRequest;
index 76f378d..02a520f 100644 (file)
@@ -78,6 +78,10 @@ class Users_model extends CI_Model {
                                && ! $this->ldap_login($username, $password))
                        return FALSE; 
                
+               if (empty($user['email']) || empty($user['first_name'])
+                               || empty($user['last_name']))
+                       $user['import'] = TRUE;
+               
                // Update last login time.
                $this->db->query("UPDATE `users`
                        SET last_login = UTC_TIMESTAMP()
@@ -201,6 +205,9 @@ class Users_model extends CI_Model {
                        $data['password'] = sha1($data['password']);
                // TODO picture data: save, convert, make it thumbnail
                
+               if (empty($data['birth_date']))
+                       $data['birth_date'] = NULL;
+               
                $cols = '';
                $vals = '';
                foreach ($data as $col=> $val)
@@ -229,13 +236,16 @@ class Users_model extends CI_Model {
                
                // If registered with internal authentication it needs to activate
                // the account.
-               $activation_code = Users_model::gen_activation_code($data['username']);
-               $user_id = $this->get_user_id($data['username']);
-               $query = $this->db->query("INSERT INTO `users_unactivated`
-                       (user_id, activation_code)
-                       VALUES ($user_id, '$activation_code')");
-               $this->send_activation_email($user_id, $data['email'],
-                       $activation_code, $data['username']);
+               if ($data['auth_src'] == 'internal')
+               {
+                       $activation_code = Users_model::gen_activation_code($data['username']);
+                       $user_id = $this->get_user_id($data['username']);
+                       $query = $this->db->query("INSERT INTO `users_unactivated`
+                               (user_id, activation_code)
+                               VALUES ($user_id, '$activation_code')");
+                       $this->send_activation_email($user_id, $data['email'],
+                               $activation_code, $data['username']);
+               }
                
                // TODO exception on failure
                return $query;
@@ -395,15 +405,22 @@ class Users_model extends CI_Model {
                        $data['password'] = sha1($data['password']);
                // TODO picture data: save, convert, make it thumbnail
                
+               if (empty($data['birth_date']))
+                       $data['birth_date'] = NULL;
+               
                $set = '';
                foreach ($data as $col => $val)
                {
+                       if ($val === NULL)
+                       {
+                               $set .= "$col = NULL, ";
+                               continue;
+                       }
+                       
                        if (is_int($val))
                                $set .= "$col = $val, ";
                        else if (is_string($val))
                                $set .= "$col = '$val', ";
-                       else if (is_null($var))
-                               $set .= "$col = NULL, ";
                }
                $set = substr($set, 0, -2);
                
diff --git a/data/user_pictures/admin-.jpg b/data/user_pictures/admin-.jpg
new file mode 100644 (file)
index 0000000..a33a4da
Binary files /dev/null and b/data/user_pictures/admin-.jpg differ
diff --git a/data/user_pictures/admin-.jpg-thumb.jpg b/data/user_pictures/admin-.jpg-thumb.jpg
new file mode 100644 (file)
index 0000000..95820d9
Binary files /dev/null and b/data/user_pictures/admin-.jpg-thumb.jpg differ