SlideShare a Scribd company logo
Grails tutorial
  Simple login/logout




                  http://khomkrit.wordpress.com
Part I
Create View
Prepare Artifact
Create Grails Application

       > grails create-app simple-login


and Create a Controller named user, used to
handle user activity such as login and logout.

       > grails create-controller user
Prepare Artifact

    Create a file named “index.gsp” in

    grails/views/user/ Directory
Custom Login Page
Custom the “index.gsp” file created recently
Custom Login Page
Custom the “index.gsp” file created recently




                  add some style
                      Create HTML textfield for
                         username/password
Custom Login Page
 create a form using <g:form> tag
Custom Login Page
if you don’t want to use <g:form> tag you can
use HTML form instead! Because in finally,
Grails will generate plain HTML form to you.

I prefer to use <g:form> tag, it’s make sense
and give more semantic and info about what
controller and what action will accepts from
form request.


      <g:form action=”login”/>
Custom Login Page
      <g:form action=”login”/>

send form request to action named “login”

and What Controller? If you don’t specify a
controller name it will send request to
default controller corresponding with the
name of file directory.

In this situation, index.gsp is in /grails-app/
user/ directory. So, It will send request to
user controller.
Custom Login Page

<g:form controller=”user” action=”login”/>



   Anyway, You can add the specific controller
   to which you want to sent request.
Start Grails Application by using this command


           > grails run-app


Go to http://localhost:8080/simple-login/user
Now, you cannot do anything with the form.
If you click the Login button, the error will
occurs. Why?

Because the target action specified by you in
the previous is not created.
What is the action specified by you?

Back to the login.gsp you will see this...
What is the action specified by you?

Back to the login.gsp you will see this...




                       Yes, action named “login” will
                           get the form request.
Part II
Let’s create the Action
Tip

You can make most changes, including
changes to the domain and controller classes,
without having to restart the web server.

Sometimes, however, change require a
restart. Creating a new controller sometimes
requires a restart
Let’s create the action

All action is declared in the controller file. In
this case, you want to send request to
controller named “user” and action named
“login”

go to UserController.groovy to create the
“login” action.
Custom Controller

       all Controller is in

       /grails-app/controllers/ directory
Custom Controller

Open UserController.groovy

and Create an action named “login”
Custom Controller
Go to http://localhost:8080/simple-login/user/


          and Click the Login Button
Custom Controller
OOP! Grails sent 404 back! Why?
Custom Controller
By Default, When you call any action, Grails try to
search for a file which has name corresponding
with the action name called by client.

In this case you try to http:/ /localhost:8080/
simple-login/user/login, this url means you try to
call action named “login” in the user controller

So, Grails try to find a file named “login.gsp” in /
grails-app/views/user/ directory for render to
client.

you don’t have that file!
Custom Controller
You don’t have the login.gsp file for Grails, It’s
make Grails don’t know what should to render
back to client.

You can use “render” method for tell Grails what
it should to render back.
Custom Controller
Go to http://localhost:8080/simple-login/user/


      and Click the Login Button again.
Custom Controller
Good Responding :)
Custom Controller
You can add some your logic to handle login such
as keep login status in the session and send some
message back to user like “you have logged in” or
“your login failed” in the login action.




                         You can add some logic to
                             handle login here
Part III
Add some Logic to
 Handle the Login
Validation
Add simple validation to check username and
password sent from client

all parameters sent from client is stored in
variable named “params”

So, the code will look like this...
Validation

For testing, go to login page and try to login
again.

If username is “admin” and password is “pass”
then you can login, else cannot.
Validation
Don’t You want to use ugly responding when
user try to login?

Next, After user has logged in, the Grails
application will redirect user to the login
page again and give some info using “flash”
variable.

About flash scope is out of this tutorial topic
but you can investigate that how to use flash
through this tutorial.
Using flash
use flash variable to store some message as
the following code and redirect to the login
page (index.gsp) .
Using flash
redirecting user to action named “index” .By
default, Grails will search for file named
“index.gsp” in grails-app/views/user/ directory.

flash message sent to action named “index” by
the last command in login action and also
through to index.gsp

So, You can access the flash message in action
named “index” and also access it in “index.gsp”
Using flash
Add ${flash.message} in login page If it has
something in, it will show message




 To display value in a variable you can use
 this pattern ${variable-name}
Using flash
       Testing, Go to login page and try to login
       again.




