aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mod/twitterservice/languages/en.php15
-rw-r--r--mod/twitterservice/twitterservice_lib.php56
-rw-r--r--mod/twitterservice/views/default/settings/twitterservice/edit.php13
3 files changed, 56 insertions, 28 deletions
diff --git a/mod/twitterservice/languages/en.php b/mod/twitterservice/languages/en.php
index 06c90f3b7..78d5877b2 100644
--- a/mod/twitterservice/languages/en.php
+++ b/mod/twitterservice/languages/en.php
@@ -5,24 +5,25 @@
$english = array(
'twitterservice' => 'Twitter Services',
-
+
'twitterservice:requires_oauth' => 'Twitter Services requires the OAuth Libraries plugin to be enabled.',
-
+
'twitterservice:consumer_key' => 'Consumer Key',
'twitterservice:consumer_secret' => 'Consumer Secret',
-
+
'twitterservice:settings:instructions' => 'You must obtain a consumer key and secret from <a href="https://twitter.com/oauth_clients" target="_blank">Twitter</a>. Most of the fields are self explanatory, the one piece of data you will need is the callback url which takes the form http://[yoursite]/action/twitterlogin/return - [yoursite] is the url of your Elgg network.',
-
+
'twitterservice:usersettings:description' => "Link your %s account with Twitter.",
'twitterservice:usersettings:request' => "You must first <a href=\"%s\">authorize</a> %s to access your Twitter account.",
'twitterservice:authorize:error' => 'Unable to authorize Twitter.',
'twitterservice:authorize:success' => 'Twitter access has been authorized.',
-
+
'twitterservice:usersettings:authorized' => "You have authorized %s to access your Twitter account: @%s.",
'twitterservice:usersettings:revoke' => 'Click <a href="%s">here</a> to revoke access.',
'twitterservice:revoke:success' => 'Twitter access has been revoked.',
-
- 'twitterservice:login' => 'Allow users to sign in with Twitter?',
+
+ 'twitterservice:login' => 'Allow existing users who have connected their Twitter account to sign in with Twitter?',
+ 'twitterservice:new_users' => 'Allow new users to sign up using their Twitter account even if manual registration is disabled?',
'twitterservice:login:success' => 'You have been logged in.',
'twitterservice:login:error' => 'Unable to login with Twitter.',
'twitterservice:login:email' => "You must enter a valid email address for your new %s account.",
diff --git a/mod/twitterservice/twitterservice_lib.php b/mod/twitterservice/twitterservice_lib.php
index 074c7d16c..fa6fb9111 100644
--- a/mod/twitterservice/twitterservice_lib.php
+++ b/mod/twitterservice/twitterservice_lib.php
@@ -99,7 +99,7 @@ function twitterservice_login() {
// create new user
if (!$user) {
// check new registration allowed
- if (!elgg_get_config('allow_registration')) {
+ if (!twitterservice_allow_new_users_with_twitter()) {
register_error(elgg_echo('registerdisabled'));
forward();
}
@@ -112,32 +112,32 @@ function twitterservice_login() {
}
// Elgg-ify Twitter credentials
- $username = "{$twitter->screen_name}_twitter";
- $display_name = $twitter->name;
- $password = generate_random_cleartext_password();
+ $username = $twitter->screen_name;
+ while (get_user_by_username($username)) {
+ $username = $twitter->screen_name . '_' . rand(1000, 9999);
+ }
- // @hack Temporary, junk email account to allow user creation
- $email = "$username@elgg.com";
-
- try {
- // create new account
- if (!$user_id = register_user($username, $password, $display_name, $email)) {
- register_error(elgg_echo('registerbad'));
- forward();
- }
- } catch (RegistrationException $r) {
- register_error($r->getMessage());
+ $password = generate_random_cleartext_password();
+ $name = $twitter->name;
+
+ $user = new ElggUser();
+ $user->username = $username;
+ $user->name = $name;
+ $user->access_id = ACCESS_PUBLIC;
+ $user->salt = generate_random_cleartext_password();
+ $user->password = generate_user_password($user, $password);
+ $user->owner_guid = 0;
+ $user->container_guid = 0;
+
+ if (!$user->save()) {
+ register_error(elgg_echo('registerbad'));
forward();
}
- $user = new ElggUser($user_id);
+ // @todo require email address?
- // @hack Remove temporary email and forward to user settings page
- // @todo Consider using a view to force valid email
$site_name = elgg_get_site_entity()->name;
system_message(elgg_echo('twitterservice:login:email', array($site_name)));
- $user->email = '';
- $user->save();
$forward = "pg/settings/user/{$user->username}";
}
@@ -304,3 +304,19 @@ function twitterservice_get_access_token($oauth_verifier = FALSE) {
$api = new TwitterOAuth($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret);
return $api->getAccessToken($oauth_verifier);
}
+
+/**
+ * Checks if this site is accepting new users.
+ * Admins can disable manual registration, but some might want to allow
+ * twitter-only logins.
+ */
+function twitterservice_allow_new_users_with_twitter() {
+ $site_reg = elgg_get_config('allow_registration');
+ $twitter_reg = elgg_get_plugin_setting('new_users');
+
+ if ($site_reg || (!$site_reg && $twitter_reg)) {
+ return true;
+ }
+
+ return false;
+} \ No newline at end of file
diff --git a/mod/twitterservice/views/default/settings/twitterservice/edit.php b/mod/twitterservice/views/default/settings/twitterservice/edit.php
index 7e43762ce..f84710af3 100644
--- a/mod/twitterservice/views/default/settings/twitterservice/edit.php
+++ b/mod/twitterservice/views/default/settings/twitterservice/edit.php
@@ -1,6 +1,6 @@
<?php
/**
- *
+ *
*/
$insert_view = elgg_view('twittersettings/extend');
@@ -28,11 +28,22 @@ $sign_on_with_twitter_view = elgg_view('input/dropdown', array(
'value' => $vars['entity']->sign_on ? $vars['entity']->sign_on : 'no',
));
+$new_users_with_twitter = elgg_echo('twitterservice:new_users');
+$new_users_with_twitter_view = elgg_view('input/dropdown', array(
+ 'internalname' => 'params[new_users]',
+ 'options_values' => array(
+ 'yes' => elgg_echo('option:yes'),
+ 'no' => elgg_echo('option:no'),
+ ),
+ 'value' => $vars['entity']->new_users ? $vars['entity']->new_users : 'no',
+));
+
$settings = <<<__HTML
<div>$insert_view</div>
<div>$consumer_key_string $consumer_key_view</div>
<div>$consumer_secret_string $consumer_secret_view</div>
<div>$sign_on_with_twitter_string $sign_on_with_twitter_view</div>
+<div>$new_users_with_twitter $new_users_with_twitter_view</div>
__HTML;
echo $settings;