returnurl() always return index.php in yii - yii

I created a module Admin in yii.
If I request any page in this module before login it will redirect to login page. But after successful login it rediect to the site/index. This is the code for redirection.
if($model->validate() && $model->login())
{
$this->redirect( Yii::app()->user->returnUrl );
}
when I print Yii::app()->user->returnUrl, it shows /
thanking you for help.

Related

How to send destination parameter in URL when redirecting user if not logged in?

I'm making a redirection on the login required pages.
If user is not logged in and he/she tried to open the login required page directly then he or she will be redirected to the login page with a destination parameter
Like this:-
https://localhost/example-app/login?destination=login-required-page
And when it will redirect to login page then there will be check of destination at the top of the file
//LOGIN CHECK
login_required_page.php :-
if(empty($user_id)) {
redirect(BASE_URL . '/login? destination=' . $page_section);
//page section is the page type ex. Login, signup, settings
}
Here is config file that contains the redirect function:-
function redirect($destination) {
header("Location: " . $destination);
}
Here is the login page redirection block :-
if($_GET['destination'])) {
$destination = $_GET['destination'];
redirect(BASE_URL . '/' . $destination);
//Only for checking I don't added redirection button onclick
//Added redirection at top of the page so that I can check it's working fine or not
}
And the error is coming on the login page.that localhost redirected you so many times and page is not able to open!
Please help me to resolve this problem

How to Redirect back to the failed Resource after successful authentication with Auth0

When unauthenticated user trying to access Resource the authProvider function is called with FETCH_ERROR type:
if (type === AUTH_ERROR) {
const { status } = params;
if (status === 401 || status === 403) {
return Promise.reject();
}
}
Status 401 or 403 triggering the authProvider() with AUTH_LOGOUT type and then redirection to /login page.
The login page calls the auth0-js.authorize() method, which redirects to the auth0 authentication page and, after authentication, redirects back to the login page.
Which is the right way to do redirect back to failed Resource after successful authentication on login page?
userLogin(payload, pathName) is called, but how to restore path to failed Resource?
Should it be saved to localStorage on AUTH_ERROR?

Express js Redirect not rendering page

I am trying to redirect the user that uses my website after he has logged into his account, he will be redirected to a dashboard.
The problem is that I can see a request for the /dashboard route in the Network tab of the browser Inspection Tools, but the page never loads.
This is my code so far.
router.post('/login', function(request, response){
// verify against database and send back response
var userData = {};
userData.email = request.body.email;
userData.password = request.body.password;
userData.rememberPassword = request.body.rememberPassword;
// check if in the database and re-route
var query = database.query('SELECT * FROM users WHERE email = ?', [userData.email], function(error, result){
if(error){
console.log('Error ', error);
}
if(result.length){
// check if the password is correct
if(userData.password === result[0].password){
// redirect to the dashboard
// TODO this piece of code does not redirect correctly
response.redirect('/dashboard'); // < HERE
console.log('Haha');
}
}
else{
// do something when there is are no results
// invalid email status code
response.statusCode = 405;
response.send('');
}
});
});
And this is the route towards the dashboard, and it is being rendered properly when accessed in the browser.
router.get('/dashboard', function(request, response){
response.render(path.resolve(__dirname, 'views', 'dashboard.pug'));
});
Why can't it redirect when the user completes the login process?
Thanks.
The issue can be in the frontend and not in the backend. If you are using AJAX to send the POST request, it is specifically designed to not change your url.
Use window.location.href after AJAX's request has completed to update the URL with the desired path.But the easiest way would be to create a form with action as /login and use the submission to trigger the url change.
To make sure that the problem does not lie with the backend,
Add a logging statement to router.get('/dashboard' to verify if
the control was passed.
Check that the HTTP status code of the /login route is 302 indicating a redirect and location header has the route /dashboard.
Content type of response /dashboard is text/html.If not please set it using res.setHeader("Content-Type", "text/html").

How do correctly authorise a Facebook App

I am creating a basic Facebook app, and when a user without permission visits the app, they are redirected to the authorisation page. However, the page doesn't display, and I see the following error.
This content cannot be displayed in a frame
Opening it in a new window then shows the authorisation page for my app. Clicking 'Go to App' then takes me to the App, but in it's own window, away from Facebook. Going back to FB and reloding the App page now works.
Stranger yet, when I am logged out and go to my app page, I get a Facebook 404 page (4oh4.php).
I'm guessing that I am doing this wrong somehow, so can anyone see anything obvious wrong with my script? Thanks.
To see what is happening - http://apps.facebook.com/dyne_drewett_news/
<?php
require 'fb/facebook.php';
$fbconfig['appUrl'] = 'my-app-url'; // Create An instance of our Facebook Application.
$facebook = new Facebook(array(
'appId' => 'my-app-ID', // Entered correctly in actual script
'secret' => 'me-app-secret', // Entered correctly in actual script
'cookies' => 'true',
));
// Get the app User ID
$user = $facebook->getUser();
if($user) :
try{ // If the user has been authenticated then proceed
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e){
error_log($e);
$user = null;
}
endif;
// If the user is authenticated then generate the variable for the logout URL
if($user) :
$logoutUrl = $facebook->getLogoutUrl();
?>
<!-- My HTML goes here -->
<?php
else :
$loginUrl = $facebook->getLoginUrl();
header('Location: '.$loginUrl);
endif;
?>
Because you are working in an iframe, you'll have to execute JavaScript redirects. Only that way will you be able to redirect the top most frame -
echo "<script language=javascript>";
echo "top.location.href ='".$url."';";
echo "</script>";
exit();
This is the only way to do complete redirects within a Facebook application. Any other redirect (with PHP for example) will only redirect the user within the iframe...

Rails 3 with Devise - Unauthorized redirect with jQuery Mobile

Application controller:
I use view inheritance instead of a different format (like :mobile)
before_filter :subdomain_view_path
def subdomain_view_path
prepend_view_path "app/views/mobile" if request.server_name.include?("mobile") || request.user_agent =~ /Mobile|iPad/
end
Shows controller
class ShowsController < ApplicationController
before_filter :authenticate_user!
end
When I go directly to /shows in my browser, I get redirected to the login page correctly.
However, I get a 401 Unauthorized when clicking a link (ajax) to that page.
How can I solve this? It would be cool to keep this ajax loading of pages.
Putting this in you application.js may help you:
// Set up a global AJAX error handler to handle the 401
// unauthorized responses. If a 401 status code comes back,
// the user is no longer logged-into the system and can not
// use it properly.
$.ajaxSetup({
statusCode: {
401: function() {
// Redirect the to the login page.
location.href = "/login";
}
}
});
Source: http://rubythings.blogspot.de/2011/10/ajax-redirects-with-devise.html