Completed
Push — develop ( 07e415...4a7a6e )
by Abdelrahman
01:36
created

User::scopeInactive()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Fort\Models;
6
7
use Rinvex\Fort\Traits\HasRoles;
8
use Illuminate\Auth\Authenticatable;
9
use Illuminate\Support\Facades\Hash;
10
use Rinvex\Fort\Traits\CanVerifyEmail;
11
use Rinvex\Fort\Traits\CanVerifyPhone;
12
use Illuminate\Database\Eloquent\Model;
13
use Rinvex\Cacheable\CacheableEloquent;
14
use Rinvex\Fort\Contracts\UserContract;
15
use Rinvex\Support\Traits\HasHashables;
16
use Illuminate\Notifications\Notifiable;
17
use Rinvex\Fort\Traits\CanResetPassword;
18
use Illuminate\Database\Eloquent\Builder;
19
use Rinvex\Support\Traits\ValidatingTrait;
20
use Rinvex\Fort\Traits\AuthenticatableTwoFactor;
21
use Rinvex\Fort\Contracts\CanVerifyEmailContract;
22
use Rinvex\Fort\Contracts\CanVerifyPhoneContract;
23
use Illuminate\Database\Eloquent\Relations\HasMany;
24
use Illuminate\Foundation\Auth\Access\Authorizable;
25
use Rinvex\Fort\Contracts\CanResetPasswordContract;
26
use Rinvex\Fort\Contracts\AuthenticatableTwoFactorContract;
27
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
28
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
29
30
/**
31
 * Rinvex\Fort\Models\User.
32
 *
33
 * @property int                                                                                                            $id
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 127 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
34
 * @property string                                                                                                         $username
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 133 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
35
 * @property string                                                                                                         $password
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 133 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
36
 * @property string|null                                                                                                    $remember_token
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 139 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
37
 * @property string                                                                                                         $email
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 130 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
38
 * @property bool                                                                                                           $email_verified
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 139 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
39
 * @property \Carbon\Carbon                                                                                                 $email_verified_at
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 142 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
40
 * @property string                                                                                                         $phone
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 130 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
41
 * @property bool                                                                                                           $phone_verified
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 139 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
42
 * @property \Carbon\Carbon                                                                                                 $phone_verified_at
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 142 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
43
 * @property string                                                                                                         $name_prefix
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 136 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
44
 * @property string                                                                                                         $first_name
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 135 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
45
 * @property string                                                                                                         $middle_name
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 136 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
46
 * @property string                                                                                                         $last_name
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 134 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
47
 * @property string                                                                                                         $name_suffix
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 136 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
48
 * @property string                                                                                                         $job_title
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 134 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
49
 * @property string                                                                                                         $country_code
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 137 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
50
 * @property string                                                                                                         $language_code
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 138 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
51
 * @property array                                                                                                          $two_factor
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 135 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
52
 * @property string                                                                                                         $birthday
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 133 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
53
 * @property string                                                                                                         $gender
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 131 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
54
 * @property bool                                                                                                           $is_active
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 134 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
55
 * @property \Carbon\Carbon                                                                                                 $last_activity
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 138 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
56
 * @property \Carbon\Carbon|null                                                                                            $created_at
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 135 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
57
 * @property \Carbon\Carbon|null                                                                                            $updated_at
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 135 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
58
 * @property \Carbon\Carbon|null                                                                                            $deleted_at
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 135 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
59
 * @property \Illuminate\Database\Eloquent\Collection|\Rinvex\Fort\Models\Ability[]                                         $abilities
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 134 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
60
 * @property-read \Illuminate\Support\Collection                                                                            $all_abilities
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 138 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
61
 * @property-read \Rinvex\Country\Country                                                                                   $country
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 132 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
62
 * @property-read \Rinvex\Language\Language                                                                                 $language
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 133 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
63
 * @property-read string                                                                                                    $name
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 129 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
64
 * @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] $notifications
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 138 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
65
 * @property \Illuminate\Database\Eloquent\Collection|\Rinvex\Fort\Models\Role[]                                            $roles
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 130 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
66
 * @property-read \Illuminate\Database\Eloquent\Collection|\Rinvex\Fort\Models\Session[]                                    $sessions
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 133 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
67
 * @property-read \Illuminate\Database\Eloquent\Collection|\Rinvex\Fort\Models\Socialite[]                                  $socialites
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 135 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
68
 *
69
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User role($roles)
70
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereBirthday($value)
71
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereCountryCode($value)
72
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereCreatedAt($value)
73
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereDeletedAt($value)
74
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereEmail($value)
75
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereEmailVerified($value)
76
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereEmailVerifiedAt($value)
77
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereFirstName($value)
78
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereGender($value)
79
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereId($value)
80
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereIsActive($value)
81
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereJobTitle($value)
82
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereLanguageCode($value)
83
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereLastActivity($value)
84
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereLastName($value)
85
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereMiddleName($value)
86
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereNamePrefix($value)
87
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereNameSuffix($value)
88
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User wherePassword($value)
89
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User wherePhone($value)
90
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User wherePhoneVerified($value)
91
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User wherePhoneVerifiedAt($value)
92
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereRememberToken($value)
93
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereTwoFactor($value)
94
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereUpdatedAt($value)
95
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereUsername($value)
96
 * @mixin \Eloquent
97
 */
