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

conedevelopment / root / 15084089635

17 May 2025 10:00AM UTC coverage: 77.93% (+0.04%) from 77.891%
15084089635

push

github

web-flow
Modernize back-end.yml (#240)

3291 of 4223 relevant lines covered (77.93%)

36.04 hits per line

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

73.68
/src/Models/User.php
1
<?php
2

3
namespace Cone\Root\Models;
4

5
use Cone\Root\Interfaces\Models\User as Contract;
6
use Cone\Root\Traits\HasMedia;
7
use Cone\Root\Traits\HasMetaData;
8
use Cone\Root\Traits\InteractsWithProxy;
9
use Illuminate\Database\Eloquent\Casts\Attribute;
10
use Illuminate\Database\Eloquent\Relations\HasMany;
11
use Illuminate\Database\Eloquent\Relations\HasOne;
12
use Illuminate\Database\Eloquent\Relations\MorphMany;
13
use Illuminate\Foundation\Auth\User as Authenticatable;
14
use Illuminate\Http\Request;
15
use Illuminate\Notifications\Notifiable;
16
use Illuminate\Support\Facades\Date;
17

18
class User extends Authenticatable implements Contract
19
{
20
    use HasMedia;
21
    use HasMetaData;
22
    use InteractsWithProxy;
23
    use Notifiable;
24

25
    /**
26
     * Get the proxied interface.
27
     */
28
    public static function getProxiedInterface(): string
1✔
29
    {
30
        return Contract::class;
1✔
31
    }
32

33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function getMorphClass(): string
33✔
37
    {
38
        return static::getProxiedClass();
33✔
39
    }
40

41
    /**
42
     * Get the uploads for the user.
43
     */
44
    public function uploads(): HasMany
13✔
45
    {
46
        return $this->hasMany(Medium::getProxiedClass());
13✔
47
    }
48

49
    /**
50
     * Get the Root notifications for the user.
51
     */
52
    public function rootNotifications(): MorphMany
5✔
53
    {
54
        return $this->morphMany(Notification::getProxiedClass(), 'notifiable')->latest();
5✔
55
    }
56

57
    /**
58
     * Get the current auth code for the user.
59
     */
60
    public function authCode(): HasOne
2✔
61
    {
62
        return $this->authCodes()->one()->ofMany()->active();
2✔
63
    }
64

65
    /**
66
     * Get the auth codes for the user.
67
     */
68
    public function authCodes(): HasMany
4✔
69
    {
70
        return $this->hasMany(AuthCode::getProxiedClass())->active();
4✔
71
    }
72

73
    /**
74
     * Get the triggered root events for the user.
75
     */
76
    public function triggeredRootEvents(): HasMany
1✔
77
    {
78
        return $this->hasMany(Event::getProxiedClass());
1✔
79
    }
80

81
    /**
82
     * Determine whether the object requires two factor authentication.
83
     */
84
    public function requiresTwoFactorAuthentication(): bool
×
85
    {
86
        return false;
×
87
    }
88

89
    /**
90
     * Determine whether the user should be two factor authenticated.
91
     */
92
    public function shouldTwoFactorAuthenticate(Request $request): bool
×
93
    {
94
        if (! $this->requiresTwoFactorAuthentication()) {
×
95
            return false;
×
96
        }
97

98
        if ($request->cookie('device_token') === $this->generateDeviceToken($request)) {
×
99
            return false;
×
100
        }
101

102
        return ! $request->session()->has('root.auth.two-factor');
×
103
    }
104

105
    /**
106
     * Generate a new auth code for the user.
107
     */
108
    public function generateAuthCode(): AuthCode
2✔
109
    {
110
        $this->authCodes()->delete();
2✔
111

112
        $code = $this->authCodes()->make()->forceFill([
2✔
113
            'code' => mt_rand(100000, 999999),
2✔
114
            'expires_at' => Date::now()->addMinutes(5),
2✔
115
        ]);
2✔
116

117
        $code->save();
2✔
118

119
        return $code;
2✔
120
    }
121

122
    /**
123
     * Generate a device token.
124
     */
125
    public function generateDeviceToken(Request $request): string
×
126
    {
127
        return sha1(sprintf('%s:%s', $request->user()->getKey(), $request->user()->email));
×
128
    }
129

130
    /**
131
     * Get the avatar attribute.
132
     *
133
     * @return \Illuminate\Database\Eloquent\Casts\Attribute<string|null, never>
134
     */
135
    protected function avatar(): Attribute
12✔
136
    {
137
        return new Attribute(
12✔
138
            get: static fn (mixed $value, array $attributes): ?string => isset($attributes['email'])
12✔
139
                ? sprintf('https://www.gravatar.com/avatar/%s?d=mp', md5($attributes['email']))
11✔
140
                : null
11✔
141
        );
12✔
142
    }
143
}
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