Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#4 - Login + reset password #20

Merged
merged 36 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
fa6ed85
Add migration for schools_table and modify users_table
PrabuckiDominik Aug 8, 2024
5fcd938
Add migration for schools_table and modify users_table
PrabuckiDominik Aug 8, 2024
cbb1f7c
Add:
PrabuckiDominik Aug 9, 2024
687b8d3
Fix code style
PrabuckiDominik Aug 9, 2024
13ed6bf
Add tests and SchoolFactory
PrabuckiDominik Aug 9, 2024
a12b833
Mail Verification
PrabuckiDominik Aug 12, 2024
5370de1
Test Mail
PrabuckiDominik Aug 12, 2024
89ab832
Add EmailVerifyController
PrabuckiDominik Aug 13, 2024
39ef29e
Improve DatabaseSeeder and Factories
PrabuckiDominik Aug 13, 2024
f5c1e6b
Fix RegisterUserController
PrabuckiDominik Aug 13, 2024
47dddf2
Increase bcrypt round to 12
PrabuckiDominik Aug 13, 2024
ac65257
Add .vue for Forgot-Password
PrabuckiDominik Aug 13, 2024
3fdd083
Code style fix
PrabuckiDominik Aug 13, 2024
9e87e2c
Add reset password
PrabuckiDominik Aug 13, 2024
276e7f3
Add tests for reset password
PrabuckiDominik Aug 13, 2024
2f9ae64
Merge branch 'main' of https://github.com/blumilksoftware/interns2024…
PrabuckiDominik Aug 13, 2024
f742250
fix code style
PrabuckiDominik Aug 13, 2024
d8815a6
Add validation errors and messages
PrabuckiDominik Aug 14, 2024
ee5cab6
Add validation translation files
PrabuckiDominik Aug 19, 2024
f52cabf
Fix email error message for existing email addresses
PrabuckiDominik Aug 19, 2024
12d2c02
Merge branch 'main' of https://github.com/blumilksoftware/interns2024…
PrabuckiDominik Aug 19, 2024
231188e
Link frontend with backend
PrabuckiDominik Aug 19, 2024
cb569ba
Pack routes into group middleware
PrabuckiDominik Aug 20, 2024
b45bd2d
Remove empty spaces
PrabuckiDominik Aug 20, 2024
ff649cf
Rename zipCode to zip_code
PrabuckiDominik Aug 20, 2024
cdf719a
Remove app_locale from .env.example
PrabuckiDominik Aug 20, 2024
804f0db
Move some logic into if in RegisterUserController
PrabuckiDominik Aug 20, 2024
a48af86
Remove dead code
PrabuckiDominik Aug 20, 2024
8d5243f
Fix code style
PrabuckiDominik Aug 20, 2024
a2c597d
Change redirect to home after password reset
PrabuckiDominik Aug 20, 2024
e4e4aea
Update redirect path in ResetPasswordTest
PrabuckiDominik Aug 20, 2024
6cdcd7e
Fix return message in forgot password
PrabuckiDominik Aug 20, 2024
658c3a0
Add:
PrabuckiDominik Aug 20, 2024
51d8db6
Merge branch 'main' of https://github.com/blumilksoftware/interns2024…
PrabuckiDominik Aug 20, 2024
0a07083
Remove : APP_FALLBACK_LOCALE and APP_FAKER_LOCALE from .env.example
PrabuckiDominik Aug 20, 2024
004e4a9
Add attribute required to checkbox
PrabuckiDominik Aug 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions app/Http/Controllers/AuthenticateSessionController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use App\Http\Requests\Auth\AuthenticateSessionRequest;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Validation\ValidationException;
use Inertia\Inertia;
use Inertia\Response;

class AuthenticateSessionController extends Controller
{
public function create(): Response
{
return Inertia::render("Auth/Login");
}

/**
* @throws ValidationException
*/
public function authenticate(AuthenticateSessionRequest $request): RedirectResponse
{
$credentials = $request->only("email", "password");

if (auth()->attempt($credentials)) {
$request->session()->regenerate();

return Redirect::route("home")->with("success");
}

throw ValidationException::withMessages([
"email" => "Wrong email or password",
]);
}

public function logout(): RedirectResponse
{
auth()->logout();

request()->session()->invalidate();
request()->session()->regenerateToken();

return Redirect::route("home")->with("success");
}
}
16 changes: 16 additions & 0 deletions app/Http/Controllers/ContestController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use Inertia\Inertia;
use Inertia\Response;

class ContestController extends Controller
{
public function index(): Response
{
return Inertia::render("Welcome");
}
}
34 changes: 34 additions & 0 deletions app/Http/Controllers/EmailVerifyController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\EmailVerificationRequest;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
use Inertia\Inertia;
use Inertia\Response;

class EmailVerifyController extends Controller
{
public function __invoke(EmailVerificationRequest $request): RedirectResponse
{
$request->fulfill();

return Redirect::route("home");
}

public function create(): Response
{
return Inertia::render("Auth/Verify-Email");
}

public function send(Request $request): RedirectResponse
{
$request->user()->sendEmailVerificationNotification();

return back()->with("message", "Verification link sent!");
}
}
62 changes: 62 additions & 0 deletions app/Http/Controllers/PasswordResetLinkController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use App\Http\Requests\Auth\ForgotPasswordRequest;
use App\Http\Requests\Auth\ResetPasswordRequest;
use App\Models\User;
use Illuminate\Auth\Events\PasswordReset;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Password;
use Illuminate\Support\Str;
use Inertia\Inertia;
use Inertia\Response;

