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

#3 - User Authentication #18

Merged
merged 34 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1b1ee3d
- setup
EwelinaSkrzypacz Nov 13, 2024
b5a0da2
- setup
EwelinaSkrzypacz Nov 13, 2024
c4da86b
- setup
EwelinaSkrzypacz Nov 13, 2024
abaa402
- setup
EwelinaSkrzypacz Nov 13, 2024
fe63b7b
- setup
EwelinaSkrzypacz Nov 13, 2024
05ef62d
- setup
EwelinaSkrzypacz Nov 13, 2024
ccef105
- setup
EwelinaSkrzypacz Nov 13, 2024
b419468
- delete .env
EwelinaSkrzypacz Nov 26, 2024
0db10d2
- add newlines
EwelinaSkrzypacz Nov 26, 2024
80f4fcb
solved .env
Silabalkan Nov 26, 2024
a19d841
test commit
Silabalkan Nov 26, 2024
ca2d6bc
user registration created
Silabalkan Dec 2, 2024
faf1dfd
- fixed errors
EwelinaSkrzypacz Dec 2, 2024
83c6e61
registration/login are created succesfuly
Silabalkan Dec 2, 2024
637063d
- fixed errors with register; rollback previous changes because they …
EwelinaSkrzypacz Dec 2, 2024
bc8387e
solved conflicts
Silabalkan Dec 2, 2024
9cbb2bd
Remove .env file from version control
Silabalkan Dec 2, 2024
c19f8d7
cs fix
Silabalkan Dec 2, 2024
a5cac1c
- lint fix; added lintf to make fix command
EwelinaSkrzypacz Dec 2, 2024
17245b5
- trying to fix .env.ci
EwelinaSkrzypacz Dec 2, 2024
768c04d
- trying to fix .env.ci
EwelinaSkrzypacz Dec 2, 2024
6e138ad
- fix database credentials
EwelinaSkrzypacz Dec 3, 2024
43f2655
- fix tests
EwelinaSkrzypacz Dec 3, 2024
0b6d43f
- cs fix
EwelinaSkrzypacz Dec 3, 2024
cad9b05
- fix factory
EwelinaSkrzypacz Dec 3, 2024
83123ab
The last line in the .gitignore file was removed
Silabalkan Dec 3, 2024
21a737d
The .gitignore file has been fixed
Silabalkan Dec 3, 2024
2646019
Fix coding style issues
Silabalkan Dec 3, 2024
1385afb
The errors on GitHub have been fixed
Silabalkan Dec 4, 2024
76bcc43
Fix: Addressed review comments
Silabalkan Dec 5, 2024
3fac8f8
The code design issues have been resolved
Silabalkan Dec 6, 2024
804cfbb
removed empty lin
Silabalkan Dec 6, 2024
2b9e073
fixed empty line error
Silabalkan Dec 6, 2024
04ae8aa
- trying to fix errors
EwelinaSkrzypacz Dec 12, 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
17 changes: 8 additions & 9 deletions .env.ci
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ APP_URL=http://interns2024c.blumilk.localhost
LOG_CHANNEL=stack
LOG_LEVEL=debug

BROADCAST_DRIVER=log
CACHE_DRIVER=array
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=array
SESSION_LIFETIME=120
MAIL_MAILER=array

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=interns2024c
DB_USERNAME=interns2024c
DB_PASSWORD=password

SESSION_DRIVER=array
QUEUE_CONNECTION=sync
BROADCAST_CONNECTION=log
CACHE_STORE=array
MAIL_MAILER=array

BCRYPT_ROUNDS=4
4 changes: 2 additions & 2 deletions .github/workflows/test-and-lint-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ jobs:
pgsql:
image: postgres:16.3-alpine3.18@sha256:64e18e8fb3e9c9aac89ac590c5dd8306b862478404f76cd9b5f7720d012b4c47 # https://hub.docker.com/_/postgres
env:
POSTGRES_DB: interns2024b
POSTGRES_USER: interns2024b
POSTGRES_DB: interns2024c
POSTGRES_USER: interns2024c
POSTGRES_PASSWORD: password
# Set health checks to wait until postgres has started
options: >-
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ yarn-error.log
/.vscode
/.zed
.php-cs-fixer.cache

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ analyse:
@docker compose --file ${DOCKER_COMPOSE_FILE} exec --user "${CURRENT_USER_ID}:${CURRENT_USER_GROUP_ID}" ${DOCKER_COMPOSE_APP_CONTAINER} bash -c 'composer analyse'

dev:
@docker compose --file ${DOCKER_COMPOSE_FILE} exec --user "${CURRENT_USER_ID}:${CURRENT_USER_GROUP_ID}" ${DOCKER_COMPOSE_APP_CONTAINER} bash -c 'npm run dev'
@docker compose --file ${DOCKER_COMPOSE_FILE} exec --user "${CURRENT_USER_ID}:${CURRENT_USER_GROUP_ID}" ${DOCKER_COMPOSE_APP_CONTAINER} bash -c 'npm run dev; npm run lintf'

queue:
@docker compose --file ${DOCKER_COMPOSE_FILE} exec --user "${CURRENT_USER_ID}:${CURRENT_USER_GROUP_ID}" ${DOCKER_COMPOSE_APP_CONTAINER} php artisan queue:work
Expand Down
54 changes: 54 additions & 0 deletions app/Http/Controllers/Auth/AuthenticatedSessionController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

namespace Interns2024c\Http\Controllers\Auth;

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;
use Inertia\Inertia;
use Inertia\Response;
use Interns2024c\Http\Controllers\Controller;
use Interns2024c\Http\Requests\Auth\LoginRequest;

