1 | <?php namespace JobApis\JobsToMail\Repositories; |
||
8 | class UserRepository implements Contracts\UserRepositoryInterface |
||
9 | { |
||
10 | /** |
||
11 | * @var Token model |
||
12 | */ |
||
13 | public $tokens; |
||
14 | |||
15 | /** |
||
16 | * @var User model |
||
17 | */ |
||
18 | public $users; |
||
19 | |||
20 | /** |
||
21 | * UserRepository constructor. |
||
22 | * |
||
23 | * @param $model User |
||
24 | */ |
||
25 | 11 | public function __construct(User $users, Token $tokens) |
|
30 | |||
31 | /** |
||
32 | * Confirms a user if unconfirmed. |
||
33 | * |
||
34 | * @param $user User |
||
35 | * |
||
36 | * @return boolean |
||
37 | */ |
||
38 | 2 | public function confirm(User $user) |
|
47 | |||
48 | /** |
||
49 | * Creates a single new user, generate a token and notify the user. |
||
50 | * |
||
51 | * @param $data array |
||
52 | * |
||
53 | * @return \JobApis\JobsToMail\Models\User |
||
54 | */ |
||
55 | 2 | public function create($data = []) |
|
63 | |||
64 | /** |
||
65 | * Deletes a user. |
||
66 | * |
||
67 | * @param $id string |
||
68 | * |
||
69 | * @return boolean |
||
70 | */ |
||
71 | 1 | public function delete($id = null) |
|
75 | |||
76 | /** |
||
77 | * Creates a single new user or returns an existing one by email |
||
78 | * |
||
79 | * @param $data array |
||
80 | * |
||
81 | * @return \JobApis\JobsToMail\Models\User |
||
82 | */ |
||
83 | 3 | public function firstOrCreate($data = []) |
|
95 | |||
96 | /** |
||
97 | * Deletes a user's old tokens and generates a new one |
||
98 | * |
||
99 | * @param null $user_id |
||
100 | * @param string $type |
||
101 | * |
||
102 | * @return Token |
||
103 | */ |
||
104 | 3 | public function generateToken($user_id = null, $type = 'confirm') |
|
112 | |||
113 | /** |
||
114 | * Retrieves a single record by ID |
||
115 | * |
||
116 | * @param $id string |
||
117 | * @param $options array |
||
118 | * |
||
119 | * @return \JobApis\JobsToMail\Models\User |
||
120 | */ |
||
121 | 1 | public function getById($id = null, $options = []) |
|
125 | |||
126 | /** |
||
127 | * Retrieves a single record by Email |
||
128 | * |
||
129 | * @param $email string |
||
130 | * @param $options array |
||
131 | * |
||
132 | * @return \JobApis\JobsToMail\Models\User |
||
133 | */ |
||
134 | 1 | public function getByEmail($email = null, $options = []) |
|
138 | |||
139 | /** |
||
140 | * Get Confirmation Token by token id if not expired |
||
141 | * |
||
142 | * @param string $token |
||
143 | * |
||
144 | * @return mixed |
||
145 | */ |
||
146 | 1 | public function getToken($token = null, $daysToExpire = 7) |
|
153 | |||
154 | /** |
||
155 | * Update a single user |
||
156 | * |
||
157 | * @param $id string |
||
158 | * @param $data array |
||
159 | * |
||
160 | * @return boolean |
||
161 | */ |
||
162 | 2 | public function update($id = null, $data = []) |
|
166 | |||
167 | /** |
||
168 | * Generates a new confirmation token and sends it to the user |
||
169 | * |
||
170 | * @param User $user |
||
171 | * |
||
172 | * @return Token |
||
173 | */ |
||
174 | 3 | private function sendConfirmationToken(User $user) |
|
183 | } |
||
184 |