98
class User extends Model implements UserContract, AuthenticatableContract, AuthenticatableTwoFactorContract, AuthorizableContract, CanResetPasswordContract, CanVerifyEmailContract, CanVerifyPhoneContract
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 203 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
99
{
100
    use HasRoles;
101
    use Notifiable;
102
    use Authorizable;
103
    use HasHashables;
104
    use CanVerifyEmail;
105
    use CanVerifyPhone;
106
    use Authenticatable;
107
    use ValidatingTrait;
108
    use CanResetPassword;
109
    use CacheableEloquent;
110
    use AuthenticatableTwoFactor;
111
112
    /**
113
     * {@inheritdoc}
114
     */
115
    protected $fillable = [
116
        'username',
117
        'password',
118
        'two_factor',
119
        'email',
120
        'email_verified',
121
        'email_verified_at',
122
        'phone',
123
        'phone_verified',
124
        'phone_verified_at',
125
        'name_prefix',
126
        'first_name',
127
        'middle_name',
128
        'last_name',
129
        'name_suffix',
130
        'job_title',
131
        'country_code',
132
        'language_code',
133
        'birthday',
134
        'gender',
135
        'is_active',
136
        'last_activity',
137
        'abilities',
138
        'roles',
139
    ];
140
141
    /**
142
     * {@inheritdoc}
143
     */
144
    protected $casts = [
145
        'username' => 'string',
146
        'password' => 'string',
147
        'two_factor' => 'json',
148
        'email' => 'string',
149
        'email_verified' => 'boolean',
150
        'email_verified_at' => 'datetime',
151
        'phone' => 'string',
152
        'phone_verified' => 'boolean',
153
        'phone_verified_at' => 'datetime',
154
        'name_prefix' => 'string',
155
        'first_name' => 'string',
156
        'middle_name' => 'string',
157
        'last_name' => 'string',
158
        'name_suffix' => 'string',
159
        'job_title' => 'string',
160
        'country_code' => 'string',
161
        'language_code' => 'string',
162
        'birthday' => 'string',
163
        'gender' => 'string',
164
        'is_active' => 'boolean',
165
        'last_activity' => 'datetime',
166
        'deleted_at' => 'datetime',
167
    ];
168
169
    /**
170
     * {@inheritdoc}
171
     */
172
    protected $hidden = [
173
        'password',
174
        'two_factor',
175
        'remember_token',
176
    ];
177
178
    /**
179
     * {@inheritdoc}
180
     */
181
    protected $with = [
182
        'abilities',
183
        'roles',
184
    ];
185
186
    /**
187
     * {@inheritdoc}
188
     */
189
    protected $observables = [
190
        'validating',
191
        'validated',
192
    ];
193
194
    /**
195
     * The attributes to be encrypted before saving.
196
     *
197
     * @var array
198
     */
199
    protected $hashables = [
200
        'password',
201
    ];
202
203
    /**
204
     * The default rules that the model will validate against.
205
     *
206
     * @var array
207
     */
208
    protected $rules = [];
209
210
    /**
211
     * Whether the model should throw a
212
     * ValidationException if it fails validation.
213
     *
214
     * @var bool
215
     */
216
    protected $throwValidationExceptions = true;
217
218
    /**
219
     * Create a new Eloquent model instance.
220
     *
221
     * @param array $attributes
222
     */
223
    public function __construct(array $attributes = [])
224
    {
225
        parent::__construct($attributes);
226
227
        $this->setTable(config('rinvex.fort.tables.users'));
228
        $this->setRules([
229
            'username' => 'required|alpha_dash|min:3|max:150|unique:'.config('rinvex.fort.tables.users').',username',
230
            'password' => 'sometimes|required|min:'.config('rinvex.fort.password_min_chars'),
231
            'two_factor' => 'nullable|array',
232
            'email' => 'required|email|min:3|max:150|unique:'.config('rinvex.fort.tables.users').',email',
233
            'email_verified' => 'sometimes|boolean',
234
            'email_verified_at' => 'nullable|date',
235
            'phone' => 'nullable|numeric|min:4',
236
            'phone_verified' => 'sometimes|boolean',
237
            'phone_verified_at' => 'nullable|date',
238
            'name_prefix' => 'nullable|string|max:150',
239
            'first_name' => 'nullable|string|max:150',
240
            'middle_name' => 'nullable|string|max:150',
241
            'last_name' => 'nullable|string|max:150',
242
            'name_suffix' => 'nullable|string|max:150',
243
            'job_title' => 'nullable|string|max:150',
244
            'country_code' => 'nullable|alpha|size:2|country',
245
            'language_code' => 'nullable|alpha|size:2|language',
246
            'birthday' => 'nullable|date_format:Y-m-d',
247
            'gender' => 'nullable|string|in:m,f',
248
            'is_active' => 'sometimes|boolean',
249
            'last_activity' => 'nullable|date',
250
        ]);
251
    }
252
253
    /**
254
     * {@inheritdoc}
255
     */
256
    protected static function boot()
257
    {
258
        parent::boot();
259
260
        static::saving(function (self $user) {
261
            foreach (array_intersect($user->getHashables(), array_keys($user->getAttributes())) as $hashable) {
262
                if ($user->isDirty($hashable) && Hash::needsRehash($user->$hashable)) {
263
                    $user->$hashable = Hash::make($user->$hashable);
264
                }
265
            }
266
        });
267
    }
268
269
    /**
270
     * A user may have multiple direct abilities.
271
     *
272
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
273
     */
274
    public function abilities()
275
    {
276
        return $this->belongsToMany(config('rinvex.fort.models.ability'), config('rinvex.fort.tables.ability_user'), 'user_id', 'ability_id')
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 141 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
277
                    ->withTimestamps();
278
    }
279
280
    /**
281
     * A user may have multiple roles.
282
     *
283
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
284
     */
285
    public function roles()
286
    {
287
        return $this->belongsToMany(config('rinvex.fort.models.role'), config('rinvex.fort.tables.role_user'), 'user_id', 'role_id')
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 132 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
288
                    ->withTimestamps();
289
    }
290
291
    /**
292
     * A user may have many sessions.
293
     *
294
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
295
     */
296
    public function sessions(): HasMany
297
    {
298
        return $this->hasMany(config('rinvex.fort.models.session'), 'user_id', 'id');
299
    }
300
301
    /**
302
     * A user may have multiple socialites.
303
     *
304
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
305
     */
306
    public function socialites(): HasMany
307
    {
308
        return $this->hasMany(config('rinvex.fort.models.socialite'), 'user_id', 'id');
309
    }
310
311
    /**
312
     * Get name attribute.
313
     *
314
     * @return string
315
     */
316
    public function getNameAttribute()
317
    {
318
        $name = trim(implode(' ', [$this->name_prefix, $this->first_name, $this->middle_name, $this->last_name, $this->name_suffix]));
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 134 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
319
320
        return $name ?: $this->username;
321
    }
322
323
    /**
324
     * Get all abilities of the user.
325
     *
326
     * @return \Illuminate\Support\Collection
327
     */
328
    public function getAllAbilitiesAttribute()
329
    {
330
        return $this->abilities->merge($this->roles->pluck('abilities')->collapse());
331
    }
332
333
    /**
334
     * Determine if the user is super admin.
335
     *
336
     * @return bool
337
     */
338
    public function isSuperadmin()
339
    {
340
        return $this->getAllAbilitiesAttribute()->where('resource', 'global')->where('policy', null)->contains('action', 'superadmin');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 135 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
341
    }
342
343
    /**
344
     * Determine if the user is protected.
345
     *
346
     * @return bool
347
     */
348
    public function isProtected()
349
    {
350
        return in_array($this->id, config('rinvex.fort.protected.users'));
351
    }
352
353
    /**
354
     * Route notifications for the authy channel.
355
     *
356
     * @return int
357
     */
358
    public function routeNotificationForAuthy()
359
    {
360
        if (! ($authyId = array_get($this->getTwoFactor(), 'phone.authy_id')) && $this->getEmailForVerification() && $this->getPhoneForVerification() && $this->getCountryForVerification()) {
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 190 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
361
            $result = app('rinvex.authy.user')->register($this->getEmailForVerification(), preg_replace('/[^0-9]/', '', $this->getPhoneForVerification()), $this->getCountryForVerification());
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 191 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
362
            $authyId = $result->get('user')['id'];
363
364
            // Prepare required variables
365
            $twoFactor = $this->getTwoFactor();
366
367
            // Update user account
368
            array_set($twoFactor, 'phone.authy_id', $authyId);
369
370
            $this->fill(['two_factor' => $twoFactor])->forceSave();
371
        }
372
373
        return $authyId;
374
    }
375
376
    /**
377
     * Get the user's country.
378
     *
379
     * @return \Rinvex\Country\Country
380
     */
381
    public function getCountryAttribute()
382
    {
383
        return country($this->country_code);
384
    }
385
386
    /**
387
     * Get the user's language.
388
     *
389
     * @return \Rinvex\Language\Language
390
     */
391
    public function getLanguageAttribute()
392
    {
393
        return language($this->language_code);
394
    }
395
396
    /**
397
     * Attach the user roles.
398
     *
399
     * @param mixed $roles
400
     *
401
     * @return void
402
     */
403
    public function setRolesAttribute($roles)
404
    {
405
        static::saved(function (self $model) use ($roles) {
406
            $model->roles()->sync($roles);
407
        });
408
    }
409
410
    /**
411
     * Attach the user abilities.
412
     *
413
     * @param mixed $abilities
414
     *
415
     * @return void
416
     */
417
    public function setAbilitiesAttribute($abilities)
418
    {
419
        static::saved(function (self $model) use ($abilities) {
420
            $model->abilities()->sync($abilities);
421
        });
422
    }
423
424
    /**
425
     * Activate the user.
426
     *
427
     * @return $this
428
     */
429
    public function activate()
430
    {
431
        $this->update(['is_active' => true]);
432
433
        return $this;
434
    }
435
436
    /**
437
     * Deactivate the user.
438
     *
439
     * @return $this
440
     */
441
    public function deactivate()
442
    {
443
        $this->update(['is_active' => false]);
444
445
        return $this;
446
    }
447
}
448