| Conditions | 2 |
| Paths | 2 |
| Total Lines | 23 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 32 | public function run(User $user) |
||
| 33 | { |
||
| 34 | // check if email exist on the user |
||
| 35 | if (!$user->email) { |
||
| 36 | throw new UserEmailNotFoundException; |
||
| 37 | } |
||
| 38 | |||
| 39 | // generate random unique token |
||
| 40 | $confirmationCode = sha1(time() . $user->id); |
||
| 41 | |||
| 42 | // 3. set token next to user id in the memory (redis) |
||
| 43 | Cache::put('user:email-confirmation-code:' . $user->id, $confirmationCode, |
||
| 44 | self::CONFIRMATION_CODE_VALIDATE_TIME); |
||
| 45 | |||
| 46 | // set user status not confirmed (in case the user is updating his email) |
||
| 47 | $user->confirmed = false; |
||
| 48 | $user->save(); |
||
| 49 | |||
| 50 | // build the url email confirmation URL with the confirmation code and user id |
||
| 51 | $confirmationUrl = URL::to('/') . '/users/' . $user->id . '/email/confirmation/' . $confirmationCode; |
||
| 52 | |||
| 53 | return $confirmationUrl; |
||
| 54 | } |
||
| 55 | } |
||
| 56 |