Spring Security grails login redirect - grails

I'm using spring security on my grails app and want to to this:
My Homepage is : http://www.test.com:8080/my-app/ this is the index.gsp
Now I have insert a login form in the index.gsp file:
<form action='${postUrl}' method='POST' id='loginForm' class='cssform' autocomplete='off'>
<p>
<label for='username'><g:message code="springSecurity.login.username.label"/>:</label>
<input type='text' class='text_' name='j_username' id='username'/>
</p>
<p>
<label for='password'><g:message code="springSecurity.login.password.label"/>:</label>
<input type='password' class='text_' name='j_password' id='password'/>
</p>
<p id="remember_me_holder">
<input type='checkbox' class='chk' name='${rememberMeParameter}' id='remember_me' <g:if test='${hasCookie}'>checked='checked'</g:if>/>
<label for='remember_me'><g:message code="springSecurity.login.remember.me.label"/></label>
</p>
<p>
<input type='submit' id="submit" value='${message(code: "springSecurity.login.button")}'/>
</p>
</form>
Now when I insert the username and password I want to redirect to url : http://www.test.com:8080/my-app/customer/list
How can I do this?

This answer should help you: Grails Spring Security: redirect after login success/failure
This question will very likely be considered a duplicate. If you don't mind, before posting a question on SO, run a quick search (here or on Google). :)

Related

After authentication in Spring Security, Grails 3 redirects me to auth.html

I'm implementing a login form like this:
<form action="${postUrl ?: '/login/auth'}" method="POST" id="loginForm" class="cssform" autocomplete="off">
<p>Por favor ingrese sus credenciales:</p>
<div class="form-group" style="color: #2C3E50 ">
<input type="text" name="${usernameParameter ?: 'username'}" id="username" class="form-control input-lg" placeholder="Usuario" required="">
</div>
<div class="form-group" style="color: #2C3E50">
<input type="password" name="${passwordParameter ?: 'password'}" id="password" class="form-control input-lg" placeholder="Contraseña" required="">
</div>
<p id="remember_me_holder">
<input type="checkbox" class="i-checks" name="${rememberMeParameter ?: 'remember-me'}" id="remember_me">
<label> Recuérdame</label>
</p>
<div class="btn-h">
<button type="submit" class="btn btn-azul btn-lg block full-width m-b" id="submit" value='${message(code: 'springSecurity.login.button')}' title="Ingresar al sistema SIIDE-DGAPA">
<i class="fa fa-sign-in"> </i> Iniciar sesión
</button>
</div>
</form>
Authentication works fine, but after logging in, redirects me to auth.html page, I want sent to index.gsp
You can change this url:
application.yml:
grails:
plugin:
springsecurity:
successHandler:
defaultTargetUrl: "/pathToRedirectAfterLogin"
alwaysUseDefault: true
Grails Spring Security plugin is very powerful. There are a huge number of different settings. Read docs: http://grails-plugins.github.io/grails-spring-security-core/
From your question, I suspect you have a bit confused with how spring security works.
Please check out with this tutorial Spring Security Core Tutorial
This tutorial is quite useful
Hope it helps, cheers.

contact us form with email submision in asp.net mvc

I am trying to design the contact us page in asp.net mvc. I would like to build a contact us form that also work as to send email to our email. This is the code in of front end; it is a design of form but I just copy this from a template. Can any body guide me to how to make it work or highlight any mistakes?
//code
<div class="contact-form">
<h2>Contact Us</h2>
<form method="post" action="contact-post.html">
<div>
<span><label>Name</label></span>
<span><input name="userName" type="text" class="textbox"></span>
</div>
<div>
<span><label>E-mail</label></span>
<span><input name="userEmail" type="text" class="textbox"></span>
</div>
<div>
<span><label>Mobile</label></span>
<span><input name="userPhone" type="text" class="textbox"></span>
</div>
<div>
<span><label>Subject</label></span>
<span><textarea name="userMsg"> </textarea></span>
</div>
<div>
<span><input type="submit" class="" value="Submit us"></span>
</div>
</form>
</div>

Grails - %252F in the url

I am using spring security plugin for login in application. The spring security has default auth.gsp page for login. I have created my own auth.gsp page to add additional thing
auth.gsp
<g:form action='${postUrl.encodeAsURL()}' method='POST' id='loginForm' autocomplete='off' class="login-form">
<g:textField class="field" name="username" value="${params.userName}"/>
<g:passwordField class="field" name="password"/>
<button>login</button>
<p class="message">Forgot Password?</p>
<p class="message"><a id="next" name="next" href="#">Have Invitation Code?</a></p>
</g:form>
The problem is that ${postUrl} contains %252F in the url. Here is the complete url: http://localhost:8080/login/%252Flogin%252Fauthenticate/loginForm. I have tried every possible answer given on stackoverflow but nothing worked.
Try using
<g:form url='${postUrl}' method='POST' id='loginForm' autocomplete='off' class="login-form">
<g:textField class="field" name="username" value="${params.userName}"/>
<g:passwordField class="field" name="password"/>
<button>login</button>
<p class="message">Forgot Password?</p>
<p class="message"><a id="next" name="next" href="#">Have Invitation Code?</a></p>
</g:form>
When setting complete urls, you use 'url' attribute. If you use "action", then you must set a action name.
Also don't use encodeAsURL(). encodeAsURL means, you want to escape special characters like '/','?' which are replaced with '%..' entities.

