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

78 lines
2.1 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
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
2019-05-11 05:32:07 +02:00
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Controllers\Traits;
use App\Models\User;
use App\Utils\Traits\UserSessionAttributes;
2020-10-28 11:10:49 +01:00
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Hash;
2019-01-27 00:22:57 +01:00
/**
* Class VerifiesUserEmail.
2019-01-27 00:22:57 +01:00
*/
trait VerifiesUserEmail
{
use UserSessionAttributes;
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 = User::whereRaw("BINARY `confirmation_code`= ?", request()->input('confirmation_code'))->first()) {
if (! $user) {
return $this->render('auth.confirmed', ['root' => 'themes', 'message' => ctrans('texts.wrong_confirmation')]);
}
if (is_null($user->password) || empty($user->password)) {
return $this->render('auth.confirmation_with_password', ['root' => 'themes']);
}
$user->email_verified_at = now();
$user->confirmation_code = null;
$user->save();
return $this->render('auth.confirmed', [
'root' => 'themes',
'message' => ctrans('texts.security_confirmation'),
]);
}
public function confirmWithPassword()
{
$user = User::where('confirmation_code', request()->confirmation_code)->first();
if (! $user) {
return $this->render('auth.confirmed', ['root' => 'themes', 'message' => ctrans('texts.wrong_confirmation')]);
}
request()->validate([
'password' => ['required', 'min:6', 'confirmed'],
]);
$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'),
]);
}
}