After try to login, you will see value in
 flash.message sent from login action.
Keep Status

You can use “session” to keep information
about login status.




                       Keep some info by
                      using session variable
Handle Logout
Create a new action named “logout” to handle when
user want to logout.

session.user keep status that the user has logged
in, so you should clear all info about logged in user.




                                  New action
Custom Login page
Add some logic more, if user has logged in then
do not show login form and show a logout link
instead.

Use <g:if>, <g:else> tag to test something.
Custom Login page
Using <g:if> tag

     <g:if test=”${boolean-logic}”>



Example:

           <g:if test=”${5 == 6}”>
Custom Login page

Creating a link to logout action, you can use
<g:link> as the following.
Custom Login page
  Anyway, you can use HTML link tag - <a href=””> ,
  instead. But I prefer to use <g:link> with the same
  reason of why I prefer to use <g:form>


        <g:link controller=”” action=””>

If you do not specify controller name, Grails will
automatic search for controller like <g:form> behavior.

               <g:link action=””>
Check Point!
Now you have a login page.

If you login succeed, You can see a logout link
and the login form has thrown away.

If you login fail, the login form still be with you.

After you try to login, Whatever the result is fail
or succeed have you got. You always see a flash
message.
Add some more thing
Grails has a default CSS and you can use its
like the following.


                            Use build in CSS,
                            class=”message”
Add some more thing
As you can see, the style has applied to
flash.message value
Add some more thing


For another style, you can see in the /web-
app/css/ directory

Other resource is in /web-app/images/ and
web-app/js directory
Q/A
Have any Question?
Thank You

Sorry about many wrong grammar in this
slide :D

More Related Content

What's hot

Servlet sessions
Servlet sessionsServlet sessions
Servlet sessions
vantinhkhuc
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
Bui Kiet
 
Grails object relational mapping: GORM
Grails object relational mapping: GORMGrails object relational mapping: GORM
Grails object relational mapping: GORM
Saurabh Dixit
 
HTL(Sightly) - All you need to know
HTL(Sightly) - All you need to knowHTL(Sightly) - All you need to know
HTL(Sightly) - All you need to know
Prabhdeep Singh
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
habib_786
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
WebStackAcademy
 
Intro to html 5
Intro to html 5Intro to html 5
Intro to html 5
Ian Jasper Mangampo
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
Trey Howard
 
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
Edureka!
 
Java script
Java scriptJava script
Java script
Shyam Khant
 
Java 9 Features
Java 9 FeaturesJava 9 Features
Java 9 Features
NexThoughts Technologies
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners
Varun Raj
 
Java Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and ExampleJava Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and Example
kamal kotecha
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJS
Brainhub
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
Seble Nigussie
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
Van Huong
 
JPA and Hibernate
JPA and HibernateJPA and Hibernate
JPA and Hibernate
elliando dias
 
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
DHTMLExtreme
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
Ian Macali
 
MySQL
MySQLMySQL

What's hot (20)

Servlet sessions
Servlet sessionsServlet sessions
Servlet sessions
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
 
Grails object relational mapping: GORM
Grails object relational mapping: GORMGrails object relational mapping: GORM
Grails object relational mapping: GORM
 
HTL(Sightly) - All you need to know
HTL(Sightly) - All you need to knowHTL(Sightly) - All you need to know
HTL(Sightly) - All you need to know
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
 
Intro to html 5
Intro to html 5Intro to html 5
Intro to html 5
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
 
Java script
Java scriptJava script
Java script
 
Java 9 Features
Java 9 FeaturesJava 9 Features
Java 9 Features
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners
 
Java Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and ExampleJava Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and Example
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJS
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
 
JPA and Hibernate
JPA and HibernateJPA and Hibernate
JPA and Hibernate
 
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
 
MySQL
MySQLMySQL
MySQL
 

Viewers also liked

Grails Connecting to MySQL
Grails Connecting to MySQLGrails Connecting to MySQL
Grails Connecting to MySQL
ashishkirpan
 
Introduction to Grails Framework
Introduction to Grails FrameworkIntroduction to Grails Framework
Introduction to Grails Framework
PT.JUG
 
Grails Overview
Grails OverviewGrails Overview
Grails Overview
Christopher Bartling
 
Grails GORM - You Know SQL. You Know Queries. Here's GORM.
Grails GORM - You Know SQL. You Know Queries. Here's GORM.Grails GORM - You Know SQL. You Know Queries. Here's GORM.
Grails GORM - You Know SQL. You Know Queries. Here's GORM.
Ted Vinke
 
