/**
  * (non-PHPdoc)
  * @see IUserLoginMethod::authenticateWithEmail()
  */
 public function authenticateWithEmail($email, $password)
 {
     // connect to a data base
     // Note: If your source application shares the same data base, you can simply use $this->_db, rather than open another connection.
     $mysqli = new mysqli($this->_websoccer->getConfig('db_host'), $this->_websoccer->getConfig('db_user'), $this->_websoccer->getConfig('db_passwort'), $this->_websoccer->getConfig('db_name'));
     // get user from your source table
     $escapedEMail = $mysqli->real_escape_string($email);
     $dbresult = $mysqli->query('SELECT password FROM mydummy_table WHERE email = \'' . $escapedEMail . '\'');
     if (!$dbresult) {
         throw new Exception('Database Query Error: ' . $mysqli->error);
     }
     $myUser = $dbresult->fetch_array();
     $dbresult->free();
     $mysqli->close();
     // could not find user
     if (!$myUser) {
         return FALSE;
     }
     // check is password is correct (in this sample case a simple MD5 hashing is applied).
     if ($myUser['password'] != md5($password)) {
         return FALSE;
     }
     // user is valid user according to custom authentication check. Now test if user already exists in local DB and return its ID.
     $existingUserId = UsersDataService::getUserIdByEmail($this->_websoccer, $this->_db, strtolower($email));
     if ($existingUserId > 0) {
         return $existingUserId;
     }
     // if user does not exist, create a new one. Nick name can be entered by user later.
     return UsersDataService::createLocalUser($this->_websoccer, $this->_db, null, $email);
 }
 private function _authenticate($queryWhereCondition, $loginStr, $password)
 {
     // query user in Joomla table
     $result = $this->_db->querySelect('user_login,user_email,user_pass', $this->_websoccer->getConfig('wordpresslogin_tableprefix') . 'users', 'user_status = 0 AND ' . $queryWhereCondition, $loginStr);
     $wpUser = $result->fetch_array();
     $result->free();
     // user does not exist
     if (!$wpUser) {
         return FALSE;
     }
     // check password.
     require BASE_FOLDER . '/classes/phpass/PasswordHash.php';
     $hasher = new PasswordHash(8, TRUE);
     if (!$hasher->CheckPassword($password, $wpUser['user_pass'])) {
         return FALSE;
     }
     // valid user, check if he exists
     $userEmail = strtolower($wpUser['user_email']);
     $userId = UsersDataService::getUserIdByEmail($this->_websoccer, $this->_db, $userEmail);
     if ($userId > 0) {
         return $userId;
     }
     // create new user
     return UsersDataService::createLocalUser($this->_websoccer, $this->_db, $wpUser['user_login'], $userEmail);
 }
 private function _authenticate($queryWhereCondition, $loginStr, $password)
 {
     // query user in Joomla table
     $result = $this->_db->querySelect('username,email,password', $this->_websoccer->getConfig('joomlalogin_tableprefix') . 'users', 'block < 1 AND ' . $queryWhereCondition, $loginStr);
     $joomlaUser = $result->fetch_array();
     $result->free();
     // user does not exist
     if (!$joomlaUser) {
         return FALSE;
     }
     // check password. Joomla password has two parts: 0. password hash; 1. salt
     $passwordParts = explode(':', $joomlaUser['password']);
     $hashedPassword = md5($password . $passwordParts[1]);
     if ($hashedPassword != $passwordParts[0]) {
         return FALSE;
     }
     // valid user, check if he exists
     $userEmail = strtolower($joomlaUser['email']);
     $userId = UsersDataService::getUserIdByEmail($this->_websoccer, $this->_db, $userEmail);
     if ($userId > 0) {
         return $userId;
     }
     // create new user
     return UsersDataService::createLocalUser($this->_websoccer, $this->_db, $joomlaUser['username'], $userEmail);
 }
 public function executeAction($parameters)
 {
     // authenticate
     $userEmail = FacebookSdk::getInstance($this->_websoccer)->getUserEmail();
     // not authenticated
     if (!strlen($userEmail)) {
         $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_WARNING, $this->_i18n->getMessage("facebooklogin_failure"), ""));
         return "home";
     }
     // authenticated. Check if user exists.
     $userEmail = strtolower($userEmail);
     $userId = UsersDataService::getUserIdByEmail($this->_websoccer, $this->_db, $userEmail);
     // if does not exist, then create new user
     if ($userId < 1) {
         $userId = UsersDataService::createLocalUser($this->_websoccer, $this->_db, null, $userEmail);
     }
     // log in user
     SecurityUtil::loginFrontUserUsingApplicationSession($this->_websoccer, $userId);
     $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("facebooklogin_success"), ""));
     return strlen($this->_websoccer->getUser()->username) ? "office" : "enter-username";
 }