Updates the JFusion user lookup table during login

@param Userinfo $userinfo object containing the userdata

@return bool
181564
final public function deleteLookup(Userinfo $userinfo)
	{
		if ($userinfo->getJname() == $this->getJname()) {
			$db = Factory::getDBO();
			//we don't need to update the lookup for internal joomla unless deleting a user

			try {
				$query = $db->getQuery(true)
					->delete('#__jfusion_users')
					->where('userid = ' . $db->quote($userinfo->userid))
					->where('jname = ' . $db->quote($this->getJname()));

				$db->setQuery($query);
				$db->execute();
				return true;
			} catch (Exception $e) {
				Framework::raise(LogLevel::ERROR, $e);
			}
		}
		return false;
	}
834976
public function update($user, User $userToManage)
    {
        if ($userToManage->id == $user->id || $userToManage->superAdmin()) {
            return false;
        }

        $user = User::findOrFail($user->id);

        return $user->hasPermission('laralum::users.update') || $user->superAdmin();
    }
268635
public function save(Userinfo $userinfo, Userinfo $olduserinfo = null, $new = false)
	{
		$this->debugger->set(null, array());

		//create an array to store the debug info
		$debug_info = array();
		$error_info = array();


		$plugins = Factory::getPlugins();

		if ($userinfo instanceof Userinfo) {
			// Recover the old data of the user
			// This is then used to determine if the username was changed
			$updateUsername = false;

			if ($userinfo->getJname() !== null && $olduserinfo->getJname() !== null) {
				if ($new == false && $userinfo instanceof Userinfo && $olduserinfo instanceof Userinfo) {
					if ($userinfo->getJname() == $olduserinfo->getJname() && $userinfo->username != $olduserinfo->username) {
						$updateUsername = true;
					}
				}
			}
			$exsistingUser = User::search($olduserinfo, true);

			foreach ($plugins as $plugin) {
				try {
					$userPlugin = Factory::getUser($plugin->name);
					if ($userPlugin->validateUser($userinfo)) {
						if ($updateUsername) {
							if ($exsistingUser instanceof Userinfo) {
								$pluginUserinfo = $userPlugin->getUser($exsistingUser);

								if ($pluginUserinfo instanceof Userinfo) {
									try {
										$userPlugin->resetDebugger();
										$userPlugin->updateUsername($userinfo, $pluginUserinfo);
										if (!$userPlugin->debugger->isEmpty('error')) {
											$error_info[$plugin->name . ' ' . Text::_('USERNAME') . ' ' . Text::_('UPDATE') . ' ' . Text::_('ERROR') ] = $userPlugin->debugger->get('error');
										}
										if (!$userPlugin->debugger->isEmpty('debug')) {
											$debug_info[$plugin->name . ' ' . Text::_('USERNAME') . ' ' . Text::_('UPDATE') . ' ' . Text::_('DEBUG') ] = $userPlugin->debugger->get('debug');
										}
									} catch (Exception $e) {
										$status[LogLevel::ERROR][] = Text::_('USERNAME_UPDATE_ERROR') . ': ' . $e->getMessage();
									}
								} else {
									$error_info[$plugin->name] = Text::_('NO_USER_DATA_FOUND');
								}
							}
						}
						//run the update user to ensure any other userinfo is updated as well
						$userPlugin->resetDebugger();
						$pluginUserinfo = $userPlugin->updateUser($userinfo, 1);
						$debug = $userPlugin->debugger->get();

						if (!empty($debug[LogLevel::ERROR])) {
							$error_info[$plugin->name] = $debug[LogLevel::ERROR];
						}
						if (!empty($debug[LogLevel::DEBUG])) {
							$debug_info[$plugin->name] = $debug[LogLevel::DEBUG];
						}
						if (!$pluginUserinfo instanceof Userinfo) {
							//make sure the userinfo is available
							$pluginUserinfo = $userPlugin->getUser($userinfo);
						}
						//update the jfusion_users table
						if ($pluginUserinfo instanceof Userinfo) {
							$userPlugin->updateLookup($pluginUserinfo, $userinfo);
						}
					}
				} catch (Exception $e) {
					$error_info[$plugin->name] = array($e->getMessage());
				}
			}
		}
		$this->debugger->set('debug', $debug_info);
		$this->debugger->set('error', $error_info);
		return true;
	}
