2018-10-24 12:24:09 +02:00
|
|
|
<?php
|
2020-05-19 14:59:44 +02:00
|
|
|
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2024-04-12 06:15:41 +02:00
|
|
|
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2019-05-11 05:32:07 +02:00
|
|
|
*/
|
2018-10-24 12:24:09 +02:00
|
|
|
|
|
|
|
namespace App\Http\Controllers\Traits;
|
|
|
|
|
|
|
|
use App\Models\User;
|
2021-04-08 06:35:02 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2018-11-03 02:01:40 +01:00
|
|
|
use App\Utils\Traits\UserSessionAttributes;
|
2020-10-28 11:10:49 +01:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
2020-06-26 14:20:45 +02:00
|
|
|
use Illuminate\Support\Facades\Hash;
|
2022-08-10 23:50:45 +02:00
|
|
|
use Illuminate\Support\Facades\Validator;
|
2018-10-24 12:24:09 +02:00
|
|
|
|
2019-01-27 00:22:57 +01:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Class VerifiesUserEmail.
|
2019-01-27 00:22:57 +01:00
|
|
|
*/
|
2018-10-24 12:24:09 +02:00
|
|
|
trait VerifiesUserEmail
|
|
|
|
{
|
2018-11-03 02:01:40 +01:00
|
|
|
use UserSessionAttributes;
|
2021-04-08 06:35:02 +02:00
|
|
|
use MakesHash;
|
2018-10-24 12:24:09 +02:00
|
|
|
|
2019-01-27 00:22:57 +01:00
|
|
|
/**
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return RedirectResponse
|
2019-01-27 00:22:57 +01:00
|
|
|
*/
|
2020-03-11 00:40:10 +01:00
|
|
|
public function confirm()
|
2018-10-24 12:24:09 +02:00
|
|
|
{
|
2020-06-26 14:20:45 +02:00
|
|
|
$user = User::where('confirmation_code', request()->confirmation_code)->first();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
|
|
|
if (! $user) {
|
2023-06-11 08:43:04 +02:00
|
|
|
return $this->render('auth.confirmed', [
|
2023-10-26 04:57:44 +02:00
|
|
|
'root' => 'themes',
|
2023-06-11 08:43:04 +02:00
|
|
|
'message' => ctrans('texts.wrong_confirmation'),
|
2023-06-11 08:45:40 +02:00
|
|
|
'redirect_url' => request()->has('react') ? config('ninja.react_url')."/#/" : url('/')]);
|
2020-06-26 14:20:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$user->email_verified_at = now();
|
|
|
|
$user->save();
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if (isset($user->oauth_user_id)) {
|
2021-04-21 05:54:10 +02:00
|
|
|
return $this->render('auth.confirmed', [
|
|
|
|
'root' => 'themes',
|
|
|
|
'message' => ctrans('texts.security_confirmation'),
|
2023-06-11 08:45:40 +02:00
|
|
|
'redirect_url' => request()->has('react') ? config('ninja.react_url')."/#/" : url('/'),
|
2021-04-21 05:54:10 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2021-04-08 06:35:02 +02:00
|
|
|
if (is_null($user->password) || empty($user->password) || Hash::check('', $user->password)) {
|
2023-06-11 08:45:40 +02:00
|
|
|
return $this->render('auth.confirmation_with_password', ['root' => 'themes', 'user_id' => $user->hashed_id, 'redirect_url' => request()->has('react') ? config('ninja.react_url')."/#/" : url('/')]);
|
2021-04-08 06:35:02 +02:00
|
|
|
}
|
|
|
|
|
2020-06-26 14:20:45 +02:00
|
|
|
return $this->render('auth.confirmed', [
|
|
|
|
'root' => 'themes',
|
|
|
|
'message' => ctrans('texts.security_confirmation'),
|
2023-06-11 08:45:40 +02:00
|
|
|
'redirect_url' => request()->has('react') ? config('ninja.react_url')."/#/" : url('/'),
|
2020-06-26 14:20:45 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function confirmWithPassword()
|
|
|
|
{
|
2021-04-08 06:35:02 +02:00
|
|
|
$user = User::where('id', $this->decodePrimaryKey(request()->user_id))->firstOrFail();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2022-08-10 23:50:45 +02:00
|
|
|
$validator = Validator::make(request()->all(), [
|
2022-08-10 23:36:16 +02:00
|
|
|
'password' => 'min:6|required_with:password_confirmation|same:password_confirmation',
|
|
|
|
'password_confirmation' => 'min:6'
|
2020-06-26 14:20:45 +02:00
|
|
|
]);
|
|
|
|
|
2022-08-10 23:50:45 +02:00
|
|
|
if ($validator->fails()) {
|
|
|
|
return back()
|
|
|
|
->withErrors($validator)
|
|
|
|
->withInput();
|
|
|
|
}
|
|
|
|
|
2020-06-26 14:20:45 +02:00
|
|
|
$user->password = Hash::make(request()->password);
|
|
|
|
|
|
|
|
$user->email_verified_at = now();
|
|
|
|
$user->confirmation_code = null;
|
|
|
|
$user->save();
|
2018-10-24 12:24:09 +02:00
|
|
|
|
2020-05-19 14:59:44 +02:00
|
|
|
return $this->render('auth.confirmed', [
|
|
|
|
'root' => 'themes',
|
2020-06-26 14:20:45 +02:00
|
|
|
'message' => ctrans('texts.security_confirmation'),
|
2023-06-11 08:45:40 +02:00
|
|
|
'redirect_url' => request()->has('react') ? config('ninja.react_url')."/#/" : url('/'),
|
2020-05-19 14:59:44 +02:00
|
|
|
]);
|
2018-10-24 12:24:09 +02:00
|
|
|
}
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|