4 * @file src/Model/User.php
5 * @brief This file includes the User class with user related database functions
8 namespace Friendica\Model;
10 use Friendica\Core\System;
11 use Friendica\Core\Worker;
12 use Friendica\Database\DBM;
15 require_once 'boot.php';
16 require_once 'include/plugin.php';
19 * @brief This class handles User related functions
23 public static function authenticate($user_info, $password)
25 if (is_object($user_info)) {
26 $user = (array) $user_info;
27 } elseif (is_int($user_info)) {
28 $user = dba::select('user',
33 'account_expired' => 0,
34 'account_removed' => 0,
39 } elseif (is_string($user_info)) {
40 $user = dba::fetch_first('SELECT `uid`, `password`
42 WHERE (`email` = ? OR `username` = ? OR `nickname` = ?)
44 AND `account_expired` = 0
45 AND `account_removed` = 0
56 if (!DBM::isResult($user) || !isset($user['uid']) || !isset($user['password'])) {
60 $password_hashed = hash('whirlpool', $password);
62 if ($password_hashed !== $user['password']) {
70 * @param object $uid user to remove
73 public static function remove($uid)
79 logger('Removing user: ' . $uid);
81 $r = dba::select('user', array(), array('uid' => $uid), array("limit" => 1));
83 call_hooks('remove_user', $r);
85 // save username (actually the nickname as it is guaranteed
86 // unique), so it cannot be re-registered in the future.
88 dba::insert('userd', array('username' => $r['nickname']));
90 // The user and related data will be deleted in "cron_expire_and_remove_users" (cronjobs.php)
91 q("UPDATE `user` SET `account_removed` = 1, `account_expires_on` = UTC_TIMESTAMP() WHERE `uid` = %d", intval($uid));
92 Worker::add(PRIORITY_HIGH, "Notifier", "removeme", $uid);
94 // Send an update to the directory
95 Worker::add(PRIORITY_LOW, "Directory", $r['url']);
97 if ($uid == local_user()) {
98 unset($_SESSION['authenticated']);
99 unset($_SESSION['uid']);
100 goaway(System::baseUrl());