1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 21:52:35 +01:00
invoiceninja/app/Http/Controllers/Traits/VerifiesUserEmail.php

91 lines
2.7 KiB
PHP
Raw Normal View History

<?php
2019-05-11 05:32:07 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
2019-05-11 05:32:07 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. 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
*/
namespace App\Http\Controllers\Traits;
use App\Models\User;
2021-04-08 06:35:02 +02:00
use App\Utils\Traits\MakesHash;
use App\Utils\Traits\UserSessionAttributes;
2020-10-28 11:10:49 +01:00
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
2019-01-27 00:22:57 +01:00
/**
* Class VerifiesUserEmail.
2019-01-27 00:22:57 +01:00
*/
trait VerifiesUserEmail
{
use UserSessionAttributes;
2021-04-08 06:35:02 +02:00
use MakesHash;
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()
{
$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)) {
2021-04-21 05:54:10 +02:00
return $this->render('auth.confirmed', [
'root' => 'themes',
'message' => ctrans('texts.security_confirmation'),
]);
}
2021-04-08 06:35:02 +02:00
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()
{
2021-04-08 06:35:02 +02:00
$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'),
2023-06-04 08:46:59 +02:00
'redirect_url' => request()->hasHeader('X-React') ? 'https://app.invoicing.co/#/' : url('/'),
]);
}
}