Browser back button is showing previous page after logout in Grails - grails

I am using grails-2.4.5 version and spring-security-core-2.0-RC5. I have set a default target URI in config.groovy page. When user login then they can access to that page, when logout no access, should display only login page.
My problem is, when user logout login page is displayed, but if browser back button is hit then the default target page is displayed although he can't access any action. But it odd. My config is given below:
in config.groovy >>
grails.plugin.springsecurity.successHandler.defaultTargetUrl = '/dashboard/index'
grails.plugin.springsecurity.logout.postOnly = false
my url mapping class >>
class UrlMappings {
static mappings = {
"/$controller/$action?/$id?(.$format)?"{
constraints {
// apply constraints here
}
}
"/"(controller:"login", action: "auth")
"500"(view:'/error')
}
}
my default target uri method >>
class DashboardController {
def index() {
}
}

There are many possible ways to stop,
Browser back button is showing previous page after logout
With JavaScript, you can clear location history or disable back button.
<script>
history.pushState(null, null, location.href);
window.onpopstate = function () {
history.go(1);
};
</script>
Demo
Here you will get many possible options
Hope this will helps you.

Related

How to do webix jet navigation?

I am getting an error in webix jet when I navigate the URL.
The first URL is this => http://localhost:8080/#!/navigationBar/topSideBar/appslist
There is a button to call the next view, After I click the button next view URL(second URL) will => http://localhost:8080/#!/navigationBar/qtoApplication
Then, when I go back(by browser back button) to the first URL view, I got the below error, Url is changed but the view is not changing. I cannot go back to the first URL view.
I tried to add a button at the second URL view in order to go back to the first URL. It is also got the same error as per below.
I used navigationBar view as a top view, the rest is a subview.
I would like to know How to do correct navigation.
Thanks in Advance
myapp.js:9836 TypeError: Cannot read property 'linkInput' of undefined
at result._init_onchange (webix.js:30753)
at result.callEvent (webix.js:729)
at result.render (webix.js:2736)
at result.render (webix.js:28077)
at result.$setSize (webix.js:30618)
at result._set_child_size (webix.js:20648)
at result._set_child_size (webix.js:20752)
at result.$setSize (webix.js:20743)
at result._set_child_size (webix.js:20635)
at result._set_child_size (webix.js:20752)
myapp is like this,
// myapp.js
import { JetApp, EmptyRouter, HashRouter } from "webix-jet";
export default class MyApp extends JetApp {
constructor(config) {
const defaults = {
router: BUILD_AS_MODULE ? EmptyRouter : HashRouter,
debug: !PRODUCTION,
start: "/navigationBar/topSideBar/projects"
};
super({ ...defaults, ...config });
}
}
if (!BUILD_AS_MODULE) {
webix.ready(() => {
if (webix.CustomScroll){
webix.CustomScroll.init();
}
new MyApp().render();
});
}

Prevent loading page

I have a controller create and return content where it triggers an alert.
The problem it load an empty page. How can I prevent it to load an empty page and stays in the current view and do nothing just pop the alert.
What I really wanted here is before the user can create new data, it will validate first if the diseaseID is already existing for specific assessmentID, and when the result is null, it will just pop an alert and do nothing. But here I'm just trying make alert() work properly.
Controller:
public ActionResult CreateDisease(int? diseaseID,int? assessmentID, DiseaseList diseaselist)
{
diseaselist.DiseaseID = diseaseID;
diseaselist.AssessmentID = assessmentID;
db.DiseaseLists.Add(diseaselist);
db.SaveChanges();
return Content("<script language='javascript' type='text/javascript'>alert('Item already exist');</script>");
}
You dont need to return the script as content from the controller, just return the values as json that will tell you that the item already exist and based on that true or false value show an alert from the client side js.
your controller code will look something like this
diseaseModel.DiseaseID = diseaseID;
diseaseModel.AssessmentID = assessmentID;
diseaseModel.AlreadyExist = true;
return Json(diseaseModel);

Calling of function of one page from another page in blackberry cascades using qml

