/
LoginProvider.php
58 lines (47 loc) · 1.32 KB
/
LoginProvider.php
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\User;
use Flarum\Database\AbstractModel;
/**
* @property int $id
* @property int $user_id
* @property string $provider
* @property string $identifier
* @property \Illuminate\Support\Carbon $created_at
* @property \Illuminate\Support\Carbon $last_login_at
* @property-read User $user
*/
class LoginProvider extends AbstractModel
{
protected $dates = ['created_at', 'last_login_at'];
public $timestamps = true;
const UPDATED_AT = 'last_login_at';
protected $fillable = ['provider', 'identifier'];
/**
* Get the user that the login provider belongs to.
*/
public function user()
{
return $this->belongsTo(User::class);
}
/**
* Get the user associated with the provider so that they can be logged in.
*
* @param string $provider
* @param string $identifier
* @return User|null
*/
public static function logIn(string $provider, string $identifier): ?User
{
if ($provider = static::where(compact('provider', 'identifier'))->first()) {
$provider->touch();
return $provider->user;
}
return null;
}
}