Grails - %252F in the url - grails

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.

Related

Grails form validation on client

I have the following domain class and gsp and can't seemed to work for validation on client gsp side.
The domain class:
class User {
String username
String password
String emailAddress
static hasMany = [memberships: Membership]
}
The form gsp:
<div class="error-details">
<g:hasErrors bean="${user}">
<ul>
<g:eachError var="err" bean="${user}">
<li>${err}</li>
</g:eachError>
</ul>
</g:hasErrors>
</div>
<form action="${raw(createLink(controller:'purchase', action:
'createSubscription'))}" method="POST">
<input type="text" name="username">
<input type="text" name="password">
<input type="text" name="emailAddress">
</form>
Is there anything I've missed out?
You should use the built in Taglibs for rendering fields. Don't use standard HTML. This way you allow Grails to determine the constraints based on your domain class.
You didn't specify the version of grails you're running:
The latest version 3.3.x uses the fields plugin, please see https://grails-fields-plugin.github.io/grails-fields/latest/ref/Tags/field.html
<f:field bean="user" property="username"/>
<f:field bean="user" property="password" />
<f:field bean="user" property="emailAddress"/>
or just use this
<f:all bean="user"/>
Which will render all the attributes of user.
Make sure you update your domain and include the following constraint
static constraints = {
password password: true
}
Additional constraints are possible. Please see https://docs.grails.org/latest/ref/Constraints/Usage.html
In older version of grails, please see https://grails.github.io/grails2-doc/2.4.3/ref/Tags/field.html
<g:field type="text" name="username" value="${userInstance?.username}"/>
<g:field type="password" name="password" value="${userInstance?.password}"/>
<g:field type="text" name="username" value="${userInstance?.username}"/>

Get method : form input not in url

I am doing my first ASP.NET mvc project, on the home page, Index.cshtml, I have a small form:
<form action="ChoixFormulaire" method="get">
<fieldset>
<label>NAS</label>
<input id="nas" type="text" placeholder="###"/>
<br />
<label>Date of birth</label>
<input id="date" type="text" placeholder="AAAA-MM-JJ"/>
<br />
<label>Employee number</label>
<input id="numEmployee" type="text" placeholder="######"/>
<br />
</fieldset>
<input type="submit" value="Soumettre" onclick="return VerifierFormulaire()" />
</form>
When the button is clicked, there is some verification made in the 'VerifierFormulaire()' method, which is defined in the same Index.cshtml file. Then the ChoixFormulaire.cshtml is displayed (called from the ChoixFormulaire() method in my HomeController, which returns View()).
I was expecting the form inputs to be in the URL as parameters. For example, If I enter '123' for NAS, '1989-01-01' for date of birth and '123456' for employee number, I am redirected to http://localhost:15778/Home/ChoixFormulaire? but I would expect to be redirected to http://localhost:15778/Home/ChoixFormulaire?nas=123&dateBirth=1989-01-01&numEmployee=123456
Try adding the name attribute:
<input id="nas" name="nas" />

Spring Security grails login redirect

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). :)

unable to display the validation messages from #Html.ValidationSummary() in MVC view

I have a fairly simple form created in a partial view and loading the form on a jquery dialog. The view is tightly bound to a model. When the user clicks on the submit button with out entering any inputs, I need to show the validation messages.
<div>
<form method="post" enctype="multipart/form-data" id="ssimForm" action="Home/ProcessUploadedFile"
onsubmit="return false;">
<div>
<h3>
Select the file to be uploaded :</h3>
<span>
<input type="file" name="UploadFileName" id="UploadFileName" /></span>
</div>
<div>
<h3>
Select the date range :</h3>
<span class="uslabel">From Date(MM/dd/yyyy): </span>
<input class="usdate" id="usfromdate" name="StartDate" type="date" />
<span class="uslabel">To Date(MM/dd/yyyy): </span>
<input class="usdate" id="ustodate" name="EndDate" type="date" />
</div>
<div>
<br />
<input type="submit" id="submitButton" name="submitButton" value="Process File" />
</div>
#Html.ValidationSummary()
<div class="message-success">
<span>#ViewBag.Confirmation</span>
</div>
<div class="message-error">
<span>#ViewBag.Error</span>
</div>
</form>
</div>
Now comes the actual problem. when I submit the form I am able to see the validationSummary object populated with the messages, but they are not getting rendered on the screen.
I am able to see the messages if I replace the content of the dialog with the response from the jquery ajax call, that fetches the entire view from the server side. I do not want to take this approach as I beleive this is not the correct way to return validation summary in MVC.
Am I missing something? Any help is appreciated.
I don't know why you don't have the #using (Html.BeginForm()) { } block.
Here is my blog post for a quick and easy way to set up Validation Summary + Unobtrusive Validation for MVC3+.
http://geekswithblogs.net/stun/archive/2011/01/28/aspnet-mvc-3-client-side-validation-summary-with-jquery-validation-unobtrusive-javascript.aspx

How to add a filter to Active Admin dashboard?

I want to add search functionality for a couple of my models on the Active Admin Dashboard page. How do I do that?
For a regular model I can do that using "filter", but how do I do that on Dashboard view. What are the methods available within section and ActiveAdmin::Dashboards.build?
Adding how I did it (following advice from Sjors), so that someone else may find it useful:
in dashboards.rb:
section "Search User", :priority => 4 do
div do
render "search_user"
end
end
in views/admin/dashboard/_search_user.html.erb (Copied HTML of the user filter using firebug):
<div class="panel_contents">
<form method="get" id="q_search" class="filter_form" action="/admin/users" accept-charset="UTF-8">
<div class="filter_form_field filter_string">
<label for="q_email" class=" label">Search Email:</label>
<input type="text" name="q[email_contains]" id="q_email" />
<input type="submit" value="Go" name="commit" id="q_submit" />
</div>
</form>
</div>

Resources