mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-25 05:09:24 -04:00 
			
		
		
		
	
		
			
				
	
	
		
			90 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			90 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| /**
 | |
|  * Invoice Ninja (https://invoiceninja.com).
 | |
|  *
 | |
|  * @link https://github.com/invoiceninja/invoiceninja source repository
 | |
|  *
 | |
|  * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
 | |
|  *
 | |
|  * @license https://www.elastic.co/licensing/elastic-license
 | |
|  */
 | |
| 
 | |
| namespace App\Http\Controllers\Traits;
 | |
| 
 | |
| use App\Models\User;
 | |
| use App\Utils\Traits\MakesHash;
 | |
| use App\Utils\Traits\UserSessionAttributes;
 | |
| use Illuminate\Http\RedirectResponse;
 | |
| use Illuminate\Support\Facades\Hash;
 | |
| use Illuminate\Support\Facades\Validator;
 | |
| 
 | |
| /**
 | |
|  * Class VerifiesUserEmail.
 | |
|  */
 | |
| trait VerifiesUserEmail
 | |
| {
 | |
|     use UserSessionAttributes;
 | |
|     use MakesHash;
 | |
| 
 | |
|     /**
 | |
|      * @return RedirectResponse
 | |
|      */
 | |
|     public function confirm()
 | |
|     {
 | |
|         $user = User::where('confirmation_code', request()->confirmation_code)->first();
 | |
| 
 | |
|         if (! $user) {
 | |
|             return $this->render('auth.confirmed', ['root' => 'themes', 'message' => ctrans('texts.wrong_confirmation')]);
 | |
|         }
 | |
| 
 | |
|         $user->email_verified_at = now();
 | |
|         // $user->confirmation_code = null; //this prevented the form from showing validation errors.
 | |
|         $user->save();
 | |
| 
 | |
|         if (isset($user->oauth_user_id)) {
 | |
|             return $this->render('auth.confirmed', [
 | |
|                 'root' => 'themes',
 | |
|                 'message' => ctrans('texts.security_confirmation'),
 | |
|             ]);
 | |
|         }
 | |
| 
 | |
|         if (is_null($user->password) || empty($user->password) || Hash::check('', $user->password)) {
 | |
|             return $this->render('auth.confirmation_with_password', ['root' => 'themes', 'user_id' => $user->hashed_id]);
 | |
|         }
 | |
| 
 | |
|         return $this->render('auth.confirmed', [
 | |
|             'root' => 'themes',
 | |
|             'message' => ctrans('texts.security_confirmation'),
 | |
|         ]);
 | |
|     }
 | |
| 
 | |
|     public function confirmWithPassword()
 | |
|     {
 | |
|         $user = User::where('id', $this->decodePrimaryKey(request()->user_id))->firstOrFail();
 | |
| 
 | |
|         $validator = Validator::make(request()->all(), [
 | |
|             //'password' => ['required', 'min:6'],
 | |
|             'password' => 'min:6|required_with:password_confirmation|same:password_confirmation',
 | |
|             'password_confirmation' => 'min:6'
 | |
|         ]);
 | |
| 
 | |
|         if ($validator->fails()) {
 | |
|             return back()
 | |
|                         ->withErrors($validator)
 | |
|                         ->withInput();
 | |
|         }
 | |
| 
 | |
|         $user->password = Hash::make(request()->password);
 | |
| 
 | |
|         $user->email_verified_at = now();
 | |
|         $user->confirmation_code = null;
 | |
|         $user->save();
 | |
| 
 | |
|         return $this->render('auth.confirmed', [
 | |
|             'root' => 'themes',
 | |
|             'message' => ctrans('texts.security_confirmation'),
 | |
|         ]);
 | |
|     }
 | |
| }
 |