aboutsummaryrefslogtreecommitdiff
path: root/mod
diff options
context:
space:
mode:
authorBrett Profitt <brett.profitt@gmail.com>2011-08-23 20:12:58 -0700
committerBrett Profitt <brett.profitt@gmail.com>2011-08-23 20:12:58 -0700
commit9f13557c2e7422cb15ce109adbe5714d6d78fc9e (patch)
treef2c3966a0bbaae5462475089945e531d0f9138c9 /mod
parent469f8ba89cc3b613b88228d95f9c69cb53e5b605 (diff)
downloadelgg-9f13557c2e7422cb15ce109adbe5714d6d78fc9e.tar.gz
elgg-9f13557c2e7422cb15ce109adbe5714d6d78fc9e.tar.bz2
Fixes #3117. Added an interstitial page for twitter new users.
Diffstat (limited to 'mod')
-rw-r--r--mod/twitter_api/actions/twitter_api/interstitial_settings.php53
-rw-r--r--mod/twitter_api/languages/en.php24
-rw-r--r--mod/twitter_api/lib/twitter_api.php2
-rw-r--r--mod/twitter_api/pages/twitter_api/interstitial.php21
-rw-r--r--mod/twitter_api/start.php15
-rw-r--r--mod/twitter_api/views/default/forms/twitter_api/interstitial_settings.php61
-rw-r--r--mod/twitter_api/views/default/usersettings/twitter_api/edit.php21
7 files changed, 189 insertions, 8 deletions
diff --git a/mod/twitter_api/actions/twitter_api/interstitial_settings.php b/mod/twitter_api/actions/twitter_api/interstitial_settings.php
new file mode 100644
index 000000000..5f742efd8
--- /dev/null
+++ b/mod/twitter_api/actions/twitter_api/interstitial_settings.php
@@ -0,0 +1,53 @@
+<?php
+/**
+ * Save settings for first time logins with twitter
+ */
+elgg_make_sticky_form('twitter_api_interstitial');
+
+$display_name = get_input('display_name');
+$email = get_input('email');
+$password_1 = get_input('password_1');
+$password_2 = get_input('password_2');
+
+if (!$display_name) {
+ register_error(elgg_echo('twitter_api:interstitial:no_display_name'));
+ forward(REFERER);
+}
+
+if ($email && !is_email_address($email)) {
+ register_error(elgg_echo('twitter_api:interstitial:invalid_email'));
+ forward(REFERER);
+}
+
+$existing_user = get_user_by_email($email);
+if ($email && $existing_user) {
+ register_error(elgg_echo('twitter_api:interstitial:existing_email'));
+ forward(REFERER);
+}
+
+if ($password_1 && !($password_1 == $password_2)) {
+ register_error(elgg_echo('twitter_api:interstitial:password_mismatch'));
+ forward(REFERER);
+}
+
+$user = elgg_get_logged_in_user_entity();
+$user->name = $display_name;
+
+if ($email) {
+ $user->email = $email;
+}
+
+if ($password_1) {
+ $user->salt = generate_random_cleartext_password();
+ $user->password = generate_user_password($user, $password_1);
+}
+
+if (!$user->save()) {
+ register_error(elgg_echo('twitter_api:interstitial:cannot_save'));
+ forward(REFERER);
+}
+
+elgg_clear_sticky_form('twitter_api_interstitial');
+
+system_message(elgg_echo('twitter_api:interstitial:saved'));
+forward('/'); \ No newline at end of file
diff --git a/mod/twitter_api/languages/en.php b/mod/twitter_api/languages/en.php
index 3a422b043..9d8554a9e 100644
--- a/mod/twitter_api/languages/en.php
+++ b/mod/twitter_api/languages/en.php
@@ -15,6 +15,7 @@ $english = array(
'twitter_api:usersettings:description' => "Link your %s account with Twitter.",
'twitter_api:usersettings:request' => "You must first <a href=\"%s\">authorize</a> %s to access your Twitter account.",
+ 'twitter_api:usersettings:cannot_revoke' => "You cannot unlink you account with Twitter because you haven't provided an email address or password. <a href=\"%s\">Provide them now</a>.",
'twitter_api:authorize:error' => 'Unable to authorize Twitter.',
'twitter_api:authorize:success' => 'Twitter access has been authorized.',
@@ -28,7 +29,30 @@ $english = array(
'twitter_api:login:error' => 'Unable to login with Twitter.',
'twitter_api:login:email' => "You must enter a valid email address for your new %s account.",
+ 'twitter_api:invalid_page' => 'Invalid page',
+
'twitter_api:deprecated_callback_url' => 'The callback URL has changed for Twitter API to %s. Please ask your administrator to change it.',
+
+ 'twitter_api:interstitial:settings' => 'Configure your settings',
+ 'twitter_api:interstitial:description' => 'You\'re almost ready to use %s! We need a few more details before you can continue. These are optional, but will allow you login if Twitter goes down or you decide to unlink your accounts.',
+
+ 'twitter_api:interstitial:username' => 'This is your username. It cannot be changed. If you set a password, you can use the username or your email address to log in.',
+
+ 'twitter_api:interstitial:name' => 'This is the name people will see when interacting with you.',
+
+ 'twitter_api:interstitial:email' => 'Your email address. Users cannot see this by default.',
+
+ 'twitter_api:interstitial:password' => 'A password to login if Twitter is down or you decide to unlink your accounts.',
+ 'twitter_api:interstitial:password2' => 'The same password, again.',
+
+ 'twitter_api:interstitial:no_thanks' => 'No thanks',
+
+ 'twitter_api:interstitial:no_display_name' => 'You must have a display name.',
+ 'twitter_api:interstitial:invalid_email' => 'You must enter a valid email address or nothing.',
+ 'twitter_api:interstitial:existing_email' => 'This email address is already registered on this site.',
+ 'twitter_api:interstitial:password_mismatch' => 'Your passwords do not match.',
+ 'twitter_api:interstitial:cannot_save' => 'Cannot save account details.',
+ 'twitter_api:interstitial:saved' => 'Account details saved!',
);
add_translation('en', $english);
diff --git a/mod/twitter_api/lib/twitter_api.php b/mod/twitter_api/lib/twitter_api.php
index 81aef38fb..b14b84f2d 100644
--- a/mod/twitter_api/lib/twitter_api.php
+++ b/mod/twitter_api/lib/twitter_api.php
@@ -109,7 +109,7 @@ function twitter_api_login() {
$user = twitter_api_create_user($twitter);
$site_name = elgg_get_site_entity()->name;
system_message(elgg_echo('twitter_api:login:email', array($site_name)));
- $forward = "settings/user/{$user->username}";
+ $forward = "twitter_api/intersitial";
}
// set twitter services tokens
diff --git a/mod/twitter_api/pages/twitter_api/interstitial.php b/mod/twitter_api/pages/twitter_api/interstitial.php
new file mode 100644
index 000000000..d1f1ac20c
--- /dev/null
+++ b/mod/twitter_api/pages/twitter_api/interstitial.php
@@ -0,0 +1,21 @@
+<?php
+/**
+ * An interstitial page for newly created Twitter users.
+ *
+ * This prompts them to enter an email address and set a password in case Twitter goes down or they
+ * want to disassociate their account from twitter.
+ */
+
+$title = elgg_echo('twitter_api:interstitial:settings');
+
+$site = get_config('site');
+$content = elgg_echo('twitter_api:interstitial:description', array($site->name));
+$content .= elgg_view_form('twitter_api/interstitial_settings');
+
+$params = array(
+ 'content' => $content,
+ 'title' => $title,
+);
+$body = elgg_view_layout('one_sidebar', $params);
+
+echo elgg_view_page($title, $body);
diff --git a/mod/twitter_api/start.php b/mod/twitter_api/start.php
index 0c71104b5..b17643c8c 100644
--- a/mod/twitter_api/start.php
+++ b/mod/twitter_api/start.php
@@ -36,6 +36,9 @@ function twitter_api_init() {
// push status messages to twitter
elgg_register_plugin_hook_handler('status', 'user', 'twitter_api_tweet');
+
+ $actions = dirname(__FILE__) . '/actions/twitter_api';
+ elgg_register_action('twitter_api/interstitial_settings', "$actions/interstitial_settings.php", 'logged_in');
}
/**
@@ -75,6 +78,18 @@ function twitter_api_pagehandler($page) {
case 'login':
twitter_api_login();
break;
+ case 'interstitial':
+ gatekeeper();
+ // only let twitter users do this.
+ $guid = elgg_get_logged_in_user_guid();
+ $twitter_name = elgg_get_plugin_user_setting('twitter_name', $guid, 'twitter_api');
+ if (!$twitter_name) {
+ register_error(elgg_echo('twitter_api:invalid_page'));
+ forward();
+ }
+ $pages = dirname(__FILE__) . '/pages/twitter_api';
+ include "$pages/interstitial.php";
+ break;
default:
forward();
break;
diff --git a/mod/twitter_api/views/default/forms/twitter_api/interstitial_settings.php b/mod/twitter_api/views/default/forms/twitter_api/interstitial_settings.php
new file mode 100644
index 000000000..fdeafd46d
--- /dev/null
+++ b/mod/twitter_api/views/default/forms/twitter_api/interstitial_settings.php
@@ -0,0 +1,61 @@
+<?php
+/**
+ * Make the user set up some alternative ways to login.
+ */
+
+$user = elgg_get_logged_in_user_entity();
+
+if (elgg_is_sticky_form('twitter_api_interstitial')) {
+ extract(elgg_get_sticky_values('twitter_api_interstitial'));
+ elgg_clear_sticky_form('twitter_api_interstitial');
+}
+
+if (!isset($display_name)) {
+ $display_name = $user->name;
+}
+
+// username
+$title = elgg_echo('username');
+
+$body = elgg_echo('twitter_api:interstitial:username');
+$body .= elgg_view('input/text', array('value' => $user->username, 'disabled' => 'disabled'));
+
+echo elgg_view_module('info', $title, $body);
+
+// display name
+$title = elgg_echo('name');
+
+$body = elgg_echo('twitter_api:interstitial:name');
+$body .= elgg_view('input/text', array('name' => 'display_name', 'value' => $display_name));
+
+echo elgg_view_module('info', $title, $body);
+
+// email
+$title = elgg_echo('email');
+
+$body = elgg_echo('twitter_api:interstitial:email');
+$body .= elgg_view('input/email', array('name' => 'email', 'value' => $email));
+
+echo elgg_view_module('info', $title, $body);
+
+// password
+$title = elgg_echo('password');
+
+$body = elgg_echo('twitter_api:interstitial:password');
+$body .= elgg_view('input/password', array('name' => 'password_1'));
+$body .= elgg_echo('twitter_api:interstitial:password2');
+$body .= elgg_view('input/password', array('name' => 'password_2'));
+
+echo elgg_view_module('info', $title, $body);
+
+// buttons
+
+echo elgg_view('input/submit', array(
+ 'text' => elgg_echo('save')
+));
+
+echo elgg_view('output/url', array(
+ 'class' => 'right',
+ 'text' => elgg_echo('twitter_api:interstitial:no_thanks'),
+ 'href' => '/',
+)); \ No newline at end of file
diff --git a/mod/twitter_api/views/default/usersettings/twitter_api/edit.php b/mod/twitter_api/views/default/usersettings/twitter_api/edit.php
index 0898087ca..acb8d9af5 100644
--- a/mod/twitter_api/views/default/usersettings/twitter_api/edit.php
+++ b/mod/twitter_api/views/default/usersettings/twitter_api/edit.php
@@ -3,10 +3,11 @@
* User settings for Twitter API
*/
-$user_id = elgg_get_logged_in_user_guid();
-$twitter_name = get_plugin_usersetting('twitter_name', $user_id, 'twitter_api');
-$access_key = get_plugin_usersetting('access_key', $user_id, 'twitter_api');
-$access_secret = get_plugin_usersetting('access_secret', $user_id, 'twitter_api');
+$user = elgg_get_logged_in_user_entity();
+$user_guid = $user->getGUID();
+$twitter_name = get_plugin_usersetting('twitter_name', $user_guid, 'twitter_api');
+$access_key = get_plugin_usersetting('access_key', $user_guid, 'twitter_api');
+$access_secret = get_plugin_usersetting('access_secret', $user_guid, 'twitter_api');
$site_name = elgg_get_site_entity()->name;
echo '<div>' . elgg_echo('twitter_api:usersettings:description', array($site_name)) . '</div>';
@@ -16,7 +17,13 @@ if (!$access_key || !$access_secret) {
$request_link = twitter_api_get_authorize_url(null, false);
echo '<div>' . elgg_echo('twitter_api:usersettings:request', array($request_link, $site_name)) . '</div>';
} else {
- $url = elgg_get_site_url() . "twitter_api/revoke";
- echo '<div class="twitter_anywhere">' . elgg_echo('twitter_api:usersettings:authorized', array($site_name, $twitter_name)) . '</div>';
- echo '<div>' . sprintf(elgg_echo('twitter_api:usersettings:revoke'), $url) . '</div>';
+ // if this user logged in through twitter and never set up an email address, don't
+ // let them disassociate their account.
+ if ($user->email) {
+ $url = elgg_get_site_url() . "twitter_api/revoke";
+ echo '<div class="twitter_anywhere">' . elgg_echo('twitter_api:usersettings:authorized', array($site_name, $twitter_name)) . '</div>';
+ echo '<div>' . sprintf(elgg_echo('twitter_api:usersettings:revoke'), $url) . '</div>';
+ } else {
+ echo elgg_echo('twitter_api:usersettings:cannot_revoke', array(elgg_normalize_url('twitter_api/interstitial')));
+ }
}