EE 5.x - How to suppress login/logout confirmation page - expressionengine

on EE 2.x the Freemember addon allowed to directly redirect the user after login/logout to a specified page (avoiding the default login/logout confirmation page).
Since the Freemember addon is EOL, how can I achieve the same thing on EE 5.x ?

First you could use Custom System Messages
You can also do this with ajax (dont't have an example at hand)

You could use the member_member_login_single hook in a simple extension and redirect it with php.
function member_member_login_single($hook_data)
{
if(isset($_POST['RET'])){
header('location: '.$_POST['RET']);
exit;
}
}

I ended up using the member_member_login_single($hook_data) in a custom extension to get this done. Works.

Related

Optionally inject Content Script

Content Script can be injected programatically or permanently by declaring in Extension manifest file. Programatic injection require host permission, which is generally grant by browser or page action.
In my use case, I want to inject gmail, outlook.com and yahoo mail web site without user action. I can do by declaring all of them manifest, but by doing so require all data access to those account. Some use may want to grant only outlook.com, but not gmail. Programatic injection does not work because I need to know when to inject. Using tabs permission is also require another permission.
Is there any good way to optionally inject web site?
You cannot run code on a site without the appropriate permissions. Fortunately, you can add the host permissions to optional_permissions in the manifest file to declare them optional and still allow the extension to use them.
In response to a user gesture, you can use chrome.permission.request to request additional permissions. This API can only be used in extension pages (background page, popup page, options page, ...). As of Chrome 36.0.1957.0, the required user gesture also carries over from content scripts, so if you want to, you could add a click event listener from a content script and use chrome.runtime.sendMessage to send the request to the background page, which in turn calls chrome.permissions.request.
Optional code execution in tabs
After obtaining the host permissions (optional or mandatory), you have to somehow inject the content script (or CSS style) in the matching pages. There are a few options, in order of my preference:
Use the chrome.declarativeContent.RequestContentScript action to insert a content script in the page. Read the documentation if you want to learn how to use this API.
Use the webNavigation API (e.g. chrome.webNavigation.onCommitted) to detect when the user has navigated to the page, then use chrome.tabs.executeScript to insert the content script in the tab (or chrome.tabs.insertCSS to insert styles).
Use the tabs API (chrome.tabs.onUpdated) to detect that a page might have changed, and insert a content script in the page using chrome.tabs.executeScript.
I strongly recommend option 1, because it was specifically designed for this use case. Note: This API was added in Chrome 38, but only worked with optional permissions since Chrome 39. Despite the "WARNING: This action is still experimental and is not supported on stable builds of Chrome." in the documentation, the API is actually supported on stable. Initially the idea was to wait for a review before publishing the API on stable, but that review never came and so now this API has been working fine for almost two years.
The second and third options are similar. The difference between the two is that using the webNavigation API adds an additional permission warning ("Read your browsing history"). For this warning, you get an API that can efficiently filter the navigations, so the number of chrome.tabs.executeScript calls can be minimized.
If you don't want to put this extra permission warning in your permission dialog, then you could blindly try to inject on every tab. If your extension has the permission, then the injection will succeed. Otherwise, it fails. This doesn't sound very efficient, and it is not... ...on the bright side, this method does not require any additional permissions.
By using either of the latter two methods, your content script must be designed in such a way that it can handle multiple insertions (e.g. with a guard). Inserting in frames is also supported (allFrames:true), but only if your extension is allowed to access the tab's URL (or the frame's URL if frameId is set).
I advise against using declarativeContent APIs because they're deprecated and buggy with CSS, as described by the last comment on https://bugs.chromium.org/p/chromium/issues/detail?id=708115.
Use the new content script registration APIs instead. Here's what you need, in two parts:
Programmatic script injection
There's a new contentScripts.register() API which can programmatically register content scripts and they'll be loaded exactly like content_scripts defined in the manifest:
browser.contentScripts.register({
matches: ['https://your-dynamic-domain.example.com/*'],
js: [{file: 'content.js'}]
});
This API is only available in Firefox but there's a Chrome polyfill you can use. If you're using Manifest v3, there's the native chrome.scripting.registerContentScript which does the same thing but slightly differently.
Acquiring new permissions
By using chrome.permissions.request you can add new domains on which you can inject content scripts. An example would be:
// In a content script or options page
document.querySelector('button').addEventListener('click', () => {
chrome.permissions.request({
origins: ['https://your-dynamic-domain.example.com/*']
}, granted => {
if (granted) {
/* Use contentScripts.register */
}
});
});
And you'll have to add optional_permissions in your manifest.json to allow new origins to be requested:
{
"optional_permissions": [
"*://*/*"
]
}
In Manifest v3 this property was renamed to optional_host_permissions.
I also wrote some tools to further simplify this for you and for the end user, such as
webext-domain-permission-toggle and webext-dynamic-content-scripts. They will automatically register your scripts in the next browser launches and allow the user the remove the new permissions and scripts.
Since the existing answer is now a few years old, optional injection is now much easier and is described here. It says that to inject a new file conditionally, you can use the following code:
// The lines I have commented are in the documentation, but the uncommented
// lines are the important part
//chrome.runtime.onMessage.addListener((message, callback) => {
// if (message == “runContentScript”){
chrome.tabs.executeScript({
file: 'contentScript.js'
});
// }
//});
You will need the Active Tab Permission to do this.