Application Architectures in Grails
Application Architectures in GrailsApplication Architectures in Grails
Application Architectures in Grails
Peter Ledbrook
 
Introduction to Grails
Introduction to GrailsIntroduction to Grails
Introduction to Grails
Hiten Pratap Singh
 
No Container: a Modern Java Stack with Bootique
No Container: a Modern Java Stack with BootiqueNo Container: a Modern Java Stack with Bootique
No Container: a Modern Java Stack with Bootique
Andrus Adamchik
 
Devoxx
DevoxxDevoxx
Java training in Bhubaneswar
Java training in BhubaneswarJava training in Bhubaneswar
Java training in Bhubaneswar
javalit
 
Gorm
GormGorm
Image compression: Techniques and Application
Image compression: Techniques and ApplicationImage compression: Techniques and Application
Image compression: Techniques and Application
Nidhi Baranwal
 
Image compression .
Image compression .Image compression .
Image compression .
Payal Vishwakarma
 
Contrast limited adaptive histogram equalization
Contrast limited adaptive histogram equalizationContrast limited adaptive histogram equalization
Contrast limited adaptive histogram equalization
Er. Nancy
 
Nielsen company overview
Nielsen company overviewNielsen company overview
Nielsen company overview
fenist
 
How to generate customized java 8 code from your database
How to generate customized java 8 code from your databaseHow to generate customized java 8 code from your database
How to generate customized java 8 code from your database
Speedment, Inc.
 
Image pre processing-restoration
Image pre processing-restorationImage pre processing-restoration
Image pre processing-restoration
Ashish Kumar
 
Image Processing (General Topic)
Image Processing (General Topic)Image Processing (General Topic)
Image Processing (General Topic)
mcc.jeppiaar
 
Spandana image processing and compression techniques (7840228)
Spandana   image processing and compression techniques (7840228)Spandana   image processing and compression techniques (7840228)
Spandana image processing and compression techniques (7840228)
indianspandana
 
JPEG Image Compression
JPEG Image CompressionJPEG Image Compression
JPEG Image Compression
Hemanth Kumar Mantri
 
BigData: AWS RedShift with S3, EC2
BigData: AWS RedShift with S3, EC2BigData: AWS RedShift with S3, EC2
BigData: AWS RedShift with S3, EC2
Paulraj Pappaiah
 

Viewers also liked (20)

Grails Connecting to MySQL
Grails Connecting to MySQLGrails Connecting to MySQL
Grails Connecting to MySQL
 
Introduction to Grails Framework
Introduction to Grails FrameworkIntroduction to Grails Framework
Introduction to Grails Framework
 
Grails Overview
Grails OverviewGrails Overview
Grails Overview
 
Grails GORM - You Know SQL. You Know Queries. Here's GORM.
Grails GORM - You Know SQL. You Know Queries. Here's GORM.Grails GORM - You Know SQL. You Know Queries. Here's GORM.
Grails GORM - You Know SQL. You Know Queries. Here's GORM.
 
Application Architectures in Grails
Application Architectures in GrailsApplication Architectures in Grails
Application Architectures in Grails
 
Introduction to Grails
Introduction to GrailsIntroduction to Grails
Introduction to Grails
 
No Container: a Modern Java Stack with Bootique
No Container: a Modern Java Stack with BootiqueNo Container: a Modern Java Stack with Bootique
No Container: a Modern Java Stack with Bootique
 
Devoxx
DevoxxDevoxx
Devoxx
 
Java training in Bhubaneswar
Java training in BhubaneswarJava training in Bhubaneswar
Java training in Bhubaneswar
 
Gorm
GormGorm
Gorm
 
Image compression: Techniques and Application
Image compression: Techniques and ApplicationImage compression: Techniques and Application
Image compression: Techniques and Application
 
Image compression .
Image compression .Image compression .
Image compression .
 
Contrast limited adaptive histogram equalization
Contrast limited adaptive histogram equalizationContrast limited adaptive histogram equalization
Contrast limited adaptive histogram equalization
 
Nielsen company overview
Nielsen company overviewNielsen company overview
Nielsen company overview
 
How to generate customized java 8 code from your database
How to generate customized java 8 code from your databaseHow to generate customized java 8 code from your database
How to generate customized java 8 code from your database
 
