}
/**
- * FIXME: Do something
- *
- * @param \obj $user
+ * @param \string $username
+ * @param \string $password
*
* @return bool
*/
- public function loadUser($user) {
+ public function loadUser($username, $password = NULL) {
+ $uid = JUserHelper::getUserId($username);
+ if (empty($uid)) {
+ return FALSE;
+ }
+ $contactID = CRM_Core_BAO_UFMatch::getContactId($uid);
+ if (!empty($password)) {
+ $instance = JFactory::getApplication('site');
+ $params = array(
+ 'username' => $username,
+ 'password' => $password,
+ );
+ //perform the login action
+ $instance->login($params);
+ }
+
+ $session = CRM_Core_Session::singleton();
+ $session->set('ufID', $uid);
+ $session->set('userID', $contactID);
return TRUE;
}
}
/**
- * FIXME: Do something
- *
- * @param \obj $user
+ * @param \string $user
*
* @return bool
*/
public function loadUser($user) {
+ $userdata = get_user_by('login', $user);
+ if (!$userdata->data->ID) {
+ return false;
+ }
+
+ $uid = $userdata->data->ID;
+ wp_set_current_user($uid);
+ $contactID = CRM_Core_BAO_UFMatch::getContactId($uid);
+
+ // lets store contact id and user id in session
+ $session = CRM_Core_Session::singleton();
+ $session->set('ufID', $uid);
+ $session->set('userID', $contactID);
return TRUE;
}
$this->_log(ts("Failed to login as %1. Wrong username or password.", array('1' => $this->_user)));
return FALSE;
}
- if (!$cms->loadUser($this->_user)) {
+ if (($this->_config->userFramework == 'Joomla' && !$cms->loadUser($this->_user, $this->_password)) || !$cms->loadUser($this->_user)) {
$this->_log(ts("Failed to login as %1", array('1' => $this->_user)));
return FALSE;
}