Stencil redirect after login - bigcommerce

Is there a good way to redirect to a specific page using Stencil right after logging in? It defaults to the my account, but want to send to main shop page. I know login.php?from= works, just not sure how to enforce that and looking for a better way.

I'd recommend a javascript redirect based on the referring URL, though it isn't ideal. There isn't a store setting to accomplish this.
if (document.referrer !== "http://www.stackoverflow.com") {
window.location.href = "http://www.google.com";
}
There are alternative scripts to accomplishing this that can be found if you look for "redirect by referring url" or "redirect based on previous page".

Related

Nuxt.js: how to redirect inside methods

I'm learning Nuxt.js and I'm puzzled by how difficult it seems to be to simply redirect a user to another page from a method that is triggered via a click.
Here is the set up: I'm using Nuxt Auth to authenticate users, once authenticated I want them to be forwarded away from the signup page to another route. I already have middleware set up that redirect logged-in users, but it is only triggered when I refresh the page, not when I first log them in.
I have a method like this:
async login(event) {
event.preventDefault()
try {
await this.$auth.loginWith('local', this.loginData)
// this is where my redirect logic should go
} catch(error) { ... }
}
So far I've tried using this.$nuxt.refresh() which doesn't do anything at all and I've also tried this.$router.push('/route') which seems to hang the page completely. Ideally, I would prefer the refresh approach so that I don't have to specify the landing page for logged in users in multiple places, but I also need to know how to use redirections inside methods, I would have thought it should be the most simple operation imaginable and yet it seems to be difficult to find.
Any tips would be highly appreciated!
UPDATE:
I've found a solution, although it's not an ideal one. I've added an if-statement into beforeCreate that checks this.$auth.loggedIn and if it's true, then it calls this.$auth.redirect('home') when "home" is defined in nuxt.config.js under auth redirect. The reason this solution is not ideal is that it relies on the auth module (as opposed to being a general redirect mechanism).
There's a way in Nuxt to reload the page like so:
this.$router.go(0)
also you can find more information here
if this.$router is not working, try this
this.$nuxt.$options.router.push(url);

Prestashop logout user programmatically

I am developing a module in Prestashop. I want to know how to logout user programmatically, and how can I redirect a user to custom url?
You can use
$customer->logout();
Or
$customer->mylogout();
The first one is a complete logout, the second one will leave affiliate information in customer's cookies.
Both methods fire actionCustomerLogoutBefore and actionCustomerLogoutAfter hooks, so you can attach to them for your redirect.
Speaking of redirect - it depends on what page you want to redirect your customers to, if it's an internal page, you can use either:
$redirect_link = Context::getContext()->link->getPageLink(...); // or "getModuleLink", etc., see classes/Link.php for details.
Or
$redirect_link = $this->context->link->getPageLink(...);
You would then use either redirect, redirectLink or redirectAdmin (probably the other two, as redirectAdmin only makes sense if you're in Back Office) of Tools class to redirect to that link.

Yii how to redirect to particular URL

I have used url beautifier to remove index.php?r= from URL. it works fine.
now i want user to redirect to URL if user hits particular url.
suppose
http://localhost/xm/xmds.php?wsdl
To
http://localhost/xm_demo_menu/WebService/service
how to achieve this. i search lot on google but not found material relevant to my problem
any suggestions ?
I do not see where the problem should be. See documentation
In you controller, simply call:
$this->redirect("http://localhost/xm_demo_menu/WebService/service");

Apache rewrite for 404: getting the requested url

On my error page that I redirect to for any 404s, I'd like to record the url that the user tried to get to.
I've tried this but it doesn't work:
ErrorDocument 404 /error/?url=%{HTTP_REFERRER}
Can anyone tell me how to do it?
Try it with %{REQUEST_URI}. I'm not certain this will work in ErrorDocument since I've never tested it, but it's worth trying.
ErrorDocument 404 /error/?url=%{REQUEST_URI}
There isn't a direct way. Nor a perfect one. But there are few workarounds with PHP.
For example, I currently use a function to create the links of each page. So I would just need to add file_exists() to the main function (few lines in a single function).
This is the function I would use to create urls:
function url ($Value)
{
// Do some stuff with the url
// [Not showed]
if (!file_exists("/internal/path/".$Value))
{
// Call a function to store the error in a database
error ("404", $Value);
// One way of handling it. Replace '/' for ' ' and search that string.
// Example: "path/to/page" would become "path to page".
$Value=str_replace("/","%20",$Value);
return "http://www.example.com/search=".$Value;
}
else
{
// If the page exists, create the normal link.
return $FullUrl;
}
}
This is my regular way of creating an urls:
<?php url('path/to/page'); ?>
I just thought about this method. It's great as it allows you to find missing pages even IF the user doesn't click on the links. Thank you for making me think about it and now I'll use it in my page (:
Another 'simpler' method (in case you do not wrap links) is that you store last couple of pages visited in $_SESSION['lastpage']; and $_SESSION['lastlastpage'];, if 404 is found then store the corresponding page from which the user tried to access the broken page. It's not a perfect solution since you have to manually find the broken link in the previous page, but at least it gives you some idea of where it is.
Disadvantage: As you can see, both solutions ONLY work with internal broken links.
It would seem there isn't a way.

How do I change the default landing page in a Trac wiki?

A default Trac installation will display the WikiStart page as its home page. I'd like it to display another page. How do I do that? I was unable to find anything with Google, as any request with "Trac" in it will return links to every opensource project that uses Trac.
If you want to keep the "Welcome to Trac" page, have you considered simply migrating that content to a new page and then editing WikiStart? Trac documentation upgrades leave the WikiStart page unchanged (as documented here), so you aren't making trouble for yourself in that regard.
Are you wanting to display a different wiki page, or a different kind of page? I don't know of a config option for the former, but you can use [trac] default_handler in your trac.ini to make, say, the custom query page be the default page.
Edit: Taking a quick glance over the sources, WikiStart is pretty well hard-coded as the start page for the wiki. So, short of patching Trac, I don't think you can do what you're after.
It seems there's no hope in overriding /wiki URL path to render a wiki page other than WikiStart. That's hardcoded by design (maybe for a very good reason).
On the other hand you can use configuration options in [mainnav] section to override Wiki link in main navigation area and make it point at a custom wiki page e.g.
[mainnav]
wiki.label = Home
wiki.href = /wiki/HomePage
see details in trac:wiki:TracInterfaceCustomization#CustomNavigationEntries
If your Trac installation is behind Apache, then you can use an Apache configuration directive to redirect or rename the "home page" url. For example, look at the "Alias" directive.
My solution to the same problem was to use the [[Include]] macro (http://trac-hacks.org/wiki/IncludeMacro), and have the WikiStart page contain a single include statement.
I wanted a different page name than WikiStart so I could use the page name prefixes to categorize sets of pages, e.g., MyToolNameIntroduction is my start page.
This trac ticket suggests it is not directly possible: http://trac.edgewall.org/ticket/9012