Skip to content

Commit

Permalink
feat: display flash message
Browse files Browse the repository at this point in the history
  • Loading branch information
ammezie committed Jun 17, 2022
1 parent b748631 commit 11dabb2
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 28 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@
{
"src": "resources/views/auth/resend-verification.txt",
"dest": "auth/resend-verification.edge"
},
{
"src": "resources/views/partials/notification.txt",
"dest": "partials/notification.edge"
}
]
}
Expand Down
6 changes: 3 additions & 3 deletions templates/controllers/AuthController.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class AuthController {
await auth.attempt(email, password, remember)

session.flash({
alert: {
notification: {
type: 'info',
message: "Welcome back, you're now signed in.",
},
Expand All @@ -22,7 +22,7 @@ export default class AuthController {
return response.intended()
} catch (error) {
session.flash({
alert: {
notification: {
type: 'error',
message: "We couldn't verify your credentials.",
},
Expand All @@ -37,6 +37,6 @@ export default class AuthController {

session.forget('password_confirmed_at')

return response.redirect('/')
return response.redirect().toRoute('home')
}
}
2 changes: 1 addition & 1 deletion templates/controllers/ConfirmPasswordController.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class ConfirmPasswordController {
return response.intended()
} catch (error) {
session.flash({
alert: {
notification: {
type: 'error',
message: "We couldn't verify your credentials.",
},
Expand Down
10 changes: 5 additions & 5 deletions templates/controllers/EmailVerificationController.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class EmailVerificationController {
public async verify({ request, params, session, response }: HttpContextContract) {
if (!request.hasValidSignature()) {
session.flash({
alert: {
notification: {
type: 'error',
message: 'Verification link is invalid or has expired.',
},
Expand All @@ -21,7 +21,7 @@ export default class EmailVerificationController {

if (user.emailVerifiedAt) {
session.flash({
alert: {
notification: {
type: 'info',
message: 'Email address already verified.',
},
Expand All @@ -34,7 +34,7 @@ export default class EmailVerificationController {
await user.save()

session.flash({
alert: {
notification: {
type: 'success',
message: 'Email address verified.',
},
Expand All @@ -54,7 +54,7 @@ export default class EmailVerificationController {

if (user?.emailVerifiedAt) {
session.flash({
alert: {
notification: {
type: 'info',
message: 'Email address arealdy verified.',
},
Expand All @@ -66,7 +66,7 @@ export default class EmailVerificationController {
Event.emit('userRegistered', user!)

session.flash({
alert: {
notification: {
type: 'success',
message:
'A verification link has been sent to your email address, kindly follow the link to verify your email address.',
Expand Down
6 changes: 3 additions & 3 deletions templates/controllers/PasswordResetController.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class PasswordResetController {
})
} catch (error) {
session.flash({
alert: {
notification: {
type: 'error',
message: 'Invalid password reset token.',
},
Expand Down Expand Up @@ -46,7 +46,7 @@ export default class PasswordResetController {
Event.emit('passwordReset', user)

session.flash({
alert: {
notification: {
type: 'success',
message: 'Password reset successful.',
},
Expand All @@ -55,7 +55,7 @@ export default class PasswordResetController {
return response.redirect('/login')
} catch (error) {
session.flash({
alert: {
notification: {
type: 'error',
message: 'Invalid password reset token.',
},
Expand Down
2 changes: 1 addition & 1 deletion templates/controllers/PasswordResetRequestController.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class PasswordResetRequestController {
Event.emit('passwordResetRequested', { user, token })

session.flash({
alert: {
notification: {
type: 'success',
message: 'A password reset link has been sent to your email address.',
},
Expand Down
8 changes: 5 additions & 3 deletions templates/controllers/RegisterController.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@ export default class RegisterController {
return view.render('auth/register')
}

public async store({ request, session, response }: HttpContextContract) {
public async store({ request, auth, session, response }: HttpContextContract) {
const payload = await request.validate(RegisterValidator)

const user = await User.create(payload)

Event.emit('userRegistered', user)

session.flash({
alert: {
notification: {
type: 'success',
message: 'Register successful!',
},
})

return response.redirect().back()
await auth.login(user)

return response.redirect().toRoute('dashboard')
}
}
3 changes: 1 addition & 2 deletions templates/resources/views/auth/confirm-password.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
Please confirm your password to continue.
</p>

{{-- @include('partials/alert')
@include('partials/errors') --}}
@include('partials/notification')

<form class="space-y-6" action="{{ route('ConfirmPasswordController.store') }}" method="POST">
{{ csrfField() }}
Expand Down
3 changes: 1 addition & 2 deletions templates/resources/views/auth/forgot-password.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
Enter your email address and we'll send you a password reset link.
</p>

{{-- @include('partials/alert')
@include('partials/errors') --}}
@include('partials/notification')

<form class="space-y-6" action="{{ route('PasswordResetRequestController.store') }}" method="POST">
{{ csrfField() }}
Expand Down
3 changes: 1 addition & 2 deletions templates/resources/views/auth/login.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
<div class="bg-white py-8 px-4 shadow sm:rounded-lg sm:px-10">
<h3 class="mb-6 text-2xl text-gray-700">Log in</h3>

{{-- @include('partials/alert')
@include('partials/errors') --}}
@include('partials/notification')

<form class="space-y-6" action="{{ route('AuthController.store') }}" method="POST">
{{ csrfField() }}
Expand Down
3 changes: 1 addition & 2 deletions templates/resources/views/auth/register.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
<div class="bg-white py-8 px-4 shadow sm:rounded-lg sm:px-10">
<p class="mb-6 text-2xl text-gray-700">Create a free account</p>

{{-- @include('partials/alert')
@include('partials/errors') --}}
@include('partials/notification')

<form class="space-y-6" action="{{ route('RegisterController.store') }}" method="POST">
{{ csrfField() }}
Expand Down
3 changes: 1 addition & 2 deletions templates/resources/views/auth/resend-verification.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
Didn't receive the verification link? Enter your email address and we'll resend it to you.
</p>

{{-- @include('partials/alert')
@include('partials/errors') --}}
@include('partials/notification')

<form class="space-y-6" action="{{ route('EmailVerificationController.store') }}" method="POST">
{{ csrfField() }}
Expand Down
3 changes: 1 addition & 2 deletions templates/resources/views/auth/reset-password.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
<div class="bg-white text-gray-500 py-8 px-4 shadow sm:rounded-lg sm:px-10">
<p class="mb-6">Set a new password reset.</p>

{{-- @include('partials/alert')
@include('partials/errors') --}}
@include('partials/notification')

<form class="space-y-6" action="{{ route('PasswordResetController.store') }}" method="POST">
{{ csrfField() }}
Expand Down
15 changes: 15 additions & 0 deletions templates/resources/views/partials/notification.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@if (flashMessages.has('notification'))
@if(flashMessages.get('notification.type') === 'success')
<div class="rounded-md bg-green-50 p-4 text-sm font-medium text-green-800">
{{ flashMessages.get('notification.message') }}
</div>
@elseif(flashMessages.get('notification.type') === 'error')
<div class="rounded-md bg-red-50 p-4 text-sm font-medium text-red-800">
{{ flashMessages.get('notification.message') }}
</div>
@elseif(flashMessages.get('notification.type') === 'info')
<div class="rounded-md bg-blue-50 p-4 text-sm font-medium text-blue-800">
{{ flashMessages.get('notification.message') }}
</div>
@endif
@endif

0 comments on commit 11dabb2

Please sign in to comment.