Umbraco - Redirect from Login to last currentpage - redirect

I'm working in Umbraco and is currently using this code:
#if(Members.GetCurrentLoginStatus().IsLoggedIn) {
Response.Redirect(Request.UrlReferrer.AbsolutePath);
}
In my login-template, so when I click on a protected page, I will be redirected to Login (that works) and then after successfull login be redirected back to the protected page. That works like a charm, but if I'm on Homepage and clicks "log in" and logs in, I get this problem when it is redirecting:
Server Error in '/' Application.
"Object reference not set to an instance of an object.
#if(Members.GetCurrentLoginStatus().IsLoggedIn) {Response.Redirect(Request.UrlReferrer.AbsolutePath);}"
I'm not using Visual Studio, only the CMS itself online so I can't access any controllers and do it myself.
Any Ideas how I can solve this?

Well, if there is no referrer it shouldn't redirect, right? So something like this should do?
#if(Members.GetCurrentLoginStatus().IsLoggedIn && Request.UrlReferrer != null) {
Response.Redirect(Request.UrlReferrer.AbsolutePath);
}

Related

Redirect after login in drupal 8

I'm trying to redirect users after login to the destination set in the url, like : /user/login?destination=my-modules
I'm using this module to redirect to login page instead of showing a 403 page : https://www.drupal.org/project/r4032login
It works well and generates the URL with the '?destination=' parameter but after i login i'm redirected to homepage everytime.
The module is supposed to manage this by itself, but i still tried to create a custom module to do the redirection, i created a custom module and installed it, but nothing happens still.
Here is my code :
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
/**
* Implements hook_form_FORM_ID_alter().
*/
function test_redirect_form_user_login_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$form['#submit'][] = 'test_redirect_user_login_form_submit';
}
/**
* Custom submit handler for the login form.
*/
function test_redirect_user_login_form_submit($form, FormStateInterface $form_state) {
$url = Url::fromRoute('a route');
$form_state->setRedirectUrl($url);
}
How do i properly do this ? Thank you
I know you asked for help with your code. I'm not super good at custom modules.
Maybe this module will help you:
https://www.drupal.org/project/login_destination
I've used it and it's pretty good but may not fit your needs.
Once you install it, you will have the option to set different login destinations for different users found at [mysite.com]/admin/config/people/login-destination
User Redirect (Redirect user after Login or Logout) helps to redirect the user after login or logout activity. This module is compatible to the Drupal latest versions and has full security coverage.

How to redirect to home page in kentico after login in site intead Admin/cmsadministration.aspx?

I'm trying to redirect the users to home page after to log in. I've already added default target URL in the web part also in the template, I tried also by code
else if (!String.IsNullOrEmpty(DefaultTargetUrl))
{
redirectUrl = ResolveUrl("~/Compliance.aspx");
}
I also add a new domain alias with a default alias path but nothing is working.
Instead of using ~/admin as the login page, create your own ~/login page, that can be redirected to anywhere. If you use the default ~/admin it result to /CMSPages/logon.aspx?ReturnUrl=%2fKentico11%2fAdmin%2fcmsadministration.aspx which return URL is the Admin/cmsadministration.aspx

laravel socialite doesnt take GET parameter to redirect on same page

I have a problem with one Laravel plugin
its called Socialite
it allows my site users to loggin with facebook, twitter etc
i need some help
the problem is that after login it redirects to index page and the page visitor initiated login
ogin url /login?redirect=https://www...
socialite doesnt take this GET parameter
default laravel login works with this parameter, but not socialite
i think it doesnt support redirect, because callback URL is set static in config
I cannot figure out how to modify it to take GET paramenter with customs URLs
class SocialAuthController extends Controller {
public function redirect() {
return Socialite::driver('facebook')->redirect();
}
public function callback(SocialAccountService $service) {
$user = $service->createOrGetUser(Socialite::driver('facebook')->user()); auth()->login($user);
return redirect()->to('/home');
}
}
How can i put a dynamic link to this intead of /home SO that it redirects me to the same page where i was before log-in.
redirect()->to('/home')
Laravel Socialite plugin after login with Facebook or Twitter redirects to:
SocialAuthController.php
...
public function callback(SocialAccountService $service, $provider)
....
return redirect()->to('/');
I want to redirect visitor to page where login was initiated and not static page '/'
My login page receives GET parameter /login?redirect=http://www.website.com/dynamic_url
Please make code changes that Socialite plugin redirects after login to dynamically set redirect URL.
It is really easy.I search it by myself.No one replied me so i think it was really embarrisng.
So the solution is return Redirect::to(URL::previous());
A more easy way to do that is just:
return redirect()->back();
Happy coding! :D

How to redirect the user to a custom page when user click "Connect to QuickBooks" button?