Image pre processing-restoration
Image pre processing-restorationImage pre processing-restoration
Image pre processing-restoration
 
Image Processing (General Topic)
Image Processing (General Topic)Image Processing (General Topic)
Image Processing (General Topic)
 
Spandana image processing and compression techniques (7840228)
Spandana   image processing and compression techniques (7840228)Spandana   image processing and compression techniques (7840228)
Spandana image processing and compression techniques (7840228)
 
JPEG Image Compression
JPEG Image CompressionJPEG Image Compression
JPEG Image Compression
 
BigData: AWS RedShift with S3, EC2
BigData: AWS RedShift with S3, EC2BigData: AWS RedShift with S3, EC2
BigData: AWS RedShift with S3, EC2
 

Similar to Grails Simple Login

How To: Use Google Search Ap Is On Your Blog
How To: Use Google Search Ap Is On Your BlogHow To: Use Google Search Ap Is On Your Blog
How To: Use Google Search Ap Is On Your Blog
mutex07
 
RSpec User Stories
RSpec User StoriesRSpec User Stories
RSpec User Stories
rahoulb
 
What's new in Rails 2?
What's new in Rails 2?What's new in Rails 2?
What's new in Rails 2?
brynary
 
OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails Turtorial
Yi-Ting Cheng
 
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docxLab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
smile790243
 
Aug Xml Net Forum Dynamics Integration
Aug Xml Net Forum Dynamics IntegrationAug Xml Net Forum Dynamics Integration
Aug Xml Net Forum Dynamics Integration
MariAnne Woehrle
 
Grails Advanced
Grails Advanced Grails Advanced
Grails Advanced
Saurabh Dixit
 
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English
Grails 0.3-SNAPSHOT Presentation WJAX 2006 EnglishGrails 0.3-SNAPSHOT Presentation WJAX 2006 English
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English
Sven Haiges
 
Introduce cucumber
Introduce cucumberIntroduce cucumber
Introduce cucumber
Bachue Zhou
 
Gadgets Intro (Plus Mapplets)
Gadgets Intro (Plus Mapplets)Gadgets Intro (Plus Mapplets)
Gadgets Intro (Plus Mapplets)
Pamela Fox
 
Cis407 a ilab 6 web application development devry university
Cis407 a ilab 6 web application development devry universityCis407 a ilab 6 web application development devry university
Cis407 a ilab 6 web application development devry university
lhkslkdh89009
 
Angular 11 google social login or sign in tutorial using angularx social-login
Angular 11 google social login or sign in tutorial using angularx social-loginAngular 11 google social login or sign in tutorial using angularx social-login
Angular 11 google social login or sign in tutorial using angularx social-login
Katy Slemon
 
Grails and Dojo
Grails and DojoGrails and Dojo
Grails and Dojo
Sven Haiges
 
Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation
Compare Infobase Limited
 
Rails Plugins - Linux For You, March 2011 Issue
Rails Plugins - Linux For You, March 2011 IssueRails Plugins - Linux For You, March 2011 Issue
Rails Plugins - Linux For You, March 2011 Issue
Sagar Arlekar
 
Google App Engine tutorial
Google App Engine tutorialGoogle App Engine tutorial
Google App Engine tutorial
NameForTheTutorial
 
Periscopix presentation
Periscopix presentationPeriscopix presentation
Periscopix presentation
JamieCluett
 
Developing and testing ajax components
Developing and testing ajax componentsDeveloping and testing ajax components
Developing and testing ajax components
Ignacio Coloma
 
Testing C# and ASP.net using Ruby
Testing C# and ASP.net using RubyTesting C# and ASP.net using Ruby
Testing C# and ASP.net using Ruby
Ben Hall
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
scidept
 

Similar to Grails Simple Login (20)

How To: Use Google Search Ap Is On Your Blog
How To: Use Google Search Ap Is On Your BlogHow To: Use Google Search Ap Is On Your Blog
How To: Use Google Search Ap Is On Your Blog
 
RSpec User Stories
RSpec User StoriesRSpec User Stories
RSpec User Stories
 
What's new in Rails 2?
What's new in Rails 2?What's new in Rails 2?
What's new in Rails 2?
 
OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails Turtorial
 
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docxLab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
 
Aug Xml Net Forum Dynamics Integration
Aug Xml Net Forum Dynamics IntegrationAug Xml Net Forum Dynamics Integration
Aug Xml Net Forum Dynamics Integration
 
