Redirect to a specific site after login via spring security - grails

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"

Related

Using ajax in thymleaf, update only part of form

I use SpringBoot, Thymeleaf.
I want to update the value only for part of form in update page.
<form id="form" class="needs-validation col-sm-6" th:action="#{'/user/edit/' + ${userInfo.id}}" th:object="${userInfo}" method="post" novalidate>
<input type="hidden" name="_method" value="put"/>
<input type="hidden" name="id" th:value="${userInfo.id}"/>
<div class="form-group">
<label for="name">Name</label>
<h4 id="name" th:text="${userInfo.name}" th:value="${userInfo.name}"></h4>
<input type="hidden" name="name" th:value="${userInfo.name}"/>
</div>
<hr>
<div class="form-group">
<label for="nickname">Nickname</label>
<input id="nickname" type="text" name="nickname" th:value="${userInfo.nickname}" placeholder="enter nickname" required minlength="2">
</div>
<hr>
<div class="form-group">
<label for="volunteerTime">Volunteer Time</label>
<span id="volunteerTime" th:text="${userInfo.volunteerTime}+'hour'" name="volunteerTime" th:value="${userInfo.volunteerTime}"></span>
<input type="text" size="5px" placeholder="hour"/>
<button type="button" name="action" value="plus" onclick="ajax()">plus</button>
<button type="button" name="action" value="minus" onclick="ajax()">minus</button>
</div>
<div class="form-group">
<input type="submit" value="update">
</div>
</form>
The "volunteerTime" section of the above code seeks to update and show values added to existing data according to the number entered.
The same goes for Minus.

How to use taghelpers for not rendering server side request in form validation

When I post the following form, it requests server. How can I stop it from posting to server and validate in client side using jquery validation?
Here is my code:
<form asp-controller="Gigs" asp-action="Create" method="post">
<div class="form-group">
<label asp-for="#Model.Venue"></label>
<input asp-for="#Model.Venue" class="form-control" />
<span asp-validation-for="#Model.Venue"></span>
</div>
<div class="form-group">
<label asp-for="#Model.Date"></label>
<input asp-for="#Model.Date" class="form-control" />
<span asp-validation-for="#Model.Date"></span>
</div>
<div class="form-group">
<label asp-for="#Model.Time"></label>
<input asp-for="#Model.Time" class="form-control" />
<span asp-validation-for="#Model.Time"></span>
</div>
<div class="form-group">
<label asp-for="#Model.Genre"></label>
<select asp-for="#Model.Genre" asp-items="#(new SelectList(Model.Genres, "Id", "Name"))" class="form-control"><option>Please Select One</option></select>
<span asp-validation-for="#Model.Genre"></span>
</div>
<button type="submit" class="btn btn-primary">Save</button>
</form>
I tried this but didn't work
<environment names="Development">
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
</environment>

Can't select checkbox using id in Capybara

There is the following RSpec code:
describe 'with valid information' do
it 'should create a new restaurant' do
visit new_restaurant_path
fill_in I18n.translate(:name), with: "Some restaurant"
fill_in I18n.translate(:address), with: "Some address of the restaurant"
fill_in I18n.translate(:average_check), with: 100
check('place_restaurant_food_types_1')
expect { click_button :submit }.to change(Restaurant, :count).by(1)
end
end
But I always get error "cannot check field, no checkbox with id, name, or label 'place_restaurant_food_types_1' found". I tried to replace id for name, but it was still the same. I'm absolutely sure that there is the item with needed id! (I copied it from the page source). How can I fix it?
HTML:
<form accept-charset="UTF-8" action="/restaurants" class="new_place_restaurant" id="new_place_restaurant" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="authenticity_token" type="hidden" value="7yQCirO7MLO6e+Nj46eCSNUjQWd67MJVDIHmUV6/5Y0=" /></div>
<div class="row">
<label for="place_restaurant_name">Название</label>
<input id="place_restaurant_name" name="place_restaurant[name]" size="30" type="text" />
</div>
<div class="row">
<label for="place_restaurant_address">Адрес</label>
<input id="place_restaurant_address" name="place_restaurant[address]" size="30" type="text" />
</div>
<div class="row">
<label for="place_restaurant_average_check">Средний чек</label>
<input id="place_restaurant_average_check" name="place_restaurant[average_check]" size="30" type="text" />
</div>
<div class="row">
<input id="place_restaurant_food_types_1" name="place_restaurant[food_types][1]" type="checkbox" value="1" />
<label for="place_restaurant_food_types_1">Восточная кухня</label>
</div>
<div class="row">
<input id="place_restaurant_food_types_2" name="place_restaurant[food_types][2]" type="checkbox" value="1" />
<label for="place_restaurant_food_types_2">Национальная кухня</label>
</div>
<div class="row">
<input id="place_restaurant_food_types_3" name="place_restaurant[food_types][3]" type="checkbox" value="1" />
<label for="place_restaurant_food_types_3">Японская кухня</label>
</div>
<div class="row">
<input id="place_restaurant_food_types_4" name="place_restaurant[food_types][4]" type="checkbox" value="1" />
<label for="place_restaurant_food_types_4">Китайская кухня</label>
</div>
<div class="row">
<input id="place_restaurant_food_types_5" name="place_restaurant[food_types][5]" type="checkbox" value="1" />
<label for="place_restaurant_food_types_5">Европейская кухня</label>
</div>
<div class="row">
<input id="place_restaurant_food_types_6" name="place_restaurant[food_types][6]" type="checkbox" value="1" />
<label for="place_restaurant_food_types_6">Кавказская кухня</label>
</div>
<div id="map_canvas"></div>
<input id="latitude" name="place_restaurant[latitude]" type="hidden" value="54.352271" />
<input id="longitude" name="place_restaurant[longitude]" type="hidden" value="48.52652" />
<div class="row">
<input id="submit" name="commit" type="submit" value="Сохранить" />
</div>
</form>
You could just use
check("place_restaurant_food_types_1")
as shown in the docs:
The check box can be found via name, id or label text.
Try By Xpath like this
find(:xpath, "//*[#id='place_restaurant_food_types_1']").click
You can use like this
find(:css,"input[id='place_restaurant_food_types_1']").set true

