*/
var $bugdarUser;
+ /**
+ * Mapping of Bugdar fields to authentication database fields; these will be synced between databases upon login
+ * @var array
+ */
+ var $fieldMap = array(
+ 'authid' => null,
+ 'displayname' => null,
+ 'email' => null,
+ 'password' => null,
+ );
+
// ###################################################################
/**
* Constructor
$this->registry =& $bugsys;
$this->db =& $bugsys->db;
+ $this->registry->debug('authentication system: ' . get_class($this));
+
$this->_setupDatabase();
}
if ($this->_verifyCookieData())
{
$this->_setCookies(true);
+ $this->_syncBugdarUser();
$this->bugdarUser = $this->_fetchBugdarUserFromAuthUser();
return true;
}
if ($this->_verifyLoginUser($password))
{
$this->_setCookies($sticky);
+ $this->_syncBugdarUser();
$this->bugdarUser = $this->_fetchBugdarUserFromAuthUser();
return true;
}
* Creates a Bugdar user with the authentication details specified in
* the auth array and returns it. You need to call this in
* _fetchBugdarUserFromAuthUser() and use the UserAPI to create the user.
- * Example for this function is this (all of these fields are required):
- *
- * $user = new UserAPI($this->registry); // do not change this
- * $user->set('email', $this->authUser['email']);
- * $user->set('displayname', $this->authUser['name']);
- * $user->set('password', $this->authUser['password']); // some random value that won't be used for authentication
- * $user->set('usergroupid', 2); // default "Registered Users" group
- * $user->set('authid', $this->authUser['userid']); // This must be a COMPLETELY STATIC key that is found in the auth db that will permanently link Bugdar to the auth user
- * $user->insert(); // saves the user
- *
- * return $user->values; // returns the newly created user array
+ * This will create a new user in Bugdar with the data from the authentication DB
+ * with the fields specified in fieldMap.
+ */
+ function _createBugdarUser()
+ {
+ $user = new UserAPI($this->registry);
+
+ // if the email already exists in the DB, it must be the same person so just hook up the authid
+ if ($check = $this->db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE email = '" . $this->db->escape_string($this->authUser[ $this->fieldMap['email'] ]) . "'"))
+ {
+ $user->set('userid', $check['userid']);
+ $user->set_condition();
+ $user->set('authid', $this->authUser[ $this->fieldMap['authid'] ]);
+ $user->update();
+ $user->fetch();
+
+ return $user->objdata;
+ }
+ else
+ {
+ $user = new UserAPI($this->registry);
+ foreach ($this->fieldMap AS $bugdar => $authdb)
+ {
+ $user->set($bugdar, $this->authUser["$authDb"]);
+ }
+ $user->set('usergroupid', 2);
+ $user->insert();
+
+ return $user->values;
+ }
+ }
+
+ // ###################################################################
+ /**
+ * Syncs a Bugdar user's fieldMap'ed values to the authentication DB's
+ * values. This allows the users to stay mostly-in-sync for the most
+ * basic of information (like email, timezone, etc.). Passwords are
+ * NOT synced.
*/
- function _createBugdarUser() {}
+ function _syncBugdarUser()
+ {
+ $fields = $this->fieldMap;
+ unset($fields['authid']);
+ unset($fields['password']);
+ $user = new UserAPI($this->registry);
+ $user->set('userid', $this->authUser[ $this->fieldMap['authid'] ]);
+ foreach ($fields AS $bugdar => $authdb)
+ {
+ $user->set($bugdar, $this->authUser["$authdb"]);
+ }
+ $user->update();
+ }
+
// ###################################################################
/**
* Responsible for unsetting all authentication cookies because they
*/
var $vBTablePrefix = '';
+ /**
+ * Fields that map Bugdar fields to vBulletin fields
+ * @var string
+ */
+ var $fieldMap = array(
+ 'authid' => 'userid',
+ 'email' => 'email',
+ 'timezone' => 'timezoneoffset',
+ 'password' => 'passworrd',
+ 'displayname' => 'username'
+ );
+
// ###################################################################
function _setupDatabase()
{
}
return $user;
}
-
- // ###################################################################
- function _createBugdarUser()
- {
- $user = new UserAPI($this->registry);
-
- // if the email already exists in the DB, it must be the same person so just hook up the authid
- if ($check = $this->db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE email = '" . $this->db->escape_string($this->authUser['email']) . "'"))
- {
- $user->set('userid', $check['userid']);
- $user->set_condition();
- $user->set('authid', $this->authUser['userid']);
- $user->update();
- $user->fetch();
-
- return $user->objdata;
- }
- else
- {
- $user = new UserAPI($this->registry);
- $user->set('email', $this->authUser['email']);
- $user->set('displayname', $this->authUser['username']);
- $user->set('password', $this->authUser['password']);
- $user->set('usergroupid', 2);
- $user->set('authid', $this->authUser['userid']);
- $user->set('timezone', $this->authUser['timezoneoffset']);
- $user->insert();
-
- return $user->values;
- }
- }
-
+
// ###################################################################
function _fetchUserWithIdentifier($username)
{