File: User.php

package info (click to toggle)
dokuwiki 2024-02-06b%2Bdfsg-9
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 24,624 kB
  • sloc: php: 97,851; javascript: 3,724; sh: 599; makefile: 70; xml: 34
file content (71 lines) | stat: -rw-r--r-- 2,127 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php

namespace dokuwiki\Remote\Response;

/**
 * Represents a user
 */
class User extends ApiResponse
{
    /** @var string The login name of the user */
    public $login;
    /** @var string The full name of the user */
    public $name;
    /** @var string The email address of the user */
    public $mail;
    /** @var string[] The groups the user is in */
    public $groups;
    /** @var bool Whether the user is a super user */
    public bool $isadmin;
    /** @var bool Whether the user is a manager */
    public bool $ismanager;

    /**
     * @param string $login defaults to the current user
     * @param string $name
     * @param string $mail
     * @param string[] $groups
     */
    public function __construct($login = '', $name = '', $mail = '', $groups = [])
    {
        global $INPUT;
        global $USERINFO;
        global $auth;

        $this->login = $login;
        $this->name = $name;
        $this->mail = $mail;
        $this->groups = $groups;

        if ($this->login === '') {
            $this->login = $INPUT->server->str('REMOTE_USER');
        }

        if ($this->login === '') {
            throw new \RuntimeException('No user available');
        }

        // for current user, use $USERINFO to fill up
        if ($this->login === $INPUT->server->str('REMOTE_USER')) {
            $this->name = $this->name ?: $USERINFO['name'];
            $this->mail = $this->mail ?: $USERINFO['mail'];
            $this->groups = $this->groups ?: $USERINFO['grps'];
        } else {
            // for other users, use auth_getUserData to fill up
            $userData = $auth->getUserData($this->login);
            $this->name = $this->name ?: $userData['name'];
            $this->mail = $this->mail ?: $userData['mail'];
            $this->groups = $this->groups ?: $userData['grps'];
        }

        // check for admin and manager
        $this->isadmin = auth_isAdmin($this->login, $this->groups);
        $this->ismanager = auth_isManager($this->login, $this->groups);
    }

    /** @inheritdoc */
    public function __toString()
    {
        return $this->login;
    }
}