Is there any way to ask popup permission at first login? - javascript

In my project, pop-ups are a core part of the system. Is there any way to ask the user to allow pop-ups on the site at first login, as it happens for HTML 5 Notifications?
EDIT: I know pop-ups are a usually a bad practice, but our customer asked us to implement them for a good reason

You could use a url fragment appended to the end of the login redirect url (if when you login it redirects to /home you could make your login route redirect to /home#something_here instead), and have some javascript in your front end to detect when a page is loaded with that fragment and display the popup.
Also, if your popup is just HTML, you could conditionally render it only when rendering the login success page.

Related

Preserve URL hash between HTTP redirects

I am working on an offers site and we are developing a functionality to send the offers listed in our page in an email to the end user.
In our webpage there is a section called Offers with the enclosed tag id as Offers.
When the user clicks the link in url
Link: https://www.test.com/service#Offers
Expectation: The service page should be loaded and it should scroll to Offers sections
This is working when the user is already signed in.
But when the user is not signed in , the user request will be forwarded to the sign in page and then it reverts to the /service.
But this time, # anchor is missing in url
https://www.test.com/service
and so scrolling is not happening.
Please help me how can i solve this issue.
is it advisable if i can replace it with https://www.test.com/service?Offers
Please advice.
Your problem is related to your frontend which doesn't send the anchor in the URL to the backend because it represents a frontend state (this is by design and cannot be changed). So when the login page keeps the return URL in session and then redirects after login, the redirection doesn't contain the anchor because the backend simply doesn't have it.
If your login is based on HTTP redirects, the web doesn't offer any native solution to your problem.

Social Auth Best Practice

Which one is the best practice to use social auth: opening a modal window to take data or same page loading?
Thanks.
A model window is better than the page redirect.
Also when the user is already logged in on social network, you just need to
show a simple ajax loader. See freelancer.com facebook login for reference.
It terms of implementation. It takes the same amount of efforts. But it has
visual benefits for the user.
The url doesn't change in the address bar.
Automatic login with just a simple ajax loader, when the user is already logged in
Symbolizes a third party login for the user.
In case of an error you are still on your site.

Facebook Javascript Canvas Login Redirect

I am building a facebook canvas application and want users, when they visit "apps.facebook.com/myApp", to be presented with the appropriate login dialogue immediately instead of showing my canvas page without having been logged in. With all the different login flows, I am confused!
Using javascript, how do I do this? Do I set the default canvas page to be a page with a script with a redirect url in it?
You should not immediately present them with the login dialog, it is best practice to show some intro screen with information about your app first. Else there is only a small authorization information and no use will really know what the app is about. Then let the user click on a "Login/Use/Start/..." button to present the authorization popup with the FB.login function of the JavaScript SDK:
https://developers.facebook.com/docs/reference/javascript/FB.login/
If you really want to require user authorization right at the beginning, user the PHP SDK:
https://github.com/facebook/facebook-php-sdk
See "$facebook->getLoginUrl()" - just redirect to the resulting URL if the user is not logged in.

Back Button issue in ASP.NET MVC Web Application

It is kind of a difficult to explain problem.
Let me describe you a scenario.
I have Home Page, Registration Page, Login Page and Dashboard page
When I register for the application from Register page and hit submit. Application will process request and will redirect me on Dashbord with User logged in. Now, The issue comes. When i hit back button. I get the Registration page with fields filled by values. This should not happen.
When i login to system and from dashboard i hit back of browser. it will show me login page. This also should not happen.
I hope it makes it clear what I am looking for.
Few Possible solutions I tried:
use a Proxy page. Similar to what many mail services are doing. But in MVC 3 it will not detect page load event and there is very less control on page.
use javascript function on a proxy page window.history.forward()
Expire proxy page once rendered.
I am not totally convinced with above solution. I was hoping to get some best practices of doing this in a systematic way and elegant solution to problem.
Please help me with your suggestions on existing solution that i am using as well as if you have some great working solution. Please share it.
Thanks All.
FYI.. I am using ASP.NET MVC 4 for development.
In the Controller/Action method for the register and login page check if the user is already logged in and redirect to eg. the Dashboard.
Something like this depending on how you do your authentication.
public ActionResult Register()
{
//If already logged in no need to show register page again
if(Request.IsAuthenticated)
return Redirec("Dashboard");
return View();
}
Edit: Updated answer to fix commented issue
I created a Partial view with the following content
<input type="hidden" id="reloader" value="" />
<script type="text/javascript">
if (document.getElementById("reloader").value === "reload")
window.location.reload();
else
document.getElementById("reloader").value = "reload"
</script>
You can then include that with #Html.Partial('PartailViewName') in your Register and Login views.
Since the DOM is cached when you use the back button the script above will reload the page if the user uses the back button.
If used together with my first answer you will get the behavior you wanted.
Use history.js to control the history.back() event. You just replace the state of the last page to point to the dashboard or the page you want (inside your web app; inter-domain is prohibited for security reasons). When the user clicks the back button the defined page is loaded instead of the login page.
https://github.com/browserstate/History.js/
The proxy solution is too complicated for this kind of UI interaction. The client-side control is the best approach for your solution. The HTML5 reference define the History API for that (http://www.w3.org/TR/html5/history.html). Unfortunately not all the browsers implement it right now; that's because the history.js script exists.

Twitter OAuth via a popup

I was wondering how to do twitter OAuth via a popup, i.e. load up the Oauth page in a popup and make the callback close the child window and reload the parent window.
Edit: OK iframes are bad, but how would you accomplish the above, I notice posterous.com does this - I'm looking to achieve the same flow as FB connect.
Doing the same thing for Yahoo today...
Open a popup
Send user to twitter for authentication
Twitter sends user back to mysite.com/authcompleted.php, with authentication parameters in the query string. Still in the popup here.
The popup (mysite.com/authcompleted.html) reads the query string and sends the data to the opener window via javascript
window.opener.setTwitterAuthData(yourData)
Inside setTwitterAuthData, which is in your main window, set appropriate form fields and submit the data to your server.
You shouldn't do this. Loading it in an IFrame hides the URL from the user, making it difficult for them to confirm that they're entering their password on twitter.com and not a third-party (i.e. phishing) site.
This maybe helpful!
http://zuzara.com/blog/2010/05/15/jquery-plugin-for-twitter-oauth-via-popup-window-facebook-style/

Categories

Resources