I have a http get request from client angular to server
If the request returns a 404, the app gets redirected to the default page which is my home page.
How do I prevent the redirect on the error function handle therE?
$http({
method: 'POST',
url: '/customers/' + customer.id + "/addresses",
data: address
})
.success(function(address){
})
.error(function(data){
//prevent the 404 redirect here
});
Related
I'm trying to setup a defaultSuccessUrl using Spring security and AngularJS, but after a success login the html page is loaded in the network but not displayed.
here is my security config
http
.authorizeRequests()
.anyRequest().authenticated().and()
.formLogin()
.loginPage("/")
.loginProcessingUrl("/")
.successHandler(this.authSuccess)
.failureHandler(this.authFailure).permitAll()
.defaultSuccessUrl("/app/components/hello.jsp", true);
http
.authorizeRequests()
.anyRequest().authenticated().and()
.logout()
.logoutSuccessHandler(this.logoutSuccess)
.deleteCookies("JSESSIONID")
.invalidateHttpSession(false).permitAll();
but when I chec the network I can see that post request for the login was redirected with 302 status code and Hello.jsp was loaded with 200 Status
however I still have the login page displayed and not the hello.jsp page.
Angular service for login :
this_.login = function(data) {
return $http.post(_contextPath + '/',
"username=" + data.username + "&password=" + data.password, {
headers : {
'Content-Type' : 'application/x-www-form-urlencoded'
}
}).success(function(response) {
return response.status;
}).error(function(response) {
return response.status;
})
};
Any one knows why?
You are using the ajax to post the login form, so the page can't redirect to the success url, you can return the default url and then redirect to the url at the front end. like this
On click of a button I send a post request to express through angularjs. In express' post, I redirect to another url. But nothing happens.
When I give a non-existing url, in the console I see a 404 error. When I give a correct existing url, it does absolutely nothing. Doesn't show any error either.
The express code:
app.get('/login',function(request,response){ //the file sent when /login is requested
response.sendFile(__dirname+"/staticFolder/view/login.html");
})
app.post('/loginCheck', function(req, res, next) { //called by angular controller when button clicked
res.redirect('http://localhost:4000/'); //supposed to show index.html
});
app.get('/',function(request,response){
response.sendFile(__dirname+"/staticFolder/view/");
})
The controller:
.controller('loginController',function($scope,$http){
$scope.login=""
$scope.password="";
$scope.mysqlError="";
$scope.loginFunc = function(){
$http({
method:'POST',
url:'/loginCheck',
data:{
login: $scope.login,
password: $scope.password
}
})
.then(function successCallback(response) {
if(response.data=='invalid'){
$scope.mysqlError="mysqlError";
}
});
}
})
I am working on a token implementation into Angular/.Net application. My part is the front-end. What's happening is that when UI sends a request with the expired token and the server replies with 401 I cannot intercept that before the Browser raises the Login form. As the result I cannot send a request to refresh the token. Can someone please give me an idea how that is supposed be managed? I will provide code just don't know what's to show.
Thanks
Adding code:
var response = $http({
method: "GET",
dataType: "json",
params: params,
headers: {
'Content-Type': "application/xml; charset=utf-8",
},
url: someurl
});
response = response.then(function (data) {
return data.data;
});
response.catch(function (data) {
$q.reject(data);
});
// Return the promise to the controller
return response;
The problem is that I cannot redirect on UI because Browser throws Login form before my code is hit when the server returns 401.
Make ajax request, and if you get 401 then redirect to login page.
P.s. for better understanding provide your code how you implement ajax request. Which module do you use for front-end auth? I recommend satellizer
Added:
I guess you need the following configuration on angular
var app = angular.module('App', ['satellizer'])
.config(function() {
/* your config */
}
.run(function($rootScope, $location, $auth) {
// Check auth status on each routing,
// Redirect to login page, if user is not authenticated or if token expired
$rootScope.$on('$routeChangeStart', function(event, next, current) {
if (!$auth.isAuthenticated()) {
$location.path('/auth/login');
}
});
});
I am using Revel + angular for my application. The index page is the login interface, and once you are successful, you should be directed to the dashboard.html page. The problem is once I have made a POST request, I get a GET request with my 'response body', however, I am still in the login page. I am using angular to make a post request to my restful server. However, whenever I make a POST request I get status 302 on my POST request but my GET request fetches the response for the page.
My Angular Controller
appMainLogin.controller('MainLoginForm',function($scope, $http){
$scope.user_email = null;
$scope.user_pass = null;
$scope.user_remember = true;
$scope.userLogin = function () {
var val = {
"user_email": $scope.user_email,
"user_pass": $scope.user_pass,
"user_remember": $scope.user_remember,
};
var stringify = JSON.stringify(val);
$http({
url: '/login',
method: 'POST',
data: stringify || '',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
}
}).success($scope.getEmailData).error($scope.httpError);
alert("error");
};
});
My routes
POST /login App.Login
GET /dash Dash.Index
I get this: 302 on the POST request
I get this: 200 OK on the GET request
On the 'response body' of the GET request (firefox debugger) I see my I intended html page but I still remain in the index page.
Why is my app not redirecting to the dashboard.html(index.html->dashboard.html) after the user enters their login credential (based on my code above)?
I have an ExtJS application on top of a Django application, and I need to post to /accounts/logout/ in order to invalidate the session and then redirect to /.
The code below runs locally but fails on the live site, which has SSL. I have an issue with doing the Ajax POST via ExtJS. The code is the following:
Ext.Ajax.request({
url: '/accounts/logout/',
withCredentials: true,
method: 'POST',
success: function() {
console.log('successfully logged out');
window.location.href='/'
}
});
The response status in Chrome is (cancelled) as shown in this screenshot:
In addition I get this warning at console level:
The page at https://domain.example.com/ displayed insecure content
from http://console.pharmacy.com.mt/.
Am I missing some config object with the Ext.Ajax request above?
try removing withCredentials: true
Ext.Ajax.request({
url: '/accounts/logout/',
method: 'POST',
success: function() {
console.log('successfully logged out');
window.location.href='/'
}
});