How to make SignUp/Login action in one form

I working on my first ASP.net MVC project and and i got some problems using multiple buttons in one form.
When my user type username&password and then hit login means it will go to welcome page
if user try to Sign Up means it will go to another form field to get Personal information.
and finally all given information need to store in database and redirect user to welcome page .
#using (Html.BeginForm("about", "home", FormMethod.Post, new { #id = "msform" }))
{
#Html.AntiForgeryToken()
#Html.ValidationSummary()
<!-- progressbar -->
<ul id="progressbar">
<li class="active"></li>
<li></li>
<li></li>
</ul>
<!-- fieldsets -->
<fieldset>
<h2 class="fs-title">Create your account</h2>
<h3 class="fs-subtitle">Take 60 Seconds With Us</h3>
<input type="text" name="UsersName" placeholder="Username" />
<input type="password" name="Passsword" placeholder="Password" />
<input type="button" name="next" class="next action-button" value="Sign Up" />
<input type="button" name="next" class="nexts action-login" value="Log In" />
<input type="submit" value="+" />
</fieldset>
<fieldset>
<h2 class="fs-title">Personal Information</h2>
<h3 class="fs-subtitle">We will never share</h3>
<input type="text" name="phone" placeholder="Email" />
<input type="text" name="phone" placeholder="Phone Number" />
<input type="text" name="date" placeholder="Date of Birth" />
<input type="text" name="gender" placeholder="Gender" />
<input type="button" name="previous" class="previous action-button" value="Previous" />
<input type="button" name="next" class="next action-button" value="Next" />
</fieldset>
<fieldset>
<h2 class="fs-title">Make SomeOne Alive</h2>
<h3 class="fs-subtitle">A donor today! A hero tommorow!</h3>
<input type="text" name="fname" placeholder="Blood Group" />
<input type="text" name="lname" placeholder="Are You ?" />
<input type="text" name="phone" placeholder="State" />
<input type="text" name="phone" placeholder="City" />
<input type="button" name="previous" class="previous action-button" value="Previous" />
<input type="submit" name="submit" class="action-button" value="Submit" />
</fieldset>
}
But now that I have a login button placed on my view form, I'm totally lost. I don't know how to make when user click login button means it will redirect ,if signUp means it will redirect to another form. How to implement the form
Give your button names, and then test for their existence in the posted data server-side. Only the one that is clicked will be there:
<button type="submit" name="_SignUp">Sign Up</button>
<button type="submit" name="_LogIn">Log In</button>
Then, in your action:
if (Request.Unvalidated["_SignUp"] != null)
{
// do sign up
}
if (Request.Unvalidated["_LogIn"] != null)
{
// do log in
}
Or, you can alternatively just divine the user's intention, by attempting to retrieve the user object to sign them in, and if you get no match, then doing the signup instead. However, that pretty much makes the buttons unimportant and could result in the user clicking "Sign Up" and actually being logged in, instead, or vice versa. It doesn't really matter, but it's better to manage user's expectations. If they think they don't have an account, but actually do, they might want to know that.

Redirect to a specific site after login via spring security

I have coded a sign up page:
<div class="container">
<div class='fheader'>
<g:message code="springSecurity.login.header" />
</div>
<g:if test='${flash.message}'>
<div class='login_message'>
${flash.message}
</div>
</g:if>
<form action='${postUrl}' method='POST' id='loginForm'
class="form-signin" autocomplete='off'>
<h2 class="form-signin-heading">Please sign in</h2>
<input type='text' class="form-control" name='j_username'
id='username' placeholder="Username" /> <input type='password'
class="form-control" name='j_password' id='password'
placeholder="Password" />
<p id="remember_me_holder">
<input type='checkbox' class='checkbox'
name='${rememberMeParameter}' id='remember_me'
<g:if test='${hasCookie}'>checked='checked'</g:if> /> <label
class="checkbox" for='remember_me'><g:message
code="springSecurity.login.remember.me.label" /></label>
</p>
<!-- <label class="checkbox"> <input type="checkbox"
value="remember-me"> Remember me
</label> -->
<input class="btn btn-lg btn-primary btn-block" type='submit'
id="submit" value='${message(code: "springSecurity.login.button")}' />
</form>
</div>
<!-- /container -->
<script type='text/javascript'>
<!--
(function() {
document.forms['loginForm'].elements['j_username'].focus();
})();
// -->
</script>
Into the page I have integrated the spring-security-core:2.0-RC2 plugin.
However, when I start the server and try to log in with my created users I get nothing. No notification that it worked, no redirect.
In fact I just want to redirect to my main page mapped as "/"(view:"/index") in the URLMappings.groovy
How to change the redirect?
I really appreciate your answer!
In your config file:
grails.plugins.springsecurity.successHandler.defaultTargetUrl="/someController/someAction"

Resources