Finished registration and e-mail verification

This commit is contained in:
Exynox 2023-07-31 08:35:40 +03:00
parent 8b5ef5211b
commit 2f230b9608
13 changed files with 283 additions and 27 deletions

View File

@ -1,9 +1,10 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request; use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Validator;
use Illuminate\View\View; use Illuminate\View\View;

View File

@ -0,0 +1,80 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Hashing\MySQLHasher;
use App\Http\Controllers\Controller;
use App\Models\Account;
use App\Models\Enums\AccountStatusEnum;
use Illuminate\Auth\Events\Registered;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
use Illuminate\View\View;
class RegisterController extends Controller
{
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Validation\Validator
*/
protected function validator(array $data): \Illuminate\Validation\Validator
{
return Validator::make($data, [
'login' => ['required', 'string', 'min:5', 'max:16', 'unique:account.account'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:account.account'],
'password' => ['required', 'string', 'min:5', 'max:16'],
'tac' => ['required'],
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return Account
*/
protected function create(array $data): Account
{
$account = new Account();
$account->login = $data['login'];
$account->email = $data['email'];
$account->password = (new MySQLHasher)->make($data['password']);
$account->status = AccountStatusEnum::NOT_AVAILABLE;
$account->saveOrFail();
return $account;
}
/**
* Show the application registration form.
*
* @return View
*/
public function showRegistrationForm(): View
{
return view('user/registration/register');
}
/**
* Handle a registration request for the application.
*
* @param Request $request
* @return RedirectResponse
* @throws ValidationException
*/
public function register(Request $request)
{
$this->validator($request->all())->validate();
event(new Registered($user = $this->create($request->all())));
Auth::guard()->login($user);
return redirect('user/verification/notice');
}
}

View File

@ -0,0 +1,69 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\VerifiesEmails;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
class VerificationController extends Controller
{
/*
|--------------------------------------------------------------------------
| Email Verification Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling email verification for any
| user that recently registered with the application. Emails may also
| be re-sent if the user didn't receive the original email message.
|
*/
use VerifiesEmails;
/**
* Where to redirect users after verification.
*
* @var string
*/
protected string $redirectTo = 'user/administration';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
$this->middleware('signed')->only('verify');
$this->middleware('throttle:6,1')->only('verify', 'resend');
}
/**
* Show the email verification notice.
*
* @param Request $request
* @return RedirectResponse|View
*/
public function show(Request $request): View|RedirectResponse
{
return $request->user()->hasVerifiedEmail()
? redirect($this->redirectPath())
: view('user/registration/verification-notice');
}
/**
* The user has been verified.
*
* @param Request $request
* @return View
*/
protected function verified(Request $request): View
{
return view('user/registration/registration-success');
}
}

View File

@ -49,7 +49,6 @@ class Account extends User implements MustVerifyEmail
*/ */
protected $fillable = [ protected $fillable = [
'login', 'login',
'password',
'email', 'email',
]; ];
@ -71,7 +70,6 @@ class Account extends User implements MustVerifyEmail
*/ */
protected $casts = [ protected $casts = [
'email_verified_at' => 'datetime', 'email_verified_at' => 'datetime',
'password' => 'hashed',
'status' => AccountStatusEnum::class 'status' => AccountStatusEnum::class
]; ];

View File

@ -226,7 +226,7 @@
</div> </div>
</div> </div>
@if (Auth::user()->status == \App\Models\Enums\AccountStatusEnum::OK) @if (Auth::user()->hasVerifiedEmail())
<div class="boxes-middle"></div> <div class="boxes-middle"></div>
<div class="modul-box modul-box-2"> <div class="modul-box modul-box-2">
<div class="modul-box-bg"> <div class="modul-box-bg">

View File

@ -10,7 +10,7 @@
<div class="securitybox"> <div class="securitybox">
<p>Scopul acestui Ghid al Comunitatii este sa creeze un mediu placut ce va face sederea in aceasta comunitate plina de distractie, unica si sigura, incurajand utilizatorii sa se comporte intr-o maniera care promoveaza integritatea, decenta si respectul. <p>Scopul acestui Ghid al Comunitatii este sa creeze un mediu placut ce va face sederea in aceasta comunitate plina de distractie, unica si sigura, incurajand utilizatorii sa se comporte intr-o maniera care promoveaza integritatea, decenta si respectul.
<br/><br/> <br/><br/>
Acest Ghid al Comunitatii va ajuta sa intelegeti ce inseamna sa faceti parte din comunitatea Metin2. Tineti minte ca prin folosirea platformelor Metin2 sunteti de acord cu Ghidul Comunitatii Metin2 si a <a href="#" target="_blank">termenilor &amp; conditiilor</a>.</p> Acest Ghid al Comunitatii va ajuta sa intelegeti ce inseamna sa faceti parte din comunitatea Metin2. Tineti minte ca prin folosirea platformelor Metin2 sunteti de acord cu Ghidul Comunitatii Metin2 si a <a href="{{ url('legal/terms') }}" target="_blank">termenilor &amp; conditiilor</a>.</p>
</div> </div>
<div class="securitybox"> <div class="securitybox">
<h4>Cateva lucruri de tinut minte atunci cand folositi platforma Metin2</h4> <h4>Cateva lucruri de tinut minte atunci cand folositi platforma Metin2</h4>

View File

@ -7,28 +7,19 @@
<div class="content-bg"> <div class="content-bg">
<div class="content-bg-bottom"> <div class="content-bg-bottom">
<h2>Înregistrarea</h2> <h2>Înregistrarea</h2>
<div id="progressTracker">
<div id="progress1" class="active"> <x-registration.progress :step="1" />
<div class="step">1</div>
<p class="progress-text">Înregistrare</p>
</div>
<div id="progress2" class="inactive">
<div class="step">2</div>
<p class="progress-text">Activează și descarcă</p>
</div>
<div id="progress3" class="inactive">
<div class="step">3</div>
<p class="progress-text">Instalează și joacă-te</p>
</div>
</div>
<div class="inner-form-border"> <div class="inner-form-border">
<div class="inner-form-box"> <div class="inner-form-box">
<h3><a id="toLogin" href="{{ url('user/login') }}" title="sau la autentificare">sau la autentificare</a>Creează un cont</h3> <h3><a id="toLogin" href="{{ url('user/login') }}" title="sau la autentificare">sau la autentificare</a>Creează un cont</h3>
<div class="trenner"></div> <div class="trenner"></div>
<form name="registerForm" id="registerForm" method="post" action="{{ url('user/register') }}"> <form name="registerForm" id="registerForm" method="post" action="{{ url('user/register') }}">
@csrf
<div> <div>
<label for="username">Nume de utilizator: *</label> <label for="username">Nume de utilizator: *</label>
<input type="text" class="validate[required,custom[noSpecialCharacters],length[5,16]]" id="username" name="username" title="" value="" maxlength="16"/> <input type="text" class="validate[required,custom[noSpecialCharacters],length[5,16]]" id="username" name="login" title="" value="" maxlength="16"/>
</div> </div>
<div> <div>
<label for="email">Email: *</label> <label for="email">Email: *</label>
@ -81,7 +72,20 @@
<span>Am citit <a href="{{ url('legal/terms') }}" target="_blank"><strong>Termenii și Condițiile</strong></a> și <a href="{{ url('legal/privacy') }}" target="_blank"><strong>Declarația privind protecția datelor</strong></a>. *</span> <span>Am citit <a href="{{ url('legal/terms') }}" target="_blank"><strong>Termenii și Condițiile</strong></a> și <a href="{{ url('legal/privacy') }}" target="_blank"><strong>Declarația privind protecția datelor</strong></a>. *</span>
</div> </div>
<input id="submitBtn" type="submit" name="SubmitRegisterForm" value="Înregistrare" class="btn-big"/> <input id="submitBtn" type="submit" name="SubmitRegisterForm" value="Înregistrare" class="btn-big"/>
<script type="text/javascript"> <script type="text/javascript">
@error('login')
$.validationEngine.buildPrompt("#username", "{{ $message }}", "error");
@enderror
@error('email')
$.validationEngine.buildPrompt("#email", "{{ $message }}", "error");
@enderror
@error('password')
$.validationEngine.buildPrompt("#password", "{{ $message }}", "error");
@enderror
@error('tac')
$.validationEngine.buildPrompt("#tac", "{{ $message }}", "error");
@enderror
</script> </script>
</form> </form>
<p id="regLegend">* este necesar</p> <p id="regLegend">* este necesar</p>

View File

@ -0,0 +1,42 @@
@extends('layouts.app')
@section('content')
<!-- center column -->
<div class="col-2" id="authenticated">
<div class="content content-last">
<div class="content-bg">
<div class="content-bg-bottom">
<h2>Contul tău</h2>
<x-registration.progress :step="3" />
<div class="pass-lost-inner-content">
<div class="input-data-box">
<div id="activateAccount" class="inner-form-border">
<div class="inner-form-box clearfix">
<h3>Ai fost înregistrat cu succes!</h3>
<div class="trenner"></div>
<div id="activateBox">
<p>
Contul tău este acum activat. Continuă prin a descărca jocul de mai jos.
Distracție plăcută!
</p>
</div>
<h3>Descarcă jocul</h3>
<div class="trenner"></div>
<a href="{{ url('main/download') }}" id="bigDownload">
Descarcă<br/>jocul acum
</a>
</div>
</div>
</div>
<div class="box-foot"></div>
</div>
</div>
</div>
</div>
<div class="shadow">&nbsp;</div>
</div>
@endsection

View File

@ -0,0 +1,59 @@
@extends('layouts.app')
@section('content')
<!-- center column -->
<div class="col-2" id="authenticated">
<div class="content content-last">
<div class="content-bg">
<div class="content-bg-bottom">
<h2>Contul tău</h2>
<x-registration.progress :step="2" />
<div class="pass-lost-inner-content">
<div class="input-data-box">
<div id="activateAccount" class="inner-form-border">
<div class="inner-form-box clearfix">
<h3>Activează-ți contul!</h3>
<div class="trenner"></div>
<div id="activateBox">
<p>
Pentru finalizarea înregistrării tale, trebuie îți verificăm adresa
de e-mail. Accesează-ți căsuța de e-mail și urmează link-ul din mesaj pentru activare.
</p>
<h3>Nu ai primit un e-mail?</h3>
<div class="trenner"></div>
@if (session('resent'))
<p style="color: #003100;"><strong>Un nou e-mail de verificare a fost trimis!</strong></p>
@endif
<p id="resendNormal">
Te rugăm aștepți câteva minute pentru a primi e-mail-ul de activare.
Totodată, nu uita verifici folderele Spam / Junk. În cazul în care
încă nu primești mesajul, poți solicita retrimiterea acestuia.
<br /><br />
<a href="{{ route('verification.resend') }}">
Retrimite mailul de activare
</a>
</p>
</div>
<h3>Descarcă jocul</h3>
<div class="trenner"></div>
<a href="{{ url('main/download') }}" id="bigDownload">
Descarcă<br/>jocul acum
</a>
</div>
</div>
</div>
<div class="box-foot"></div>
</div>
</div>
</div>
</div>
<div class="shadow">&nbsp;</div>
</div>
@endsection

View File

@ -1,6 +1,8 @@
<?php <?php
use App\Http\Controllers\LoginController; use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\Auth\RegisterController;
use App\Http\Controllers\Auth\VerificationController;
use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
@ -50,22 +52,23 @@ Route::prefix('main')->group(function() {
Route::prefix('user')->group(function() { Route::prefix('user')->group(function() {
# Registration # Registration
Route::get('/register', fn () => view('user/registration/register'))->middleware('guest'); Route::get('/register', [RegisterController::class, 'showRegistrationForm'])->middleware('guest');
Route::get('/activate', fn () => view('user/registration/activation-pending'))->name('verification.notice'); Route::post('/register', [RegisterController::class, 'register'])->middleware('guest');
Route::get('/resendack', fn () => view('user/registration/resendack')); Route::get('/verification/notice', [VerificationController::class, 'show'])->name('verification.notice');
Route::get('/verification/verify/{id}/{hash}', [VerificationController::class, 'verify'])->name('verification.verify');
Route::get('/verification/resend', [VerificationController::class, 'resend'])->name('verification.resend');
# Authentication # Authentication
Route::middleware('guest')->group(function() { Route::middleware('guest')->group(function() {
Route::get('/login', fn () => view('user/login'))->name('login'); Route::get('/login', fn () => view('user/login'))->name('login');
Route::post('/login', [LoginController::class, 'login']); Route::post('/login', [LoginController::class, 'login']);
// will autocomplete the username
Route::get('/login/{username}', fn ($username) => view('user/login'));
}); });
Route::get('/logout', [LoginController::class, 'logout']); Route::get('/logout', [LoginController::class, 'logout']);
Route::get('/passwordlostrequest', fn () => view('user/passwordlostrequest')); Route::get('/passwordlostrequest', fn () => view('user/passwordlostrequest'));
Route::get('/passwordlost/{username}/{hash}', fn ($username, $hash) => view('user/passwordlost-expired')); Route::get('/passwordlost/{username}/{hash}', fn ($username, $hash) => view('user/passwordlost-expired'));
# User administration
Route::middleware(['auth', 'verified'])->group(function() { Route::middleware(['auth', 'verified'])->group(function() {
Route::get('/administration', fn () => view('user/administration')); Route::get('/administration', fn () => view('user/administration'));