class AuthenticatedSessionController extends Controller
{
/**
* Display the login view.
*/
public function create(): Response
{
return Inertia::render("Auth/Login", [
"canResetPassword" => Route::has("password.request"),
"status" => session("status"),
]);
}

/**
* Handle an incoming authentication request.
*/
public function store(LoginRequest $request): RedirectResponse
{
$request->authenticate();

$request->session()->regenerate();

return redirect()->intended(route("dashboard", absolute: false));
}

/**
* Destroy an authenticated session.
*/
public function destroy(Request $request): RedirectResponse
{
Auth::guard("web")->logout();

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

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

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

declare(strict_types=1);

namespace Interns2024c\Http\Controllers\Auth;

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\ValidationException;
use Inertia\Inertia;
use Inertia\Response;
use Interns2024c\Http\Controllers\Controller;

class ConfirmablePasswordController extends Controller
{
/**
* Show the confirm password view.
*/
public function show(): Response
{
return Inertia::render("Auth/ConfirmPassword");
}

/**
* Confirm the user's password.
*/
public function store(Request $request): RedirectResponse
{
if (!Auth::guard("web")->validate([
"email" => $request->user()->email,
"password" => $request->password,
])) {
throw ValidationException::withMessages([
"password" => __("auth.password"),
]);
}

$request->session()->put("auth.password_confirmed_at", time());

return redirect()->intended(route("dashboard", absolute: false));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Interns2024c\Http\Controllers\Auth;

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Interns2024c\Http\Controllers\Controller;

class EmailVerificationNotificationController extends Controller
{
/**
* Send a new email verification notification.
*/
public function store(Request $request): RedirectResponse
{
if ($request->user()->hasVerifiedEmail()) {
return redirect()->intended(route("dashboard", absolute: false));
}

$request->user()->sendEmailVerificationNotification();

return back()->with("status", "verification-link-sent");
}
}
24 changes: 24 additions & 0 deletions app/Http/Controllers/Auth/EmailVerificationPromptController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Interns2024c\Http\Controllers\Auth;

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;
use Interns2024c\Http\Controllers\Controller;

class EmailVerificationPromptController extends Controller
{
/**
* Display the email verification prompt.
*/
public function __invoke(Request $request): RedirectResponse|Response
{
return $request->user()->hasVerifiedEmail()
? redirect()->intended(route("dashboard", absolute: false))
: Inertia::render("Auth/VerifyEmail", ["status" => session("status")]);
}
}
71 changes: 71 additions & 0 deletions app/Http/Controllers/Auth/NewPasswordController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

declare(strict_types=1);

namespace Interns2024c\Http\Controllers\Auth;

use Illuminate\Auth\Events\PasswordReset;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Password;
use Illuminate\Support\Str;
use Illuminate\Validation\Rules;
use Illuminate\Validation\ValidationException;
use Inertia\Inertia;
use Inertia\Response;
use Interns2024c\Http\Controllers\Controller;

class NewPasswordController extends Controller
{
/**
* Display the password reset view.
*/
public function create(Request $request): Response
{
return Inertia::render("Auth/ResetPassword", [
"email" => $request->email,
"token" => $request->route("token"),
]);
}

/**
* Handle an incoming new password request.
*
* @throws ValidationException
*/
public function store(Request $request): RedirectResponse
{
$request->validate([
"token" => "required",
"email" => "required|email",
"password" => ["required", "confirmed", Rules\Password::defaults()],
]);

// Here we will attempt to reset the user's password. If it is successful we
// will update the password on an actual user model and persist it to the
// database. Otherwise we will parse the error and return the response.
$status = Password::reset(
$request->only("email", "password", "password_confirmation", "token"),
function ($user) use ($request): void {
$user->forceFill([
"password" => Hash::make($request->password),
"remember_token" => Str::random(60),
])->save();

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

// If the password was successfully reset, we will redirect the user back to
// the application's home authenticated view. If there is an error we can
// redirect them back to where they came from with their error message.
if ($status === Password::PASSWORD_RESET) {
return redirect()->route("login")->with("status", __($status));
}

throw ValidationException::withMessages([
"email" => [trans($status)],
]);
}
}
31 changes: 31 additions & 0 deletions app/Http/Controllers/Auth/PasswordController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Interns2024c\Http\Controllers\Auth;

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\Rules\Password;
use Interns2024c\Http\Controllers\Controller;

class PasswordController extends Controller
{
/**
* Update the user's password.
*/
public function update(Request $request): RedirectResponse
{
$validated = $request->validate([
"current_password" => ["required", "current_password"],
"password" => ["required", Password::defaults(), "confirmed"],
]);

$request->user()->update([
"password" => Hash::make($validated["password"]),
]);

return back();
}
}
53 changes: 53 additions & 0 deletions app/Http/Controllers/Auth/PasswordResetLinkController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

namespace Interns2024c\Http\Controllers\Auth;

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Password;
use Illuminate\Validation\ValidationException;
use Inertia\Inertia;
use Inertia\Response;
use Interns2024c\Http\Controllers\Controller;

class PasswordResetLinkController extends Controller
{
/**
* Display the password reset link request view.
*/
public function create(): Response
{
return Inertia::render("Auth/ForgotPassword", [
"status" => session("status"),
]);
}

/**
* Handle an incoming password reset link request.
*
* @throws ValidationException
*/
public function store(Request $request): RedirectResponse
{
$request->validate([
"email" => "required|email",
]);

// We will send the password reset link to this user. Once we have attempted
// to send the link, we will examine the response then see the message we
// need to show to the user. Finally, we'll send out a proper response.
$status = Password::sendResetLink(
$request->only("email"),
);

if ($status === Password::RESET_LINK_SENT) {
return back()->with("status", __($status));
}

throw ValidationException::withMessages([
"email" => [trans($status)],
]);
}
}
Loading
Loading