class PasswordResetLinkController extends Controller
{
public function create(): Response
{
return Inertia::render("Auth/Forgot-Password");
kamilpiech97 marked this conversation as resolved.
Show resolved Hide resolved
}

public function store(ForgotPasswordRequest $request): RedirectResponse
{
$request->only("email");

$status = Password::sendResetLink(
$request->only("email"),
);

return $status === Password::RESET_LINK_SENT
? back()->with(["status" => __($status)])
: back()->withErrors(["email" => __($status)]);
}

public function resetCreate(string $token): Response
{
return Inertia::render("Auth/Reset-Password", ["token" => $token]);
kamilpiech97 marked this conversation as resolved.
Show resolved Hide resolved
}

public function resetStore(ResetPasswordRequest $request): RedirectResponse
{
$status = Password::reset(
$request->only("email", "password", "password_confirmation", "token"),
function (User $user, string $password): void {
$user->forceFill([
"password" => Hash::make($password),
])->setRememberToken(Str::random(60));

$user->save();

event(new PasswordReset($user));
},
);

return $status === Password::PASSWORD_RESET
? redirect()->route("login")->with("status", __($status))
: back()->withErrors(["email" => [__($status)]]);
}
}
35 changes: 35 additions & 0 deletions app/Http/Controllers/RegisterUserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use App\Http\Requests\Auth\RegisterUserRequest;
use App\Models\User;
use Illuminate\Auth\Events\Registered;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Redirect;
use Inertia\Inertia;
use Inertia\Response;

class RegisterUserController extends Controller
{
public function create(): Response
{
return Inertia::render("Auth/Register");
}

public function store(RegisterUserRequest $request): RedirectResponse
{
$user = new User($request->validated());
$user->password = Hash::make($request->password);
kamilpiech97 marked this conversation as resolved.
Show resolved Hide resolved
$user->save();

event(new Registered($user));
Auth::login($user);

return Redirect::route("home");
}
}
43 changes: 43 additions & 0 deletions app/Http/Requests/Auth/AuthenticateSessionRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace App\Http\Requests\Auth;

use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;

class AuthenticateSessionRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}

/**
* @return array<string, ValidationRule|array|string>
*/
public function rules(): array
{
return [
"email" => "required|email|max:255",
"password" => "required|string",
kamilpiech97 marked this conversation as resolved.
Show resolved Hide resolved
];
}

public function messages(): array
{
return [
"email" => [
"required" => "The email field is required.",
"max" => "Your email is too long. It must not be greater than 255 characters.",
"unique" => "The email has already been taken.",
"email" => "Your email is invalid.",
],

"password" => [
"required" => "The password field is required.",
],
kamilpiech97 marked this conversation as resolved.
Show resolved Hide resolved
];
}
}
37 changes: 37 additions & 0 deletions app/Http/Requests/Auth/ForgotPasswordRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace App\Http\Requests\Auth;

use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;

class ForgotPasswordRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}

/**
* @return array<string, ValidationRule|array|string>
*/
public function rules(): array
{
return [
"email" => "required|string|email:dns|max:255",
];
}

public function messages(): array
{
return [
"email" => [
"required" => "The email field is required.",
"max" => "Your email is too long. It must not be greater than 255 characters.",
"email" => "Your email is invalid.",
],
];
kamilpiech97 marked this conversation as resolved.
Show resolved Hide resolved
}
}
59 changes: 59 additions & 0 deletions app/Http/Requests/Auth/RegisterUserRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

namespace App\Http\Requests\Auth;

use App\Models\User;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;

class RegisterUserRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}

/**
* @return array<string, ValidationRule|array|string>
*/
public function rules(): array
{
return [
"email" => "required|string|email:rfc,dns|max:255|unique:" . User::class,
"name" => "required|string|max:255",
"surname" => "required|string|max:255",
"password" => "required|string|min:8",
"school_id" => "required|integer|exists:schools,id",
];
}

public function messages(): array
{
return [
"email" => [
"required" => "The email field is required.",
"max" => "Your email is too long. It must not be greater than 255 characters.",
"unique" => "The email has already been taken.",
"email" => "Your email is invalid.",
],
"name" => [
"required" => "The name field is required",
"max" => "Your name is too long. It must not be greater than 255 characters.",
],
"surname" => [
"required" => "The surname field is required",
"max" => "Your surname is too long. It must not be greater than 255 characters.",
],
"password" => [
"required" => "The password field is required.",
"min" => "Your password is too short. It must be at least 8 characters.",
],
"school_id" => [
"required" => "The school field is required.",
"exists" => "Your school is invalid. Check it again.",
],
];
kamilpiech97 marked this conversation as resolved.
Show resolved Hide resolved
}
}
47 changes: 47 additions & 0 deletions app/Http/Requests/Auth/ResetPasswordRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace App\Http\Requests\Auth;

use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;

class ResetPasswordRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}

/**
* @return array<string, ValidationRule|array|string>
*/
public function rules(): array
{
return [
"token" => "required",
"email" => "required|email|max:255",
"password" => "required|min:8|confirmed:password_confirmation",
];
}

public function messages(): array
{
return [
"token" => [
"required" => "The token field is required.",
],
"email" => [
"required" => "The email field is required.",
"max" => "Your email is too long. It must not be greater than 255 characters.",
"email" => "Your email is invalid.",
],
"password" => [
"required" => "The password field is required.",
"min" => "Your password is too short. It must be at least 8 characters.",
"confirmed" => "The password field confirmation does not match.",
],
];
}
kamilpiech97 marked this conversation as resolved.
Show resolved Hide resolved
}
Loading
Loading