Jquery Mobile Dialog with Form

I have a JQuery Mobile dialog with a form on it:
<form action="send" method="post">
<input type="text"/>
<input type="submit" />
</form>
What I want is that when the form is submitted, I just want to close the dialog or go back to the previous page. How to do it with JQM.
Try adjust next sample to your solution:
<div data-role="popup" id="popupLogin" data-theme="a" class="ui-corner-all">
<form>
<div style="padding:10px 20px;">
<h3>Please sign in</h3>
<label for="un" class="ui-hidden-accessible">Username:</label>
<input type="text" name="user" id="un" value="" placeholder="username" data-theme="a" />
<label for="pw" class="ui-hidden-accessible">Password:</label>
<input type="password" name="pass" id="pw" value="" placeholder="password" data-theme="a" />
<button type="submit" data-theme="b">Sign in</button>
</div>
</form>
</div>

Buttonset does not work anymore after adding div's

With succes I've created a page that uses the set of radio buttons that are formatted jquery. But as soon as I add the div's need to position the content on the page, the radio buttons are still formatted, but do not act as radio buttons anymore (they act like checkboxes). This is my code, what's wrong with it?
<script>
$(document).ready(function() {
$("#dt_hel").buttonset();
});
</script>
<!-- end script radiobuttons -->
<div class="demo">
<div id="ContentContainerLeft" >
<form id="dt_this_form" name="dt_this_form" action="this.php" method="post">
<p>
</div>
<div id="ContentContainerMiddle" >
<P>
<div id="dt_hel" style="font-size:80%;">
<input type="radio" id="radio1" name="dt_hel" value="0" /><label for="radio1">Lower</label>
<input type="radio" id="radio2" name="dt_hel" value="1" /><label for="radio2">Equal</label>
<input type="radio" id="radio3" name="dt_hel" value="2" checked/><label for="radio3">Higher</label>
</div>
<P></P>
</div>
<div id="TweetContainer" >
<P>
</div> <!-- end tweetcontainer -->
</div><!-- End demo -->
</form>
If you follow the rule of closing the most recent tag before closing older tag (ie set the form opening tag above the tag) then it should work e.g.
<form id="dt_this_form" name="dt_this_form" action="this.php" method="post">
<div class="demo">
<div id="ContentContainerLeft" >
<p>
</div>
<div id="ContentContainerMiddle" >
<P>
<div id="dt_hel" style="font-size:80%;">
<input type="radio" id="radio1" name="dt_hel" value="0" /><label for="radio1">Lower</label>
<input type="radio" id="radio2" name="dt_hel" value="1" /><label for="radio2">Equal</label>
<input type="radio" id="radio3" name="dt_hel" value="2" checked/><label for="radio3">Higher</label>
</div>
<P></P>
</div>
<div id="TweetContainer" >
<P>
</div> <!-- end tweetcontainer -->
</div><!-- End demo -->
</form>

Resources