• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lonnieezell / myth-auth / 3871728138

pending completion
3871728138

Pull #587

github

GitHub
Merge a8c192379 into da3522738
Pull Request #587: Update development kit

815 of 2284 relevant lines covered (35.68%)

8.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

33.33
/src/Models/LoginModel.php
1
<?php
2

3
namespace Myth\Auth\Models;
4

5
use CodeIgniter\Model;
6
use DateTime;
7

8
class LoginModel extends Model
9
{
10
    protected $table          = 'auth_logins';
11
    protected $primaryKey     = 'id';
12
    protected $returnType     = 'object';
13
    protected $useSoftDeletes = false;
14
    protected $allowedFields  = [
15
        'ip_address', 'email', 'user_id', 'date', 'success',
16
    ];
17
    protected $useTimestamps   = false;
18
    protected $validationRules = [
19
        'ip_address' => 'required',
20
        'email'      => 'required',
21
        'user_id'    => 'permit_empty|integer',
22
        'date'       => 'required|valid_date',
23
    ];
24
    protected $validationMessages = [];
25
    protected $skipValidation     = false;
26

27
    /**
28
     * Stores a remember-me token for the user.
29
     *
30
     * @return mixed
31
     */
32
    public function rememberUser(int $userID, string $selector, string $validator, string $expires)
33
    {
34
        $expires = new DateTime($expires);
2✔
35

36
        return $this->db->table('auth_tokens')->insert([
2✔
37
            'user_id'         => $userID,
2✔
38
            'selector'        => $selector,
2✔
39
            'hashedValidator' => $validator,
2✔
40
            'expires'         => $expires->format('Y-m-d H:i:s'),
2✔
41
        ]);
2✔
42
    }
43

44
    /**
45
     * Returns the remember-me token info for a given selector.
46
     *
47
     * @return mixed
48
     */
49
    public function getRememberToken(string $selector)
50
    {
51
        return $this->db->table('auth_tokens')
×
52
            ->where('selector', $selector)
×
53
            ->get()
×
54
            ->getRow();
×
55
    }
56

57
    /**
58
     * Updates the validator for a given selector.
59
     *
60
     * @return mixed
61
     */
62
    public function updateRememberValidator(string $selector, string $validator)
63
    {
64
        return $this->db->table('auth_tokens')
×
65
            ->where('selector', $selector)
×
66
            ->update([
×
67
                'hashedValidator' => hash('sha256', $validator),
×
68
                'expires'         => (new DateTime())->modify('+' . config('Auth')->rememberLength . ' seconds')->format('Y-m-d H:i:s'),
×
69
            ]);
×
70
    }
71

72
    /**
73
     * Removes all persistent login tokens (RememberMe) for a single user
74
     * across all devices they may have logged in with.
75
     *
76
     * @return mixed
77
     */
78
    public function purgeRememberTokens(int $id)
79
    {
80
        return $this->builder('auth_tokens')->where(['user_id' => $id])->delete();
1✔
81
    }
82

83
    /**
84
     * Purges the 'auth_tokens' table of any records that are past
85
     * their expiration date already.
86
     */
87
    public function purgeOldRememberTokens()
88
    {
89
        $config = config('Auth');
×
90

91
        if (! $config->allowRemembering) {
×
92
            return;
×
93
        }
94

95
        $this->db->table('auth_tokens')
×
96
            ->where('expires <=', date('Y-m-d H:i:s'))
×
97
            ->delete();
×
98
    }
99
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc