require_once SYSPATH . "Ext/hybridauth/Hybrid/Auth.php";
 try {
     // hybridauth EP
     $hybridauth = new Hybrid_Auth($config);
     // automatically try to login with Twitter
     $adapter = $hybridauth->authenticate($name);
     // get the user profile
     $user_profile = $adapter->getUserProfile();
     //        var_dump($user_profile);
     //oauth identifier
     $oauth_id = md5($name . $user_profile->identifier);
     $db = \DB::getPDO();
     $qry = 'SELECT id, username, avatar FROM ' . PREFIX . 'codo_users WHERE oauth_id=:oauth_id';
     $stmt = $db->prepare($qry);
     $stmt->execute(array(":oauth_id" => $oauth_id));
     $username = CODOF\Filter::clean_username($user_profile->displayName);
     $profile = $stmt->fetch();
     if (!empty($profile)) {
         if ($username != $profile['username'] || $user_profile->photoURL != $profile['avatar']) {
             //profile has been updated remotely
             $qry = 'UPDATE ' . PREFIX . 'codo_users SET username=:name,avatar=:avatar WHERE oauth_id=:id';
             $stmt = $db->prepare($qry);
             $stmt->execute(array(":name" => $username, ":avatar" => $user_profile->photoURL, ":id" => $oauth_id));
         }
         CODOF\User\User::login($profile['id']);
     } else {
         //no local copy of this profile yet
         $mail = $user_profile->email;
         $create_account = true;
         if ($mail == null) {
             $mail = '';