How to redirect a user with javascript while using ratchet?

Normally to redirect a user in a website using javascript I'd use window.location.replace("newpage.html"); however I've found that when using Ratchet this doesn't work. Does anyone know of a good way to make a ratchet application change pages using javascript?
Take a look at push.js to see how the navigation mechanism is triggered. Ratchet auto-wires navigation to elements triggered on the touchend event. You can call PUSH with those properties directly.
PUSH({
url : "target.html",
hash : "#",
timeout : null,
transition : "slide-in"
});

How to signout programmatically from Liferay custom portlet

I am creating a custom portlet.
And I need to log-out the User from the portal after he performs some operation in my custom portlet. I am extending liferay's MVCPortlet.
In one of MyPortlet's action methods I need to write the code to logout the user and then redirect it to the home page.
Update:
I tried the following which I think logs out the user but does not redirect to the home page after logging out:
actionResponse.sendRedirect(PortalUtil.getPortalURL(actionRequest) + "/c/portal/logout");
Thanks All
Well this may be a very late reply, but it may help somebody
Firstly, you have to validate the session and the re-direct to the logout URL. Otherwise, the session remains and the user is moved to the landing page, even though we redirect to the logout url. So, this is what one should do
HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);
request.getSession().invalidate();
actionResponse.sendRedirect(themeDisplay.getURLSignOut());
Hope this helps.
I also did not find a way to send a specific redirect by using liferay's default logout (/c/portal/logout). So I logged out the user programmatically with the util class AuthenticatedSessionManagerUtil and
afterwards sending a specific redirect location within the response object, e.g. response.sendRedirect(yourLocation)
Note:
With Liferay 7.2 I used AuthenticatedSessionManagerUtil.signOutSimultaneousLogins(userId) instead of AuthenticatedSessionManagerUtil.logout(userId) which did not work for me.
hth
You can redirect to c/portal/logout
more precisely :
actionResponse.sendRedirect("/c/portal/logout/");
Just leaving this here after facing this problem (LR7):
try {
AuthenticatedSessionManagerUtil.logout(request, response);
request.setAttribute(WebKeys.LOGOUT, true);
}
All you have to do is
perform operation: at the end of operation use this:
HttpSession session = PortalUtil.getHttpServletRequest(request).getSession();
session.invalidate();
try {
System.out.println(" redirecting to the required page");
response.sendRedirect(themeDisplay.getPortalURL() + "/page-on-which-to-be-redirected");
} catch (IOException e1) {
e1.printStackTrace();
}

setting redirect page for my Joomla website hosted in IIS

I am using Joomla with IIS in my website, and now i am trying to set a 404 redirect page in my Joomla website, i could use htaccess to make this when i am using apache, but for this IIS its gets tricky it seems.
you can see my web.config file here
any suggestion would be helpful..
There is no module available AFAIK - at least not for 1.6. But it is quite easy to do by yourself. You can use the solution in the joomla documentation. This is usable for any error code.
http://docs.joomla.org/Creating_a_Custom_404_Error_Page
if (($this->error->code) == '404') {
header('Location: /search');
exit;
}
The part behind the Location: is where you redirect to the page you want. e.g. /search in this case. The above is for 1.5, for 1.6 you need to use this:
if ($this->error->getCode() == '404') {
header('Location: /search');
exit;
} ;
in your IIS Console, right click on the website, goto the Custom Errors TAB,
scroll down to HTTP Error 404, Edit Properties, change the Message Type
to URL, and then type in the URL you want to change to.

CDI timeout results in an NPE

Is there a way (in JSF 2) to catch a Conversation timeout and redirect a user to a new page? I'm getting nasty NullPointerExceptions when the conversation times out.
I could redirect the user on all NPE's, but that seems like too big a net.
This is a bug with Weld 1.0.0 the RI for CDI
https://jira.jboss.org/browse/WELD-550
This has apparently been fixed in the Weld trunk, I don't know in which release it's available. In trunk, a org.jboss.weld.context.NonexistentConversationException exception is thrown, when trying to access an expired conversation. This Exception can be trapped with a custom ExceptionHandler, and redirect the user to an appropriate page. See this blog for more details on creating an custom ExceptionHandler:
http://weblogs.java.net/blog/edburns/archive/2009/09/03/dealing-gracefully-viewexpiredexception-jsf2
I'm also currently working with CDI-conversations and trying to build a Conversation-based app. I solved most of the problems (not easy without any useful tutorial out there...). Maybe i can help.
My first problem was that i didn't redirect the view&add the cid to GET when navigating to the next page of the Conversation-UseCase. I asked a related question in the Weld Forum.
There i learned that in my managed/weld-bean i have to redirect to the next page and add the cid as a GET-parameter.
Only then you can access conversation-scoped elements of your bean on the next page.
So when i enter the first page of my conversation i'm calling a start-method (e.g. by a commandLink) in my ConversationScoped-Bean, like this:
public String startRegister() {
if (conversation.isTransient)
conversation.begin();
return "register_start?faces-redirect=true&includeViewParams=true&cid=" + conversation.getId()
}
Does that solve your problem?
I also asked a question at StackOverflow related to the ViewExpiredException that has to be handled when working with conversations - here.

Resources