22- [ Auth Templates] ( #auth-templates )
33- [ Auth Controllers] ( #auth-controllers )
44
5- Authentication is a "must have" feature in most of today's web apps. Almost all the web apps pretty much
6- need the exact set of authentication features — user register, email verification, logging and logging out, reset
7- password etc.
5+ Authentication is a must-have feature in most of today's web apps. Almost all the web apps pretty much need the exact
6+ set of authentication features—user registration, email verification, logging and logging out, password resets etc.
87
9- It needs a lot of work to wire all the components of an authentication system — controllers, models, views, forms,
10- routing, middleware, validation, notifications etc — and make them work. Alpas comes bundled with a ` make:auth `
11- command that does pretty much everything to add an authentication system to your app.
8+ It needs a lot of work to wire all the components of an authentication system— controllers, models, views, forms,
9+ routing, middleware, validation, notifications etc.— and make them properly work. Alpas comes bundled with a
10+ ` make:auth ` command that does pretty much everything to add an authentication system to your app.
1211
13- In this section dive deep into some files and classes generated by ` alpas make:auth ` command and also see how we
14- can further customize the authentication system.
12+ In this section we will dive deep into some files and classes generated by ` alpas make:auth ` command.
13+ We will also see how we can further customize the authentication system to meet our custom needs .
1514
1615<a name =" getting-started " ></a >
1716### [ Getting started] ( #getting-started )
1817
19- To get started, run ` alpas make:auth ` command from your terminal. Once the authentication system is scaffolded,
20- call ` authRoutes() ` from your routes file.
18+ To get started, run ` alpas make:auth ` command from your terminal. Once the authentication
19+ system is scaffolded, call ` authRoutes() ` from your routes file.
20+
21+ <span class =" line-numbers " data-start =" 6 " data-file =" routes.kt " >
2122
2223``` kotlin
2324
@@ -29,21 +30,23 @@ fun Router.addRoutes() = apply {
2930
3031```
3132
33+ </span >
34+
3235That's it!
3336
34- To make sure it actually works , visit http://localhost:8080/register and you should see a nice looking registration
35- form.
37+ To make sure it actually is working , visit http://localhost:8080/register You should see a nice
38+ looking registration form.
3639
3740<a name =" auth-templates " ></a >
3841### [ Auth Templates] ( #auth-templates )
3942
40- These are some templates created by ` make:auth ` command under ` resources/templates ` folder:
43+ These are the Pebble templates created by ` make:auth ` command under ` resources/templates ` folder:
4144
4245<div class =" sublist " >
4346
4447- ` layout/app.peb `
4548
46- The authentication aware layout file used by all the auth views. It is designed to work for not just auth templates
49+ The authentication aware layout file used by all the auth views. It is designed to work for not just auth templates
4750but for your other templates as well. We recommend using this layout file for all of your templates.
4851
4952- ` auth/register.peb `
@@ -56,99 +59,105 @@ The login form page.
5659
5760- ` auth/verify.peb `
5861
59- A page that informs user to verify their email after they successfully register and created a new account.
62+ A page that informs a user to verify their email address after successfully registering and creating a new account.
6063
61- The system uses ` templates/auth/emails/verify.peb ` template to style and render the actual email that gets sent.
64+ Alpas uses ` templates/auth/emails/verify.peb ` template to style and render the actual email that gets sent.
6265
6366- ` auth/passwords/reset_email.peb `
6467
65- If a user forgets their login password, they can request your app to receive an email with password reset
66- instructions. This page is where they would make password reset request by providing an email address.
68+ If a user forgets their login password, they can request your app to receive an email with password reset
69+ instructions. This page is where they would make that request by providing an email address.
6770
68- The system uses ` templates/auth/emails/reset.peb ` template to style and render the actual email that gets sent.
71+ Alpas uses ` templates/auth/emails/reset.peb ` template to style and render the actual email that gets sent.
6972
7073- ` auth/passwords/reset.peb `
7174
72- After a user receives a password reset request email and click a link to reset, they are taken to this page where
73- they will be asked to set a new password and confirm the password.
75+ After a user receives a password reset request email and clicks a link to reset, they are taken to
76+ this page where they will be asked to set a new password and confirm the password.
7477
7578- ` home.peb `
7679
77- An example template that shows what an authenticated page looks like. You can modify this template or completely
78- remove it and its corresponding controller ` HomeController.kt ` files safely .
80+ An example template that shows what an authenticated page looks like. You can modify this template or
81+ safely remove it along with its corresponding controller: ` HomeController.kt ` .
7982
8083</div >
8184
8285<a name =" auth-controllers " ></a >
8386### [ Auth Controllers] ( #auth-controllers )
8487
85- All the controllers that are required to make the scaffolded authentication system work are put under
86- ` controllers/auth ` folder. If you open these controllers, you'll notice that every one of them is empty. This is
87- because to make the authentication system work without any further customization, you really don't have to do
88- anything. For most of the apps just default scaffolded behaviour is enough for a function authentication system.
89- These controller files are generated for you only for further customizations.
88+ All the controllers that are needed to make the scaffolded authentication system work are put under
89+ ` controllers/auth ` folder. If you open these controllers, you'll notice that every one of them is
90+ empty. This is because to make the authentication system work without any further customization,
91+ you really don't have to do anything!
92+
93+ For most of the apps just default scaffolded behaviour is enough for a functional authentication
94+ system. These controller files are generated for you only for further customizations.
9095
9196<div class =" sublist " >
9297
9398- ` controllers/auth/LoginController.kt `
9499
95100Handles user login and logout.
96101
97- ` auth/login.peb ` template is the default template used for showing the login form. If you want to use a different
98- template or want to pass some extra arguments, you need to override ` fun showLoginForm(call: HttpCall) ` method and
99- call ` call.render() ` method yourself.
102+ ` auth/login.peb ` template is the default template used for showing the login form. If you want
103+ to use a different template or want to pass some extra arguments, you need to override
104+ ` fun showLoginForm(call: HttpCall) ` method and call ` call.render() ` method yourself.
100105
101- After a successful login, users are redirected to the original
102- [ intended route ] ( /docs/http-response#redirects ) . If there is no intended route, they are redirected to ` /home `
103- route. If you want to redirect them to somewhere else override ` fun afterLoginRedirectTo(call: HttpCall) ` method.
106+ After a successful login, users are redirected to the original [ intended route ] ( /docs/http-response#redirects ) .
107+ If there is no intended route, they are redirected to ` /home ` route. If you want to redirect them to
108+ somewhere else override ` fun afterLoginRedirectTo(call: HttpCall) ` method.
104109
105- Similarly, users are redirected to ` / ` route after they logout. You can change the redirected route by overriding
106- ` fun afterLogoutRedirectTo(call: HttpCall) ` method.
110+ Similarly, users are redirected to ` / ` route after they logout. You can change the redirected route
111+ by overriding ` fun afterLogoutRedirectTo(call: HttpCall) ` method.
107112
108113- ` controllers/auth/RegisterController.kt `
109114
110115Handles user registration.
111116
112- ` auth/rgister.peb ` template is used for showing the registration form. If you want to use a different
113- template or want to pass some extra arguments, you need to override ` fun showRegistrationForm(call: HttpCall) `
114- method and call ` call.render() ` method yourself.
117+ ` auth/rgister.peb ` template is used for showing the registration form. If you want to use
118+ a different template or want to pass some extra arguments, you need to override
119+ ` fun showRegistrationForm(call: HttpCall) ` method and call ` call.render() `
120+ method yourself.
115121
116- After a successful registration, a new ` User ` record is inserted in ` UsersTable ` and the user is redirected
117- to ` /login ` route. If you want to redirect them to somewhere else override
122+ After a successful registration, a new ` User ` record is inserted in ` UsersTable ` and the user is
123+ redirected to ` /login ` route. If you want to redirect them to somewhere else override
118124` fun afterRegisterRedirectTo(call: HttpCall) ` method.
119125
120126- ` controllers/auth/ForgotPasswordController.kt `
121127
122- Handles password reset requests by asking users for the email address that is associated with the account that they
123- want to reset the password for. The template that contains the form is ` auth.passwords.reset_email ` , which you can
124- override in ` fun showResetLinkRequestForm(call: HttpCall) ` method.
128+ Handles password reset requests by asking users for the email address that is associated with the account that
129+ they would like to reset the password for. The template that contains the form is ` auth.passwords.reset_email ` ,
130+ which you can override in ` fun showResetLinkRequestForm(call: HttpCall) ` method.
125131
126- After verification, a password reset email containing a signed link is sent to the user and are redirected back to
127- the same page containing the form with a flashed successful message. If you want to redirect them to somewhere else,
132+ After verification, a password reset email containing a signed link is sent to the user and are then redirected to the
133+ same page containing the form but with a flashed successful message. If you want to redirect them to somewhere else,
128134override the ` fun afterResetLinkSentRedirectTo(call: HttpCall): String? ` method and return a different route.
129135
130136- ` controllers/auth/PasswordResetController.kt `
131137
132- Handles actual password resets by showing a reset form asking the user for a new password. The form is rendered
133- using ` auth/passwords/reset ` template. ` email ` and ` token ` parameters are passed to the template when rendering.
138+ Handles actual password resets by showing a reset form asking the user for a new password. The form is rendered using
139+ ` auth/passwords/reset ` template. Both ` email ` and ` token ` parameters are passed to the template when rendering.
134140
135- After a successful reset, users are ** automatically logged** in and then redirected to ` / ` route. If you want to
136- redirect them to somewhere else override ` fun afterResetRedirectTo(call: HttpCall) ` method.
141+ After the successful reset, users are ** automatically logged** in and then redirected to ` / ` route. If you
142+ want to redirect them to somewhere else override ` fun afterResetRedirectTo(call: HttpCall) ` method.
137143
138144- ` controllers/auth/EmailVerificationController.kt `
139145
140146Handles user's email verification process.
141147
142- If a user's email is already verified, it redirects the user to ` /home ` route. It also redirects to the same route
143- after a successful verification as well as after (re)sending a verification email. Override
148+ If a user's email is already verified, it redirects the user to ` /home ` route. It also redirects to the same
149+ ` /home ` route after a successful verification as well as after (re)sending a verification email. Override
144150` fun ifVerifiedRedirectTo(call: HttpCall): String ` method if you want to route them to somewhere else.
145151
146152- ` controllers/HomeController.kt `
147153
148- An example controller that just renders a ` home ` template. You can also see how a ` VerifiedEmailOnlyMiddleware ` is
149- applied to this controller. This means only verified users can access this route that this controller is associated
150- with. If you want to see this controller in action you need to reference it from one of your routes.
154+ An example controller that just renders a ` home ` template.
155+
156+ You can also see how a ` VerifiedEmailOnlyMiddleware ` is applied to this controller. This means only
157+ verified users can access this controller. If you want to see this controller in action you
158+ need to reference it from one of [ your routes] ( /docs/routing ) .
151159
152- Feel free to modify this controller further or remove it completely; it is not referenced by any routes by default.
160+ Feel free to modify this controller further or remove it completely; it is not referenced by any
161+ routes by default.
153162
154163</div >
0 commit comments