Grails Advanced
Grails Advanced Grails Advanced
Grails Advanced
 
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English
Grails 0.3-SNAPSHOT Presentation WJAX 2006 EnglishGrails 0.3-SNAPSHOT Presentation WJAX 2006 English
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English
 
Introduce cucumber
Introduce cucumberIntroduce cucumber
Introduce cucumber
 
Gadgets Intro (Plus Mapplets)
Gadgets Intro (Plus Mapplets)Gadgets Intro (Plus Mapplets)
Gadgets Intro (Plus Mapplets)
 
Cis407 a ilab 6 web application development devry university
Cis407 a ilab 6 web application development devry universityCis407 a ilab 6 web application development devry university
Cis407 a ilab 6 web application development devry university
 
Angular 11 google social login or sign in tutorial using angularx social-login
Angular 11 google social login or sign in tutorial using angularx social-loginAngular 11 google social login or sign in tutorial using angularx social-login
Angular 11 google social login or sign in tutorial using angularx social-login
 
Grails and Dojo
Grails and DojoGrails and Dojo
Grails and Dojo
 
Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation
 
Rails Plugins - Linux For You, March 2011 Issue
Rails Plugins - Linux For You, March 2011 IssueRails Plugins - Linux For You, March 2011 Issue
Rails Plugins - Linux For You, March 2011 Issue
 
Google App Engine tutorial
Google App Engine tutorialGoogle App Engine tutorial
Google App Engine tutorial
 
Periscopix presentation
Periscopix presentationPeriscopix presentation
Periscopix presentation
 
Developing and testing ajax components
Developing and testing ajax componentsDeveloping and testing ajax components
Developing and testing ajax components
 
Testing C# and ASP.net using Ruby
Testing C# and ASP.net using RubyTesting C# and ASP.net using Ruby
Testing C# and ASP.net using Ruby
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
 

Recently uploaded

What is Amul milk made of? Why is it unnaturally thick and ...
What is Amul milk made of? Why is it unnaturally thick and ...What is Amul milk made of? Why is it unnaturally thick and ...
What is Amul milk made of? Why is it unnaturally thick and ...
chetankumar9855
 
God made everyone equal - Woman are not weak - so Go Ahead.pptx
God made everyone equal - Woman are not weak - so Go Ahead.pptxGod made everyone equal - Woman are not weak - so Go Ahead.pptx
God made everyone equal - Woman are not weak - so Go Ahead.pptx
SSDesai1
 
UoB biyezheng degree offer diploma Transcript
UoB biyezheng degree offer diploma TranscriptUoB biyezheng degree offer diploma Transcript
UoB biyezheng degree offer diploma Transcript
gygab
 
Bournemouth University diploma
Bournemouth University diplomaBournemouth University diploma
Bournemouth University diploma
znezse
 
Birmingham City University diploma
Birmingham City University diplomaBirmingham City University diploma
Birmingham City University diploma
znezse
 
High Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 ...
High Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 ...High Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 ...
High Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 ...
rajvarma123614
 
Photographs of Prof. Dr. Ram Sharan Mehta
Photographs of Prof. Dr. Ram Sharan MehtaPhotographs of Prof. Dr. Ram Sharan Mehta
Photographs of Prof. Dr. Ram Sharan Mehta
BP KOIRALA INSTITUTE OF HELATH SCIENCS,, NEPAL
 
UofM degree offer diploma Transcript
UofM degree offer diploma TranscriptUofM degree offer diploma Transcript
UofM degree offer diploma Transcript
eoavyq
 
Vadodara Girls Call Vadodara 0X0000000X Unlimited Short Providing Girls Servi...
Vadodara Girls Call Vadodara 0X0000000X Unlimited Short Providing Girls Servi...Vadodara Girls Call Vadodara 0X0000000X Unlimited Short Providing Girls Servi...
Vadodara Girls Call Vadodara 0X0000000X Unlimited Short Providing Girls Servi...
rachitkumar09887
 
Mysore Girls Call Mysore 0X0000000X Unlimited Short Providing Girls Service A...
Mysore Girls Call Mysore 0X0000000X Unlimited Short Providing Girls Service A...Mysore Girls Call Mysore 0X0000000X Unlimited Short Providing Girls Service A...
Mysore Girls Call Mysore 0X0000000X Unlimited Short Providing Girls Service A...
rachitkumar09887
 
