2018-10-24 12:24:09 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Traits;
|
|
|
|
|
|
|
|
use App\Models\User;
|
2018-11-03 02:01:40 +01:00
|
|
|
use App\Utils\Traits\UserSessionAttributes;
|
2018-10-29 04:16:17 +01:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2018-10-24 12:24:09 +02:00
|
|
|
|
|
|
|
trait VerifiesUserEmail
|
|
|
|
{
|
2018-11-03 02:01:40 +01:00
|
|
|
use UserSessionAttributes;
|
2018-10-24 12:24:09 +02:00
|
|
|
|
|
|
|
public function confirm($code)
|
|
|
|
{
|
|
|
|
$user = User::where('confirmation_code', $code)->first();
|
|
|
|
|
|
|
|
if ($user) {
|
|
|
|
|
|
|
|
$user->email_verified_at = now();
|
|
|
|
$user->confirmation_code = null;
|
|
|
|
$user->save();
|
|
|
|
|
2018-11-03 02:01:40 +01:00
|
|
|
$this->setCurrentCompanyId($user->companies()->first()->account->default_company_id);
|
|
|
|
|
2018-10-29 04:16:17 +01:00
|
|
|
Auth::loginUsingId($user->id, true);
|
|
|
|
|
2018-11-02 11:54:46 +01:00
|
|
|
return redirect()->route('dashboard.index')->with('message', trans('texts.security_confirmation'));
|
2018-10-24 12:24:09 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-10-29 04:16:17 +01:00
|
|
|
return redirect()->route('login')->with('message', trans('texts.wrong_confirmation'));
|
2018-10-24 12:24:09 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|