3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010, StatusNet, Inc.
6 * An action that handles deauthorize callbacks from 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')) {
36 * Action class for handling deauthorize callbacks from Facebook. If the user
37 * doesn't have a password let her know she'll need to contact the site
38 * admin to get back into her account (if possible).
40 class FacebookdeauthorizeAction extends Action
45 * For initializing members of the class.
47 * @param array $args misc. arguments
49 * @return boolean true
51 function prepare($args)
53 $this->facebook = Facebookclient::getFacebook();
61 * @param array $args is ignored since it's now passed in in prepare()
63 function handle($args)
65 parent::handle($args);
67 $data = $this->facebook->getSignedRequest();
69 if (isset($data['user_id'])) {
71 $fbuid = $data['user_id'];
73 $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE);
74 $user = $flink->getUser();
76 // Remove the link to Facebook
77 $result = $flink->delete();
80 common_log_db_error($flink, 'DELETE', __FILE__);
84 'Unable to delete Facebook foreign link '
85 . 'for %s (%d), fbuid %s',
98 'Facebook callback: %s (%d), fbuid %s has deauthorized '
99 . 'the Facebook application.',
107 // Warn the user about being locked out of their account
109 if (empty($user->password) && !empty($user->email)) {
110 $this->emailWarn($user);
115 '%s (%d), fbuid $s has deauthorized his/her Facebook '
116 . 'connection but hasn\'t set a password so s/he '
131 'Facebook called the deauthorize callback '
132 . ' but didn\'t provide a user ID.'
137 // It probably wasn't Facebook that hit this action,
138 // so redirect to the login page
139 common_redirect(common_local_url('login'), 303);
145 * Send the user an email warning that their account has been
146 * disconnected and he/she has no way to login and must contact
147 * the site administrator for help.
149 * @param User $user the deauthorizing user
152 function emailWarn($user)
154 $profile = $user->getProfile();
156 $siteName = common_config('site', 'name');
157 $siteEmail = common_config('site', 'email');
159 if (empty($siteEmail)) {
162 "No site email address configured. Please set one."
166 common_switch_locale($user->language);
168 $subject = _m('Contact the %s administrator to retrieve your account');
173 We've noticed you have deauthorized the Facebook connection for your
174 %2$s account. You have not set a password for your %2$s account yet, so
175 you will not be able to login. If you wish to continue using your %2$s
176 account, please contact the site administrator (%3$s) to set a password.
189 common_switch_locale();
191 if (mail_to_user($user, $subject, $body)) {
195 'Sent account lockout warning to %s (%d)',
205 'Unable to send account lockout warning to %s (%d)',