3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010, StatusNet, Inc.
6 * An action for logging in with Facebook
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * @author Zach Copley <zach@status.net>
26 * @copyright 2010 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET')) {
35 class FacebookloginAction extends Action
38 function handle($args)
40 parent::handle($args);
42 if (common_is_real_login()) {
44 $this->clientError(_m('Already logged in.'));
48 $facebook = new Facebook(
50 'appId' => common_config('facebook', 'appid'),
51 'secret' => common_config('facebook', 'secret'),
56 $session = $facebook->getSession();
61 $fbuid = $facebook->getUser();
62 $fbuser = $facebook->api('/me');
63 } catch (FacebookApiException $e) {
64 common_log(LOG_ERROR, $e);
68 if (!empty($fbuser)) {
69 common_debug("Found a valid Facebook user", __FILE__);
71 // Check to see if we have a foreign link already
72 $flink = Foreign_link::getByForeignId($fbuid, FACEBOOK_SERVICE);
76 // See if the user would like to register a new local
79 common_local_url('facebookregister'),
86 $user = $flink->getUser();
93 'Logged in Facebook user %s as user %s (%s)',
101 common_set_user($user);
102 common_real_login(true);
103 $this->goHome($user->nickname);
113 function goHome($nickname)
115 $url = common_get_returnto();
117 // We don't have to return to it again
118 common_set_returnto(null);
120 $url = common_local_url(
122 array('nickname' => $nickname)
126 common_redirect($url, 303);
129 function getInstructions()
131 // TRANS: Instructions.
132 return _m('Login with your Facebook Account');
135 function showPageNotice()
137 $instr = $this->getInstructions();
138 $output = common_markup_to_html($instr);
139 $this->elementStart('div', 'instructions');
141 $this->elementEnd('div');
146 // TRANS: Page title.
147 return _m('Login with Facebook');
150 function showContent() {
152 $this->elementStart('fieldset');
155 //'show-faces' => 'true',
158 'perms' => 'user_location,user_website,offline_access,publish_stream'
161 $this->element('fb:login-button', $attrs);
162 $this->elementEnd('fieldset');
165 function showLocalNav()
167 $nav = new LoginGroupNav($this);