Taming the Mind Embracing Mindfulness with Mental Noting
Taming the Mind Embracing Mindfulness with Mental NotingTaming the Mind Embracing Mindfulness with Mental Noting
Taming the Mind Embracing Mindfulness with Mental Noting
SarahWawrzyniak1
 
UOL biyezheng degree offer diploma Transcript
UOL biyezheng degree offer diploma TranscriptUOL biyezheng degree offer diploma Transcript
UOL biyezheng degree offer diploma Transcript
gygab
 
KCL biyezheng degree offer diploma Transcript
KCL biyezheng degree offer diploma TranscriptKCL biyezheng degree offer diploma Transcript
KCL biyezheng degree offer diploma Transcript
gygab
 
7 Rules For A Successful Life presentation by Rohit Chandra Thakur
7 Rules For A Successful Life presentation by Rohit Chandra Thakur7 Rules For A Successful Life presentation by Rohit Chandra Thakur
7 Rules For A Successful Life presentation by Rohit Chandra Thakur
Rohit Chandra
 
The Most Helpful Book Ever Published!!!!
The Most Helpful Book Ever Published!!!!The Most Helpful Book Ever Published!!!!
The Most Helpful Book Ever Published!!!!
THOMASANTTI1
 
The Benefits of Mindfulness Practices for Mental Clarity and Focus.pptx
The Benefits of Mindfulness Practices for Mental Clarity and Focus.pptxThe Benefits of Mindfulness Practices for Mental Clarity and Focus.pptx
The Benefits of Mindfulness Practices for Mental Clarity and Focus.pptx
Vinod Adani
 
Calendar july 2024 planner organization.pdf
Calendar july 2024 planner organization.pdfCalendar july 2024 planner organization.pdf
Calendar july 2024 planner organization.pdf
AlineGeice1
 
University of Ibershire diploma
University of Ibershire diplomaUniversity of Ibershire diploma
University of Ibershire diploma
znezse
 
How to Manage Self Care in Daily Lives of Yours?
How to Manage Self Care in Daily Lives of Yours?How to Manage Self Care in Daily Lives of Yours?
How to Manage Self Care in Daily Lives of Yours?
StrengthsTheatre
 
Girls Call Bhubaneswar 000XX00000 Provide Best And Top Girl Service And No1 i...
Girls Call Bhubaneswar 000XX00000 Provide Best And Top Girl Service And No1 i...Girls Call Bhubaneswar 000XX00000 Provide Best And Top Girl Service And No1 i...
Girls Call Bhubaneswar 000XX00000 Provide Best And Top Girl Service And No1 i...
rawankhanlove256
 

Recently uploaded (20)

What is Amul milk made of? Why is it unnaturally thick and ...
What is Amul milk made of? Why is it unnaturally thick and ...What is Amul milk made of? Why is it unnaturally thick and ...
What is Amul milk made of? Why is it unnaturally thick and ...
 
God made everyone equal - Woman are not weak - so Go Ahead.pptx
God made everyone equal - Woman are not weak - so Go Ahead.pptxGod made everyone equal - Woman are not weak - so Go Ahead.pptx
God made everyone equal - Woman are not weak - so Go Ahead.pptx
 
UoB biyezheng degree offer diploma Transcript
UoB biyezheng degree offer diploma TranscriptUoB biyezheng degree offer diploma Transcript
UoB biyezheng degree offer diploma Transcript
 
Bournemouth University diploma
Bournemouth University diplomaBournemouth University diploma
Bournemouth University diploma
 
Birmingham City University diploma
Birmingham City University diplomaBirmingham City University diploma
Birmingham City University diploma
 
High Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 ...
High Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 ...High Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 ...
High Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 ...
 
Photographs of Prof. Dr. Ram Sharan Mehta
Photographs of Prof. Dr. Ram Sharan MehtaPhotographs of Prof. Dr. Ram Sharan Mehta
Photographs of Prof. Dr. Ram Sharan Mehta
 
UofM degree offer diploma Transcript
UofM degree offer diploma TranscriptUofM degree offer diploma Transcript
UofM degree offer diploma Transcript
 
Vadodara Girls Call Vadodara 0X0000000X Unlimited Short Providing Girls Servi...
Vadodara Girls Call Vadodara 0X0000000X Unlimited Short Providing Girls Servi...Vadodara Girls Call Vadodara 0X0000000X Unlimited Short Providing Girls Servi...
Vadodara Girls Call Vadodara 0X0000000X Unlimited Short Providing Girls Servi...
 