In my application I have a main.qml which has a navigation pane that goes to homepage.qml and from there to profilepage.qml. When I come back from profilepage to homepage I need to trigger a function in home page. I noticed that whenever I pop back I get a call onPopTransitionEnded in the main page. Since homepage is pushed from main.qml there is no navigation pane on homepage and I cant access onPopTransitionEnded on homepage. Below are the sample structures of my 3 qml views.
main.qml
NavigationPane {
id: nav
peekEnabled: false
onPopTransitionEnded: {
console.log("POP PAGE from main");
if(page.objectName=="newProfilePage")
{
//I tried to access the function using the homepage id but didnt work
menuScreenPage.reloadView(); // This doesnt work, shows error unknown symbol menuScreenPage
}
page.destroy();
}
Page {
id: mainPage
Container {
//some code
}
onCreationCompleted: {
//Some code and then push to homepage
nav.push(homePageDefenition.createObject());
}
}
}
homepage.qml
Page {
id: menuScreenPage
objectName: "menuScreenPage"
function reloadView() //This is the function that is needed to be called on page pop from profile page
{
//some code
}
Container {
//some code
Button { //a button to push to profile page
id:pushButton
horizontalAlignment: HorizontalAlignment.Right
verticalAlignment: VerticalAlignment.Bottom
onClicked: {
console.log("I was clicked!")
nav.push(profilePageDefinition.createObject());
}
}
}
}
profilepage.qml
Page {
id: newProfilePage
objectName: "newProfilePage"
Container {
//some code
Button { //a button to pop to home page
id:popButton
horizontalAlignment: HorizontalAlignment.Right
verticalAlignment: VerticalAlignment.Bottom
onClicked: {
console.log("I was clicked!")
nav.pop();
}
}
}
}
So is there a way that I can access the function of homepage.qml from main.qml? Or is there any other function like onPopTransitionEnded which I can access on homepage.qml itself when I pop from profilepage? Please advice.
Seems that you created unnamed object with this line:
homePageDefenition.createObject()
If you want to access it later, you should save it in some property, for ex.
property var myHomePage: null
...
myHomePage = homePageDefenition.createObject()
nav.push(myHomePage )
...
myHomePage.reloadView();
Keep in mind that "menuScreenPage" is local name (id), it works only inside homepage.qml and nobody can access it beyond that file.
UPD
You can even use such code:
page.reloadView(); // Use local variable "page" instead of internal id "menuScreenPage"

Joomla setredirect override in save method breaks apply method

I have three toolbar buttons in my edit page of my component (joomla 3.0).
view.html.php
protected function addToolBar()
{
JToolBarHelper::apply('editpage.apply');
JToolBarHelper::save('editpage.save');
JToolBarHelper::cancel('editpage.cancel');
}
This works great. But now when I change the redirect path of my save method in the controller like this...
controller/editpage.php
function save()
{
parent::save();
$this->setredirect(JRoute::_('index.php?option=com_mycom&view=productlist', false));
}
... than by a click on "apply", the user was also redirected to this path. And this is the problem. Without this override method in controller, the apply button works fine. All fields will be saved and the edit page will not leave. So how can I solve that problem?
Both Save and apply method call to the same function of joomla library to save the records. The better way to over come the issue is
view.html.php
protected function addToolBar()
{
JToolBarHelper::apply('editpage.tasktoApply'); // any name other then apply
JToolBarHelper::save('editpage.tasktoSave'); // any name other then save
JToolBarHelper::cancel('editpage.cancel');
}
controller/editpage.php
function tasktoApply()
{
parent::save();
$this->setredirect('ANY CUSTOM REDIRECT AS PER YOUR NEED', false));
}
function tasktoSave()
{
parent::save();
$this->setredirect('ANY CUSTOM REDIRECT AS PER YOUR NEED', false));
}
This would sort out your issue

spring security User details

My application has been developed using jsf2 , primefaces and spring
I want to add user details bar on the above of page
This bar will contain String hello User,
This bar appears only when user logged in
My problem is when access the application again , I see the bar while Logging process isn't performed
Any suggestions ?
The code of set bar visible is :
public String login() {
boolean success = authenticationService.login(mail, password);
if (success) {
signedIn = true;
User user = (User) SecurityContextHolder.getContext()
.getAuthentication().getPrincipal();
String name = user.getUsername(); // get logged in username
System.out.println(">>>>>>>>> login "+name);
setName(name);
return "facultyRating"; // return to
// application
// but being
// logged now
} else {
signedIn = false;
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage("Login or password incorrect."));
return "/pages/securityLogin.xhtml/loginPage.xhtml";
}
this method exists in bean where Jsf2 page "that Contains user info bar" read from it
Thanks
Assuming that the login method is part of a session scoped managed bean, you could use the signedIn property to determine whether or not to show the menu bar using the rendered attribute of the component.
Something like the following:
<h:form id="menuForm">
<p:menubar rendered="#{authMBean.signedIn}">...</p:menubar>
</h:form>
The login method should also update the form where the user bar is placed in order to show it on login success.
org.primefaces.context.RequestContext.getCurrentInstance().update(":menuForm");
It has been solved by making the info bar in separate secured page "Will appear only after Logging in "

Resources