So Intuit charges for each active connections to QuickBooks. Therefore, I want to restrict the QuickBooks functionality in my application to premium users only.
Ideally when any user clicks the "Connect to QuickBooks" button and my RequestOAuthToken http handler is called, I want to check if the user is allowed to use QuickBooks. If that is the case, then the normal OAuth flow continue. If the user is NOT allowed, then I want to redirect the user to the upgrade page of my app.
Given that the "Connect to QuickBooks" button opens a new window (at least on desktop, I haven't tried on phone/tablets), the window should get closed, and the main window (my app) should redirect the user to the right page. And actually this is exactly what happens if the normal OAuth flow completes.
Now, I have tried a few different approaches but I couldn't get it working.
1) In my RequestOAuthToken, return a HTTP redirect to the plan page
2) In my RequestOAuthToken, return an html page with javascript logic to redirect to page
3) In my RequestOAuthToken, return HTTP redirect to a page with javascript logic to redirect to page
4) I haven't tried that one but could I somehow intercept the javascript click handler on the Intuit button. I'm not sure if that is an accepted practice.
Here is the piece a javascript I grabbed from the .Net sample:
try
{
var parentlocation = window.parent.opener.location.hostname;
var currentlocation = window.location.hostname;
if (parentlocation != currentlocation)
{
window.location = plansUrl;
}
else
{
window.opener.location.href = window.opener.location.href;
window.close();
}
}
catch (e)
{
window.location = plansUrl;
}
Help me out please.
I don't think you'll be able to do exactly what you're asking, but you can probably come close by taking a different approach.
Rather than trying to redirect them after they click the button, why not try to redirect them before they click it? e.g. when they try to get to the page that has the "Connect to QuickBooks" button it, check if they are a premium user there, and redirect them if they are not.
I don't think you'll be able to redirect them after they click the button because once they click that button, they get kicked over to Intuit's website and it's beyond your control at that point.
Clement, Keith has provided the answer we would want you to pursue. You may not alter the behavior of the Connect To QuickBooks button. It must be used as described in our documentation. Providing a link to a page that shows the Connect To QuickBooks buttons for your premium users and an upgrade message to non-premium users is the way to go.
I highly recommend that you visit http://docs.developer.intuit.com/0025_Intuit_Anywhere/0010_Getting_Started/0040_Publishing_Your_App and review all of the documentation there. If you develop with our guidelines and requirements in mind it will speed up the review process.
Tony Purmal
Developer Relations Engineer
Intuit Partner Platform

Facebook redirect after login

I have read a number of questions and answers, including this one on StackOverflow and none works. My question to all responses I have seen are 'does it work in Safari?'.
I am trying to get this to work with Safari. It works on Chrome and Firefox fine. But in Safari the login screen just freezes and I get the "Unsafe JavaScript attempt to access frame with URL" log message.
I have a canvas app. I want to log the user in and redirect them to a page once they have logged in. I am trying to redirect directly after login. I have tried
setting window.top.location to a facebook url (with some data passed to a signed request as the all_data argument)
setting window.location to a URL with the same domain as my app.
subscribing to the auth.login event and putting the redirect there
putting the redirect in the callback to login
None of these works for Safari. I'm starting to think that there's no way to do it.
function doSomething()
{
FB.login(
function(loginResponse)
{
if (loginResponse.authResponse)
{
window.top.location = "my url"
}
},
{
scope:"some,scope"
}
);
}
}
In response to Nitzan Tomer, here is the equivalent code which doesn't work with Safari but does work with others:
function myThing()
{
FB.login(function(loginResponse)
{
if (loginResponse.authResponse)
{
FB.api('/me', function(response)
{
window.location = "http://my_app.com?x=" + response.xyz;
});
}
},
{
scope:"scopes"
}
);
}
This is not much of a solution to your problem, but more of a "workaround", though it still uses window.top.location but not from a callback so maybe it will work (I'm just not sure where the callback is executed, since it's the fb sdk that executes it, maybe they call it from the fb iframe inside your iframe).
Instead of using client side authentication, you can use the server side flow.
The entire process is happening on the top window, since it starts by you redirecting the user to the oauth dialog using window.top.location.
When the process ends facebook redirects the user to your redirect_uri, and there you can simply redirect the user where ever you want.
I hope this will help.
Also, you should be aware that in the Facebook Platform Policies it states:
13 . The primary purpose of your Canvas or Page Tab app on Facebook must not be to simply redirect users out of the Facebook experience
and onto an external site.
It turns out the problem was occurring slightly earlier in the login process and the callback never got called. I did set a breakpoint in the callback (which wasn't called) but I thought the breakpoint might not work for some reason (perhaps because it was being executed in the context of another window).
Anyway, the problem was that the channel file (which the docs seem to suggest are optional) wasn't working properly, and this caused a problem with Safari but not with other browsers.