801712
function doUpdatePassword(Userinfo $userinfo, Userinfo &$existinguser)
	{
		$changed = false;

		if (!empty($userinfo->password_clear) && strlen($userinfo->password_clear) != 32) {
			// add password_clear to existinguser for the Joomla helper routines
			$existinguser->password_clear = $userinfo->password_clear;
			//check if the password needs to be updated
			try {
				$model = Factory::getAuth($this->getJname());
				if ($model->checkPassword($existinguser) !== true) {
					try {
						$this->updatePassword($userinfo, $existinguser);
						$changed = true;
					} catch (Exception $e) {
						$this->debugger->addError(Text::_('PASSWORD_UPDATE_ERROR') . ' ' . $e->getMessage());
					}
				} else {
					$this->debugger->addDebug(Text::_('SKIPPED_PASSWORD_UPDATE') . ':' . Text::_('PASSWORD_VALID'));
				}
			} catch (Exception $e) {
				$this->debugger->addError(Text::_('SKIPPED_PASSWORD_UPDATE') . ':' . $e->getMessage());
			}
		} else {
			$this->debugger->addDebug(Text::_('SKIPPED_PASSWORD_UPDATE') . ': ' . Text::_('PASSWORD_UNAVAILABLE'));
		}
		return $changed;
	}
1257742
protected function update_users_used() {
        global $DB;

        $this->userfullnames = array();
        $userids = array();

        // For each event cache full username.
        // Get list of userids which will be shown in log report.
        foreach ($this->rawdata as $event) {
            $logextra = $event->get_logextra();
            if (!empty($event->userid) && empty($userids[$event->userid])) {
                $userids[$event->userid] = $event->userid;
            }
            if (!empty($logextra['realuserid']) && empty($userids[$logextra['realuserid']])) {
                $userids[$logextra['realuserid']] = $logextra['realuserid'];
            }
            if (!empty($event->relateduserid) && empty($userids[$event->relateduserid])) {
                $userids[$event->relateduserid] = $event->relateduserid;
            }
        }
        $this->rawdata->close();

        // Get user fullname and put that in return list.
        if (!empty($userids)) {
            list($usql, $uparams) = $DB->get_in_or_equal($userids);
            $users = $DB->get_records_sql("SELECT id," . get_all_user_name_fields(true) . " FROM {user} WHERE id " . $usql,
                    $uparams);
            foreach ($users as $userid => $user) {
                $this->userfullnames[$userid] = fullname($user);
                unset($userids[$userid]);
            }

            // We fill the array with false values for the users that don't exist anymore
            // in the database so we don't need to query the db again later.
            foreach ($userids as $userid) {
                $this->userfullnames[$userid] = false;
            }
        }
    }
47149
function doCreateUser(Userinfo $userinfo)
	{
		$user = null;

		//check activation and block status
		$create_inactive = $this->params->get('create_inactive', 1);
		$create_blocked = $this->params->get('create_blocked', 1);

		if ((empty($create_inactive) && !empty($userinfo->activation)) || (empty($create_blocked) && !empty($userinfo->block))) {
			//block user creation
			$this->debugger->addDebug(Text::_('SKIPPED_USER_CREATION'));
			$this->debugger->set('action', 'unchanged');
		} else {
			$this->debugger->addDebug(Text::_('NO_USER_FOUND_CREATING_ONE'));
			try {
				$user = $this->createUser($userinfo);
				$this->debugger->addDebug(Text::_('USER_CREATION'));
				$this->debugger->set('action', 'created');
			} catch (Exception $e) {
				$this->debugger->addError(Text::_('USER_CREATION_ERROR') . $e->getMessage());
			}
		}
		return $user;
	}
229494
public function setUsername($username)
    {
        if($username == $this->username){
            return true;
        }
        if ($this->usernameExists($username)) {
            return false;
        }

        if ($this->setUsernameStatement === null) {
            $this->setUsernameStatement = $this->connection->prepare("UPDATE User SET username = ? WHERE username = ?");
        }
        $wasLoggedIn = $this->isLoggedIn();

        $this->setUsernameStatement->execute(array($username, $this->username));
        $this->username = $username;

        if ($wasLoggedIn) {
            $this->updateLoginSession();
        }
        $this->notifyObservers(User::EVENT_USERNAME_UPDATE);
        return true;
    }
1013480
public static function search(Userinfo $userinfo, $lookup = false)
	{
		$exsistingUser = null;

		if ($lookup && $userinfo->getJname() !== null) {
			$userPlugin = Factory::getUser($userinfo->getJname());

			$exsistingUser = $userPlugin->lookupUser($userinfo);
		}
		if (!$exsistingUser instanceof Userinfo) {
			$plugins = Factory::getPlugins();
			foreach ($plugins as $plugin) {
				try {
					$JFusionSlave = Factory::getUser($plugin->name);

					$exsistingUser = $JFusionSlave->getUser($userinfo);
					if ($exsistingUser instanceof Userinfo) {
						break;
					}
				} catch (Exception $e) {
				}
			}
		}
		return $exsistingUser;
	}