Mysore Girls Call Mysore 0X0000000X Unlimited Short Providing Girls Service A...
Mysore Girls Call Mysore 0X0000000X Unlimited Short Providing Girls Service A...Mysore Girls Call Mysore 0X0000000X Unlimited Short Providing Girls Service A...
Mysore Girls Call Mysore 0X0000000X Unlimited Short Providing Girls Service A...
 
Taming the Mind Embracing Mindfulness with Mental Noting
Taming the Mind Embracing Mindfulness with Mental NotingTaming the Mind Embracing Mindfulness with Mental Noting
Taming the Mind Embracing Mindfulness with Mental Noting
 
UOL biyezheng degree offer diploma Transcript
UOL biyezheng degree offer diploma TranscriptUOL biyezheng degree offer diploma Transcript
UOL biyezheng degree offer diploma Transcript
 
KCL biyezheng degree offer diploma Transcript
KCL biyezheng degree offer diploma TranscriptKCL biyezheng degree offer diploma Transcript
KCL biyezheng degree offer diploma Transcript
 
7 Rules For A Successful Life presentation by Rohit Chandra Thakur
7 Rules For A Successful Life presentation by Rohit Chandra Thakur7 Rules For A Successful Life presentation by Rohit Chandra Thakur
7 Rules For A Successful Life presentation by Rohit Chandra Thakur
 
The Most Helpful Book Ever Published!!!!
The Most Helpful Book Ever Published!!!!The Most Helpful Book Ever Published!!!!
The Most Helpful Book Ever Published!!!!
 
The Benefits of Mindfulness Practices for Mental Clarity and Focus.pptx
The Benefits of Mindfulness Practices for Mental Clarity and Focus.pptxThe Benefits of Mindfulness Practices for Mental Clarity and Focus.pptx
The Benefits of Mindfulness Practices for Mental Clarity and Focus.pptx
 
Calendar july 2024 planner organization.pdf
Calendar july 2024 planner organization.pdfCalendar july 2024 planner organization.pdf
Calendar july 2024 planner organization.pdf
 
University of Ibershire diploma
University of Ibershire diplomaUniversity of Ibershire diploma
University of Ibershire diploma
 
How to Manage Self Care in Daily Lives of Yours?
How to Manage Self Care in Daily Lives of Yours?How to Manage Self Care in Daily Lives of Yours?
How to Manage Self Care in Daily Lives of Yours?
 
Girls Call Bhubaneswar 000XX00000 Provide Best And Top Girl Service And No1 i...
Girls Call Bhubaneswar 000XX00000 Provide Best And Top Girl Service And No1 i...Girls Call Bhubaneswar 000XX00000 Provide Best And Top Girl Service And No1 i...
Girls Call Bhubaneswar 000XX00000 Provide Best And Top Girl Service And No1 i...
 

