Social Engine 4 authentication check - zend-framework

I have a website and within it, Social Engine 4.1.4 is just a sub-module. I am using the login system of Social Engine in my website. When a user login and then comes back to the site homepage, I want to show his login status. I mean, that if the user is logged in SE4, then I should greet him with his name. How can I do the same.
My site is not using Zend Framework. Since the session data is stored in the table engine4_core_session, I was thinking of a way to decode the serialized data column in some way by getting the specific user row through the *session_id*. I'm not getting the way to decode the data.

Hi you get de name in socialengine 4 :
in the controller you get this:
public function indexAction()
{
$viewer = Engine_Api::_()->user()->getViewer();
$fields = Engine_Api::_()->fields()->getFieldsValuesByAlias($viewer);
$this->view->name = $fields["first_name"] ." ". $fields["last_name"];
$viewer->getTitle();
}
in your view print this:
<h1><?php echo $this->name; ?></h1>

Related

laravel 5.2 Auth::loginUsingId() not working when i redirect to another page

I am Implementing Facebook Login in my Laravel Project. for this I have used Facebook JS code. Its working fine I receiving data also. Now i want to save data in my database and login with this inserted id.
For this I have created a function called "checkloginByFacebook_API" in a controller and put below code also
$this->middleware('auth', ['except' => ['checkloginByFacebook_API']]);
now I am using below method
$auth_data = Auth::loginUsingId(1);</code>
Here it print $auth _data array but if I change page it don't show its value means Auth session not worked.

How do I remove the Facebook login prompt when displaying images pulled with graph api on a page?

I recently started playing around with Facebook graph API and wanted to integrate images pulled from my Facebook page to display on my website. I have the images displaying properly but my problem is whenever anyone tries to view the page they are asked to log into Facebook first. Is there any way to display the images without prompting the user to log into Facebook?
Here is what I am using to make the session:
$app_id = 'id';
$app_secret = 'secret';
$redirect = 'my webpage';
// init app with app id and secret
FacebookSession::setDefaultApplication($app_id,$app_secret);
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper($redirect);
try {
$session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
// When Facebook returns an error
} catch( Exception $ex ) {
// When validation fails or other local issues
}
Any help would be appreciated.
Step one: familiarize yourself with the API. Read the docs, and play around with the Graph API Explorer
Step two: the code you provided has nothing to do with what you are trying to achieve (displaying page photos). That code is basically the getting started code used in the docs. If you need help, post the relevant code.
Step three: as mentioned by #CBroe, authenticating the visitor is not needed to display photos from a page. What you might want to explore:
The page admin authenticating your app with the right permissions (maybe manage_pages)
with the user access token you just got, you extend it to long-lived one
then you query the API to get a page access token that won't expire
you store this access token and query the API to get the relevant data and store it (GET /{PAGE-ID}/photos or GET /{PAGE-ID}/albums ... etc)
you show the stored data to your visitors
Notes:
Do not make these calls on client-side ... i.e. reveal your page access token, since you can do this in the backend.
Use the realtime updates to get notified when you should query the API and get new photos instead of periodically querying the API to pull new photos, or even worst, querying the API on each user visit.

Track who downloaded a PDF from my Custom Facebook Tab

I am going to create a custom page tab on Facebook and offer a free downloadable PDF with information about my services. Is it possible to track which Facebook users have downloaded the PDF?
An option to look into is authenticating the users individually and receiving their respective Facebook user IDs as a result. You may be interested in reading up on the page tab authentication process referenced here:
Reference: http://developers.facebook.com/docs/authentication/pagetab/
Once you have this user ID, you can track their activity by opening a session containing their user information (to identify them when they download the PDF). For instance, assuming you're using PHP (alongside a CMS):
<?php
if ($current_user->fb_id == 0) {
exit();
} else {
echo $current_user->fb_id;
// do stuff with user here
}
header("Location: http://www.example.com/file.pdf");
// redirect them to the actual file
?>
Hopefully this pseudocode gives you a starting point on your project.

Codeigniter session problem

I am building a facebook app with codeigniter. When a user accepts a request and gets redirected to my app I want to store the request_id in a session. At first it gets stored but when the page is reloaded after the user authenticates the app the requested_id stored earlier doesn't exist anymore.
function save_request_id()
{
$this->session->set_userdata('request_id', $request_id);
}
function retrieve_request_id()
{
$data = $this->session->all_userdata();
print_r($data);
exit;
}
You want to only retrieve the request_id:
$this->session->userdata('request_id');
Sounds like the session is being cleared when the user completes the auth cycle. Are you using the FB PHP SDK? If so, I believe it creates its own session to manage the connected user. Check the library you're using, you may need to adjust it to fit your needs - or devise an alternate solution, like redirecting after auth to a view that can process a request_id in the URL.
session library of CodeIgniter has this problem,use native php session + secuirty lib of CodeIgniter to clean XSS .

Architecture for Zend Framework + Facebook Connect

I'm currently building out an application using ZF and want to integrate Facebook Connect - had some questions about architecture.
Functionality:
All logins go through FB connect, there is no other login form. When a user first clicks 'Connect', the application needs to create an entry for them in the database to tie extra data to (reviews, profile, etc).
The header should have a 'Login with FB Connect' button on all pages if the user isn't logged in, and a welcome message/picture/profile completion % bar if he or she is.
Architecture
As far as I can see, there's two components - a JS call that handles the login, redirect, and cookie writing (fb:login-button) and some PHP that reads the cookie. I'm a little confused about what should go where.
The login button is via JS, so I've loaded it in my layout.phtml and handled the cookie check via a View Helper - the helper retrieves the cookie and returns it to the view. That's fine, but I need to handle things like checking if the user exists and adding new users to the database - that doesn't seem like something that belongs in a helper.
I refactored it to include the cookie PHP in the user controller, but I need the cookie in the view, which is rendered by a different controller. I called a view action helper, but that seems to be more for returning partial pages, and I can't get the cookie array variable out of it.
I'm fairly new to MVC, and it seems like I'm missing something fairly obvious - thoughts?
Code is right off the FB developers site:
class Zend_View_Helper_FacebookCookie extends Zend_View_Helper_Abstract
{
public function facebookCookie()
{
$FACEBOOK_APP_ID = 'xxx';
$FACEBOOK_SECRET = 'xxx';
$cookie = $this->getFacebookCookie($FACEBOOK_APP_ID, $FACEBOOK_SECRET);
//Zend_Debug::dump($cookie);
return $cookie;
}
public function getFacebookCookie($app_id, $application_secret)
{
$args = array();
parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
ksort($args);
$payload = '';
foreach ($args as $key => $value) {
if ($key != 'sig') {
$payload .= $key . '=' . $value;
}
}
if (md5($payload . $application_secret) != $args['sig']) {
return null;
}
return $args;
}
}
and in the view:
if ($cookie) { ?>
Your user ID is <?= $cookie['uid'] ?>
<?php } else { ?>
<fb:login-button></fb:login-button>
<?php } ?>
The way I've implemented this in the past is via a single preDispatch plugin -- it checks the status of the user with the Facebook API and then modifies their local state (i.e. logged in / not logged in) and stores that state using Zend_Auth and/or Zend_Session.
If the user is authenticated with Facebook but not yet in your database, then the preDispatch plugin creates the record in your database before setting their local state.
Then, you can query Zend_Auth later in the application to determine whether the user is logged in.
The benefit here is that if you implement other authentication mechanisms (OpenID or others) you can simply create another plugin to do this and you don't have to modify the rest of your the user is ultimately 'locally' authenticated by Zend_Auth).