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 all 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
4 changes: 0 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ APP_KEY=base64:sCsJw8z+d/4ymp0OvzSip2h4Vp2hZZhpV2uOxgTqP94=
APP_DEBUG=true
APP_URL=http://interns2024b.blumilk.localhost

APP_LOCALE=en
APP_FALLBACK_LOCALE=en
APP_FAKER_LOCALE=en_US

APP_MAINTENANCE_DRIVER=file
APP_MAINTENANCE_STORE=database

Expand Down
41 changes: 41 additions & 0 deletions app/Http/Controllers/AuthenticateSessionController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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;

class AuthenticateSessionController extends Controller
{
/**
* @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");
}
}
20 changes: 20 additions & 0 deletions app/Http/Controllers/ContestController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use App\Http\Resources\SchoolResource;
use App\Models\School;
use Inertia\Inertia;
use Inertia\Response;

class ContestController extends Controller
{
public function index(): Response
{
$schools = School::all()->sortBy("name");

return Inertia::render("Home", ["schools" => SchoolResource::collection($schools)]);
}
}
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/ForgotPassword", ["status" => session()->get("status")]);
}

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()->with(["status" => __("passwords.sent")]);
}

public function resetCreate(string $token): Response
{
return Inertia::render("Auth/ResetPassword", ["token" => $token]);
}

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("home")->with("status", __($status))
: back()->withErrors(["email" => [__($status)]]);
}
}
31 changes: 31 additions & 0 deletions app/Http/Controllers/RegisterUserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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;

class RegisterUserController extends Controller
{
public function store(RegisterUserRequest $request): RedirectResponse
{
$userExists = User::query()->where("email", $request->email)->exists();

if (!$userExists) {
$user = new User($request->validated());
$user->password = Hash::make($request->password);
$user->save();
event(new Registered($user));
Auth::login($user);
}

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

declare(strict_types=1);

namespace App\Http\Requests\Auth;

use Illuminate\Foundation\Http\FormRequest;

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

public function rules(): array
{
return [
"email" => ["required", "email", "max:255"],
"password" => ["required", "string"],
];
}
}
22 changes: 22 additions & 0 deletions app/Http/Requests/Auth/ForgotPasswordRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace App\Http\Requests\Auth;

use Illuminate\Foundation\Http\FormRequest;

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

public function rules(): array
{
return [
"email" => ["required", "string", "email", "max:255"],
];
}
}
26 changes: 26 additions & 0 deletions app/Http/Requests/Auth/RegisterUserRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace App\Http\Requests\Auth;

use Illuminate\Foundation\Http\FormRequest;

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

public function rules(): array
{
return [
"email" => ["required", "string", "email:rfc,dns", "max:255"],
"name" => ["required", "string", "max:255"],
"surname" => ["required", "string", "max:255"],
"password" => ["required", "string", "min:8"],
"school_id" => ["required", "integer", "exists:schools,id"],
];
}
}
24 changes: 24 additions & 0 deletions app/Http/Requests/Auth/ResetPasswordRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace App\Http\Requests\Auth;

use Illuminate\Foundation\Http\FormRequest;

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

public function rules(): array
{
return [
"token" => ["required"],
"email" => ["required", "email", "max:255"],
"password" => ["required", "min:8", "confirmed:password_confirmation"],
];
}
}
22 changes: 22 additions & 0 deletions app/Http/Resources/SchoolResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class SchoolResource extends JsonResource
{
/**
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
"id" => $this->id,
"name" => $this->name,
];
}
}
33 changes: 33 additions & 0 deletions app/Mail/RegistrationMail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;

class RegistrationMail extends Mailable
{
use Queueable;
use SerializesModels;

public function __construct() {}

public function envelope(): Envelope
{
return new Envelope(
subject: "Registration Mail",
);
}

public function content(): Content
{
return new Content(
view: "emails.verify-email",
);
}
}
34 changes: 34 additions & 0 deletions app/Models/School.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

/**
* @property int $id
* @property string $name
* @property string $city
* @property string $street
* @property string $building_number
* @property string $apartment_number
* @property string $zip_code
* @property Carbon $created_at
* @property Carbon $updated_at
*/
class School extends Model
{
use HasFactory;

protected $fillable = [
"name",
"city",
"street",
"building_number",
"apartment_number",
"zip_code",
];
}
Loading
Loading