]> git.mxchange.org Git - friendica.git/blob - src/Security/TwoFactor/Model/TrustedBrowser.php
Merge remote-tracking branch 'upstream/develop' into server-detection
[friendica.git] / src / Security / TwoFactor / Model / TrustedBrowser.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Security\TwoFactor\Model;
23
24 use Friendica\BaseEntity;
25 use Friendica\Util\DateTimeFormat;
26
27 /**
28  * Class TrustedBrowser
29  *
30  *
31  * @property-read $cookie_hash
32  * @property-read $uid
33  * @property-read $user_agent
34  * @property-read $trusted
35  * @property-read $created
36  * @property-read $last_used
37  * @package Friendica\Model\TwoFactor
38  */
39 class TrustedBrowser extends BaseEntity
40 {
41         protected $cookie_hash;
42         protected $uid;
43         protected $user_agent;
44         protected $trusted;
45         protected $created;
46         protected $last_used;
47
48         /**
49          * Please do not use this constructor directly, instead use one of the method of the TrustedBroser factory.
50          *
51          * @see \Friendica\Security\TwoFactor\Factory\TrustedBrowser
52          *
53          * @param string      $cookie_hash
54          * @param int         $uid
55          * @param string      $user_agent
56          * @param bool        $trusted
57          * @param string      $created
58          * @param string|null $last_used
59          */
60         public function __construct(string $cookie_hash, int $uid, string $user_agent, bool $trusted, string $created, string $last_used = null)
61         {
62                 $this->cookie_hash = $cookie_hash;
63                 $this->uid         = $uid;
64                 $this->user_agent  = $user_agent;
65                 $this->trusted     = $trusted;
66                 $this->created     = $created;
67                 $this->last_used   = $last_used;
68         }
69
70         /**
71          * Records if the trusted browser was used
72          *
73          * @return void
74          * @throws \Exception unexpected DateTime exception happened
75          */
76         public function recordUse()
77         {
78                 $this->last_used = DateTimeFormat::utcNow();
79         }
80 }