Grails Simple Login

  • 1. Grails tutorial Simple login/logout http://khomkrit.wordpress.com
  • 3. Prepare Artifact Create Grails Application > grails create-app simple-login and Create a Controller named user, used to handle user activity such as login and logout. > grails create-controller user
  • 4. Prepare Artifact Create a file named “index.gsp” in grails/views/user/ Directory
  • 5. Custom Login Page Custom the “index.gsp” file created recently
  • 6. Custom Login Page Custom the “index.gsp” file created recently add some style Create HTML textfield for username/password
  • 7. Custom Login Page create a form using <g:form> tag
  • 8. Custom Login Page if you don’t want to use <g:form> tag you can use HTML form instead! Because in finally, Grails will generate plain HTML form to you. I prefer to use <g:form> tag, it’s make sense and give more semantic and info about what controller and what action will accepts from form request. <g:form action=”login”/>
  • 9. Custom Login Page <g:form action=”login”/> send form request to action named “login” and What Controller? If you don’t specify a controller name it will send request to default controller corresponding with the name of file directory. In this situation, index.gsp is in /grails-app/ user/ directory. So, It will send request to user controller.
  • 10. Custom Login Page <g:form controller=”user” action=”login”/> Anyway, You can add the specific controller to which you want to sent request.
  • 11. Start Grails Application by using this command > grails run-app Go to http://localhost:8080/simple-login/user
  • 12. Now, you cannot do anything with the form. If you click the Login button, the error will occurs. Why? Because the target action specified by you in the previous is not created.
  • 13. What is the action specified by you? Back to the login.gsp you will see this...
  • 14. What is the action specified by you? Back to the login.gsp you will see this... Yes, action named “login” will get the form request.
  • 16. Tip You can make most changes, including changes to the domain and controller classes, without having to restart the web server. Sometimes, however, change require a restart. Creating a new controller sometimes requires a restart
  • 17. Let’s create the action All action is declared in the controller file. In this case, you want to send request to controller named “user” and action named “login” go to UserController.groovy to create the “login” action.
  • 18. Custom Controller all Controller is in /grails-app/controllers/ directory
  • 19. Custom Controller Open UserController.groovy and Create an action named “login”
  • 20. Custom Controller Go to http://localhost:8080/simple-login/user/ and Click the Login Button
  • 21. Custom Controller OOP! Grails sent 404 back! Why?
  • 22. Custom Controller By Default, When you call any action, Grails try to search for a file which has name corresponding with the action name called by client. In this case you try to http:/ /localhost:8080/ simple-login/user/login, this url means you try to call action named “login” in the user controller So, Grails try to find a file named “login.gsp” in / grails-app/views/user/ directory for render to client. you don’t have that file!
  • 23. Custom Controller You don’t have the login.gsp file for Grails, It’s make Grails don’t know what should to render back to client. You can use “render” method for tell Grails what it should to render back.
  • 24. Custom Controller Go to http://localhost:8080/simple-login/user/ and Click the Login Button again.
  • 26. Custom Controller You can add some your logic to handle login such as keep login status in the session and send some message back to user like “you have logged in” or “your login failed” in the login action. You can add some logic to handle login here
  • 27. Part III Add some Logic to Handle the Login
  • 28. Validation Add simple validation to check username and password sent from client all parameters sent from client is stored in variable named “params” So, the code will look like this...
  • 29. Validation For testing, go to login page and try to login again. If username is “admin” and password is “pass” then you can login, else cannot.
  • 30. Validation Don’t You want to use ugly responding when user try to login? Next, After user has logged in, the Grails application will redirect user to the login page again and give some info using “flash” variable. About flash scope is out of this tutorial topic but you can investigate that how to use flash through this tutorial.
  • 31. Using flash use flash variable to store some message as the following code and redirect to the login page (index.gsp) .
  • 32. Using flash redirecting user to action named “index” .By default, Grails will search for file named “index.gsp” in grails-app/views/user/ directory. flash message sent to action named “index” by the last command in login action and also through to index.gsp So, You can access the flash message in action named “index” and also access it in “index.gsp”
  • 33. Using flash Add ${flash.message} in login page If it has something in, it will show message To display value in a variable you can use this pattern ${variable-name}
  • 34. Using flash Testing, Go to login page and try to login again. After try to login, you will see value in flash.message sent from login action.
  • 35. Keep Status You can use “session” to keep information about login status. Keep some info by using session variable
  • 36. Handle Logout Create a new action named “logout” to handle when user want to logout. session.user keep status that the user has logged in, so you should clear all info about logged in user. New action
  • 37. Custom Login page Add some logic more, if user has logged in then do not show login form and show a logout link instead. Use <g:if>, <g:else> tag to test something.
  • 38. Custom Login page Using <g:if> tag <g:if test=”${boolean-logic}”> Example: <g:if test=”${5 == 6}”>
  • 39. Custom Login page Creating a link to logout action, you can use <g:link> as the following.
  • 40. Custom Login page Anyway, you can use HTML link tag - <a href=””> , instead. But I prefer to use <g:link> with the same reason of why I prefer to use <g:form> <g:link controller=”” action=””> If you do not specify controller name, Grails will automatic search for controller like <g:form> behavior. <g:link action=””>
  • 41. Check Point! Now you have a login page. If you login succeed, You can see a logout link and the login form has thrown away. If you login fail, the login form still be with you. After you try to login, Whatever the result is fail or succeed have you got. You always see a flash message.
  • 42. Add some more thing Grails has a default CSS and you can use its like the following. Use build in CSS, class=”message”
  • 43. Add some more thing As you can see, the style has applied to flash.message value
  • 44. Add some more thing For another style, you can see in the /web- app/css/ directory Other resource is in /web-app/images/ and web-app/js directory
  • 46. Thank You Sorry about many wrong grammar in this slide :D