When logging into Facebook through application the page refreshes - facebook

The first page of the application passes a value over to the next page using a text box. If the user isn't logged in then it will display a login link that will allow them to do so. Whenever they click the link the page will refresh which drops the value for the variable passed over from the first page.
This is the code for the input box on the first page (HTML)
<form action="verify.php" METHOD=post>
Enter a School:
<input type="text" name="school" />
<INPUT TYPE=SUBMIT VALUE="GO">
</form>
This is the code for the second page to check if they are logged in or not (PHP)
$user = $facebook->getUser();
if ($user == 0){
$loginUrl = $facebook->getLoginUrl();
echo ( '<b>Please Login before proceeding.</b>' );
echo ( '<br />' );

Store the value you need to save before/after login in a session variable, or apprend it to the variables used in your redirect_uri (generated in the getLoginUrl() function)
Bear in mind you'll need to keep the same redirect_uri value when you exchange the code for an access_token in the second step of the server side auth

Related

Prepend a form field response in Angular 2

I'm building a registration form in Angular 2 that asks a user to provide their website's URL before submitting.
When the form is submitted, I need the provided URL to be in the style of "http://www.google.com". To steer the user towards that format, I want the form field to autofill the initial "http://" as soon as the user clicks on the field (or when the user begins typing - either case would be acceptable). Currently I have placeholder text in the field that says "Please provide your website's URL", but I'm having trouble making the "http://" prefix appear when the user actually clicks on the field or starts typing.
Any ideas would be appreciated. Here is what the form field looks like when the user clicks on it. It's contents should switch to "http://" when clicked or typed in. Here is what the code looks like at the moment:
<div class="form-group">
<input
class="form-control"
type="text"
name="companyUrl"
[(ngModel)]="user.companyUrl"
placeholder="Company url"
required pattern='https?://.+'
#companyUrl
>
<div *ngIf="companyUrl.errors && (companyUrl.dirty || companyUrl.touched)" class="text-danger">
<div [hidden]="!companyUrl.errors.required">
Company URL is required.
</div>
<div [hidden]="!companyUrl.errors.pattern">
URL should begin with http:// or https://
</div>
</div>
<div>
Add a function to add the prefix on click event of the input.
Something like below:
<input #companyUrl (click)="addHttpPrefix()" >
And in this function
1. Get the value of companyUrl.
2. Check if it begins with http then skip else prepend with http://
if(companyUrl.indexOf('http') > -1) {
companyUrl = 'http://' + companyUrl;
}
This way when the user initially clicks on the input http:// would be appended.
if the (click) event does not meet your requirement you can try using (change) or other events.

How to redirect user after login in Joomla 2.5

I have created custom Login module in Joomla 2.5 which appears using fancybox.
Our site is using SEF URL. Now my problem is user is not redirecting to previous page where popup is trigger.
I have used following code in my module and passed it to "return" parameter of login form.
$uri =& JFactory::getURI();
$redirectUrl = urlencode(base64_encode($uri->toString()));
<input type="hidden" name="return" value="<?php echo $redirectUrl; ?>" />
But it redirect with some value appended at the end of URL and shows 404 page.
e.g.
localhost/xxx/xxxx.html
TO
localhost/xxx/xxxx.html7
try this
$redirectUrl = base64_encode($uri->toString());
you can remove the last character?
$char = strlen($redirectUrl) - 1;

Letting user specify recipients within Feed Dialog

Currently, our app posts to users' friends' walls via Graph API. However, Facebook is deprecating this functionality so we are migrating to the Feed Dialog per Facebook's recommendations (see the February 6, 2013 section at https://developers.facebook.com/roadmap/).
Now, we know we can specify the recipient as part of the Javascript SDK call (note FB.init() is called elsewhere earlier on the page):
<p><a onclick="launchFeedDialog(); return false">Testing the Feed Dialog</a></p>
<script>
function launchFeedDialog() {
// calling the API ...
var obj = {
method: 'feed',
to: 'RECIPIENT NAME', // Can specify recipient here
link: 'http://example.com',
name: 'Test post',
description: 'Test description'
};
FB.ui(obj);
}
</script>
However, it does not seem like the user can modify the recipient in the launched dialog. A screenshot of what I mean is at http://i.imgur.com/oLPTO.png.
Is there some way of invoking the Feed Dialog so that the user can change/add recipients, like in the Send Dialog?
The flow we are trying to implement (and the way it currently is) is:
User clicks a button to launch the Feed dialog
User fills in the Feed dialog (including recipient) and submits
Right now, we are stuck with this awkward flow:
User fills out a custom control specifying the recipient
User clicks a button to launch the Feed dialog
User fills in the Feed dialog and submits
OK, we found a workaround. The general idea:
Display the Feed Dialog inline as an iframe (by specifying display=iframe)
Create your own custom control for selecting a recipient Facebook username or id
Reload the iframe asynchronously upon selecting a recipient or onblur, etc
Some caveats/reasoning for above:
You can't use the JS SDK because it will launch the iframe version of the Feed Dialog as a modal lightbox (rather than inline in your page flow)
You'll need to implement a redirect page that does post processing, such as updating the state of the parent window, logging results, etc
For (2), the custom control can be as simple as a text input field, but you'll probably want at least some sort of autocomplete. This is actually not too tricky, as you grab your user's friend list with the https://graph.facebook.com/me/friends Graph API call.
Here's a basic example using a simple text input:
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
</head>
<body>
<div>
Recipient's FB username:
<input type="text" id="fb-recipient" placeholder="Recipient's FB username"></input>
<input type="submit" id="fb-recipient-submit" value="Pick" />
</div>
<iframe id="fb-feed-dialog" width="586" height="330" frameborder="0" allowfullscreen></iframe>
<script>
$('#fb-recipient-submit').click(function(e){
e.preventDefault();
var feedUrl = 'https://www.facebook.com/dialog/feed?';
feedUrl += 'display=iframe';
feedUrl += '&app_id=' + 'YOUR_APP_ID';
feedUrl += '&access_token=' + 'ACCESS_TOKEN';
feedUrl += '&link=' + 'SHARE_LINK';
feedUrl += '&redirect_uri=' + 'REDIRECT_URI';
feedUrl += '&to=' + $('#fb-recipient').val();
$('#fb-feed-dialog').attr( 'src', feedUrl );
});
</script>
</body>
</html>
You can find a screenshot of a slightly more fleshed out solution at: http://i.imgur.com/0jTM391.png

how to automatically submit a spring security login form using JSP code?

I'm using spring security for normal login form, where users register and then enter their username and password to login. I'm using login with facebook and login with google options, I'm able to authenticate users and finally get user's info like email, first name, last name etc, After logging into either fb/google I'm using fb/google user email(unique) as user name and system generated password as login credentials so that these values will be entered automatically to spring security login form and then if I click on submit button he/she will be able to login and then session handling will be taken care by spring security as in case of normal user who registers in my website.
Since, all the steps described above are automated except last step i.e. submitting the form
I want to automate the last step also using either javascript or JSP. i tried submitting the form using javascript inside JSP but its unable to
<%
if(Success_login_with_facebook/Success_login_with_google)
{
email = fb_email/google_email;
Sql query to get username and password from db using email;//unique row will be returned
uname_db = username;
uname_pass = password;
out.println("<script>document.forms('login').submit();</script>");
}
%>
<div id="autologin" style="display:none">
<form name="f" id='login' action="<c:url value='j_spring_security_check'/>" method="POST" >
User ID <input size=35 type='text' id="first" name='j_username' value='<%=uname_db %>'/>
Password<input size=35 type='password' name='j_password' value='<%=pass_db %>'>
<input type="hidden" name="_spring_security_remember_me" value=true>
<input style="height:30px" name="submit" type="submit" value="Sign In">
</form>
</div>
Your solution should work, but it's missing one thing. You need to make sure that the form exists before trying to submit it wis JavaScript. In your example, you're doing an out.println above the form. Move this to below the form, and the JavaScript should work fine.
The reason why it did not work is because the html form has submit button name as "submit", and if we try to run the javascript document.forms['login'].submit(); it will not submit the form. If the form submit button name is other than 'submit' then it will work.

URL Redirect based on input but if input url does not exist send back to same page

This code is almost perfect for what I need:
<form onsubmit="location.href='http://www.mysite.com/' + document.getElementById('myInput').value; return false;">
<input type="text" id="myInput" />
<input type="submit" />
</form>
The only thing missing is if they user puts in an input that does not exist I want it to take them nowhere or redirect back to the same page. Right now it takes them to an error page and they have to use the back button to go back and try again.
Any help will be greatly appreciated.
Thank you
Could you perhaps write a small PHP script that you use as the form action? Inside this script, you could check the supplied user input and validate that the URL exists. If it does, you could do a header() redirect to the given page. If it does not exist, you could redirect them to the desired page.
<?php
$input = $_POST['myInput']; // You'll also need to add in a name='' tag in the HTML!
$desired_page = ''; // page you want to go to if inputted file cannot be found
if (file_exists($input)) {
header("Location: $input");
}
else {
header("Location: $desired_page");
}
It'd need a lot of refining, but that's the idea. Would that do what you want?