]> BookStack Code Mirror - bookstack/blob - app/Access/ExternalBaseUserProvider.php
Thumbnails: Fixed thumnail orientation
[bookstack] / app / Access / ExternalBaseUserProvider.php
1 <?php
2
3 namespace BookStack\Access;
4
5 use Illuminate\Contracts\Auth\Authenticatable;
6 use Illuminate\Contracts\Auth\UserProvider;
7 use Illuminate\Database\Eloquent\Model;
8
9 class ExternalBaseUserProvider implements UserProvider
10 {
11     /**
12      * The user model.
13      *
14      * @var string
15      */
16     protected $model;
17
18     /**
19      * LdapUserProvider constructor.
20      */
21     public function __construct(string $model)
22     {
23         $this->model = $model;
24     }
25
26     /**
27      * Create a new instance of the model.
28      *
29      * @return Model
30      */
31     public function createModel()
32     {
33         $class = '\\' . ltrim($this->model, '\\');
34
35         return new $class();
36     }
37
38     /**
39      * Retrieve a user by their unique identifier.
40      *
41      * @param mixed $identifier
42      *
43      * @return Authenticatable|null
44      */
45     public function retrieveById($identifier)
46     {
47         return $this->createModel()->newQuery()->find($identifier);
48     }
49
50     /**
51      * Retrieve a user by their unique identifier and "remember me" token.
52      *
53      * @param mixed  $identifier
54      * @param string $token
55      *
56      * @return Authenticatable|null
57      */
58     public function retrieveByToken($identifier, $token)
59     {
60         return null;
61     }
62
63     /**
64      * Update the "remember me" token for the given user in storage.
65      *
66      * @param Authenticatable $user
67      * @param string          $token
68      *
69      * @return void
70      */
71     public function updateRememberToken(Authenticatable $user, $token)
72     {
73         //
74     }
75
76     /**
77      * Retrieve a user by the given credentials.
78      *
79      * @param array $credentials
80      *
81      * @return Authenticatable|null
82      */
83     public function retrieveByCredentials(array $credentials)
84     {
85         // Search current user base by looking up a uid
86         $model = $this->createModel();
87
88         return $model->newQuery()
89             ->where('external_auth_id', $credentials['external_auth_id'])
90             ->first();
91     }
92
93     /**
94      * Validate a user against the given credentials.
95      *
96      * @param Authenticatable $user
97      * @param array           $credentials
98      *
99      * @return bool
100      */
101     public function validateCredentials(Authenticatable $user, array $credentials)
102     {
103         // Should be done in the guard.
104         return false;
105     }
106 }