User.php 4.23 KB
Newer Older
Jacob Priddy's avatar
Jacob Priddy committed
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
<?php


namespace Source\Entities;


use Carbon\Carbon;

class User {
    /**
     * @var int
     */
    protected int $id;

    /**
     * @var string
     */
    protected string $firstName;

    /**
     * @var string
     */
    protected string $lastName;

    /**
     * @var string
     */
    protected string $displayName;

    /**
     * @var string|null
     */
    protected ?string $emplid;

    /**
     * @var string
     */
    protected string $email;

    /**
Jacob Priddy's avatar
Jacob Priddy committed
41
     * @var string|null
Jacob Priddy's avatar
Jacob Priddy committed
42
     */
Jacob Priddy's avatar
Jacob Priddy committed
43
    protected ?string $password;
Jacob Priddy's avatar
Jacob Priddy committed
44
45
46
47
48
49
50

    /**
     * @var string
     */
    protected string $doorcode;

    /**
Jacob Priddy's avatar
Jacob Priddy committed
51
     * @var Carbon|null
Jacob Priddy's avatar
Jacob Priddy committed
52
     */
Jacob Priddy's avatar
Jacob Priddy committed
53
    protected ?Carbon $expiresAt;
Jacob Priddy's avatar
Jacob Priddy committed
54
55

    /**
Jacob Priddy's avatar
Jacob Priddy committed
56
     * @var Carbon|null
Jacob Priddy's avatar
Jacob Priddy committed
57
     */
Jacob Priddy's avatar
Jacob Priddy committed
58
    protected ?Carbon $createdAt;
Jacob Priddy's avatar
Jacob Priddy committed
59
60

    /**
Jacob Priddy's avatar
Jacob Priddy committed
61
     * @var Carbon|null
Jacob Priddy's avatar
Jacob Priddy committed
62
     */
Jacob Priddy's avatar
Jacob Priddy committed
63
    protected ?Carbon $updatedAt;
Jacob Priddy's avatar
Jacob Priddy committed
64
65
66
67
68
69
70
71
72
73

    /**
     * @param int         $id
     * @param string      $firstName
     * @param string      $lastName
     * @param string      $displayName
     * @param string|null $emplid
     * @param string      $email
     * @param string      $password
     * @param string      $doorcode
Jacob Priddy's avatar
Jacob Priddy committed
74
75
76
     * @param Carbon|null $expiresAt
     * @param Carbon|null $createdAt
     * @param Carbon|null $updatedAt
Jacob Priddy's avatar
Jacob Priddy committed
77
78
79
80
81
82
83
     */
    public function __construct(int $id,
                                string $firstName,
                                string $lastName,
                                string $displayName,
                                ?string $emplid,
                                string $email,
Jacob Priddy's avatar
Jacob Priddy committed
84
                                ?string $password,
Jacob Priddy's avatar
Jacob Priddy committed
85
                                string $doorcode,
Jacob Priddy's avatar
Jacob Priddy committed
86
87
88
                                ?Carbon $expiresAt,
                                ?Carbon $createdAt,
                                ?Carbon $updatedAt) {
Jacob Priddy's avatar
Jacob Priddy committed
89
90
91
92
93
        $this->id = $id;
        $this->firstName = $firstName;
        $this->lastName = $lastName;
        $this->displayName = $displayName;
        $this->emplid = $emplid;
Jacob Priddy's avatar
Jacob Priddy committed
94
        $this->email = strtolower($email);
Jacob Priddy's avatar
Jacob Priddy committed
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
        $this->password = $password;
        $this->doorcode = $doorcode;
        $this->expiresAt = $expiresAt;
        $this->createdAt = $createdAt;
        $this->updatedAt = $updatedAt;
    }

    /**
     * @return int
     */
    public function getId(): int {
        return $this->id;
    }

    /**
     * @return string
     */
    public function getFirstName(): string {
        return $this->firstName;
    }

    /**
     * @return string
     */
    public function getLastName(): string {
        return $this->lastName;
    }

    /**
     * @return string
     */
    public function getDisplayName(): string {
        return $this->displayName;
    }

    /**
     * @return string|null
     */
    public function getEmplid(): ?string {
        return $this->emplid;
    }

    /**
     * @return string
     */
    public function getEmail(): string {
        return $this->email;
    }

    /**
Jacob Priddy's avatar
Jacob Priddy committed
145
     * @return string|null
Jacob Priddy's avatar
Jacob Priddy committed
146
     */
Jacob Priddy's avatar
Jacob Priddy committed
147
    public function getPassword(): ?string {
Jacob Priddy's avatar
Jacob Priddy committed
148
149
150
151
152
153
154
155
156
157
158
        return $this->password;
    }

    /**
     * @return string
     */
    public function getDoorcode(): string {
        return $this->doorcode;
    }

    /**
Jacob Priddy's avatar
Jacob Priddy committed
159
     * @return Carbon|null
Jacob Priddy's avatar
Jacob Priddy committed
160
     */
Jacob Priddy's avatar
Jacob Priddy committed
161
    public function getExpiresAt(): ?Carbon {
Jacob Priddy's avatar
Jacob Priddy committed
162
163
164
165
        return $this->expiresAt;
    }

    /**
Jacob Priddy's avatar
Jacob Priddy committed
166
     * @return Carbon|null
Jacob Priddy's avatar
Jacob Priddy committed
167
     */
Jacob Priddy's avatar
Jacob Priddy committed
168
    public function getCreatedAt(): ?Carbon {
Jacob Priddy's avatar
Jacob Priddy committed
169
170
171
172
        return $this->createdAt;
    }

    /**
Jacob Priddy's avatar
Jacob Priddy committed
173
     * @return Carbon|null
Jacob Priddy's avatar
Jacob Priddy committed
174
     */
Jacob Priddy's avatar
Jacob Priddy committed
175
    public function getUpdatedAt(): ?Carbon {
Jacob Priddy's avatar
Jacob Priddy committed
176
177
178
179
180
181
182
183
184
185
186
        return $this->updatedAt;
    }

    /**
     * @param int $id
     */
    public function setId(int $id): void {
        $this->id = $id;
    }

    /**
Jacob Priddy's avatar
Jacob Priddy committed
187
     * @param string $id
Jacob Priddy's avatar
Jacob Priddy committed
188
189
     * @return bool
     */
Jacob Priddy's avatar
Jacob Priddy committed
190
191
192
193
194
    public function hasUserIdOf(?string $id): bool {
        if ($id === null) {
            return false;
        }

Jacob Priddy's avatar
Jacob Priddy committed
195
        return $this->getId() === (int)$id;
Jacob Priddy's avatar
Jacob Priddy committed
196
    }
Jacob Priddy's avatar
Jacob Priddy committed
197
198

    public function matchCredentials(?string $email, ?string $password): bool {
Jacob Priddy's avatar
Jacob Priddy committed
199
200
201
        if (!$password || !$email) {
            return false;
        }
Jacob Priddy's avatar
Jacob Priddy committed
202

Jacob Priddy's avatar
Jacob Priddy committed
203
204
205
206
207
208
209
210
211
212
        return $this->getEmail() === $email && $this->getPassword() === $password;
    }

    /**
     * @param string $doorcode
     * @return bool
     */
    public function hasDoorcodeOf(?string $doorcode): bool {
        return $this->getDoorcode() === $doorcode;
    }
Jacob Priddy's avatar
Jacob Priddy committed
213
}