1016930
public function update($user_id, array $data)
    {
        $result = null;
        $this->hook->attach('user.update.before', $user_id, $data, $result, $this);

        if (isset($result)) {
            return (bool) $result;
        }

        $data['modified'] = GC_TIME;

        if (!empty($data['password'])) {
            $data['hash'] = gplcart_string_hash($data['password']);
        }

        if ($this->isSuperadmin($user_id)) {
            $data['status'] = 1;
        }

        $updated = $this->db->update('user', $data, array('user_id' => $user_id));
        $data['user_id'] = $user_id;
        $updated += (int) $this->setAddress($data);

        $result = $updated > 0;
        $this->hook->attach('user.update.after', $user_id, $data, $result, $this);
        return (bool) $result;
    }
393834
final public function lookupUser(Userinfo $exsistinginfo)
	{
		$user = null;
		if ($exsistinginfo) {
			//initialise some vars
			$db = Factory::getDBO();

			$query = $db->getQuery(true)
				->select('b.userid, b.username, b.email')
				->from('#__jfusion_users AS a')
				->innerJoin('#__jfusion_users AS b ON a.id = b.id')
				->where('b.jname = ' . $db->quote($this->getJname()))
				->where('a.jname = ' . $db->quote($exsistinginfo->getJname()));

			$search = array();
			if (isset($exsistinginfo->userid)) {
				$search[] = 'a.userid = ' . $db->quote($exsistinginfo->userid);
			}
			if (isset($exsistinginfo->username)) {
				$search[] = 'a.username = ' . $db->quote($exsistinginfo->username);
			}
			if (isset($exsistinginfo->email)) {
				$search[] = 'a.email = ' . $db->quote($exsistinginfo->email);
			}
			if (!empty($search)) {
				$query->where('( ' . implode(' OR ', $search) . ' )');
				$db->setQuery($query);
				$result = $db->loadObject();

				if ($result) {
					$user = new Userinfo($this->getJname());
					$user->bind($result);
				}
			}
		}
		return $user;
	}
934005
public function login(string $userID): bool
    {
        $data = Internal\Server::call('login', ['userID' => $userID], true);
        if (isset($data['result'])) {
            return $data['result'] === 'ok';
        }
        return false;
    }
626689
public function updateUserRecordWithLastlogin($userId) {

        $now = Carbon::now();
        $ip  = $this->request->getClientIp();

        DB::table('users')
            ->where('id', $userId)
            ->update(['last_login' => $now, 'last_login_ip' => $ip] )
        ;
    }
1007511
public function updateUser($username, array $data)
    {
        /** @var UserInterface|EloquentUser $user */
        if ( ! ($user = $this->sentinel->findByCredentials(['email' => $username]))) {
            return false;
        }

        return $user->update($data);
    }
187391
private function checkUserInfo() : void
    {
        foreach ($this->user->getAttributes() as $key => $value) {
            $this->{$key} = $value;
        }
    }
782412
public function login( UserData $user ) {
		// clear session
		foreach ( $_SESSION as $key => $value ) {
			unset( $_SESSION[$key] );
		}

		// generate new session id
		session_regenerate_id( true );

		// store user info in session
		$this->setUser( $user );
	}
1191719
function doUserLanguage(Userinfo $userinfo, Userinfo &$existinguser)
	{
		$changed = false;
		//Update the user language with the current used in Joomla or the one existing from an other plugin
		if (empty($userinfo->language)) {
			$user_lang = '';
			if (!empty($userinfo->params)) {
				$params = new Registry($userinfo->params);
				$user_lang = $params->get('language');
			}
			$userinfo->language = !empty($user_lang) ? $user_lang : Factory::getLanguage()->getTag();
		}
		if (!empty($userinfo->language) && isset($existinguser->language) && !empty($existinguser->language) && $userinfo->language != $existinguser->language) {
			try {
				$this->updateUserLanguage($userinfo, $existinguser);
				$existinguser->language = $userinfo->language;
				$this->debugger->addDebug(Text::_('LANGUAGE_UPDATED') . ' : ' . $existinguser->language . ' -> ' . $userinfo->language);

				$changed = true;
			} catch (Exception $e) {
				$this->debugger->addError(Text::_('LANGUAGE_UPDATED_ERROR') . ' ' . $e->getMessage());
			}
		} else {
			//return a debug to inform we skipped this step
			$this->debugger->addDebug(Text::_('LANGUAGE_NOT_UPDATED'));
		}
		return $changed;
	}
772881
public function updateMetaData(string $key, string $value): User
    {
        $previous = get_user_meta($this->ID, $key, true);

        if ($previous === $value) {
            return $this;
        }

        $update = update_user_meta($this->ID, $key, $value, $previous);

        if (false === $update) {
            throw new UserException("Cannot update user meta data with a key of [$key]");
        }

        return $this;
    }