aboutsummaryrefslogtreecommitdiff
path: root/mod/twitterservice/twitterservice_lib.php
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-02-12 19:22:55 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-02-12 19:22:55 +0000
commit606b7b6a101bf109817567b1a2b0a7e831768766 (patch)
tree954659456b0b9dbfe4fcfb6a01619d01d64ac20b /mod/twitterservice/twitterservice_lib.php
parent628239ea178e1690b0520b334e0d552bfbfe8f43 (diff)
downloadelgg-606b7b6a101bf109817567b1a2b0a7e831768766.tar.gz
elgg-606b7b6a101bf109817567b1a2b0a7e831768766.tar.bz2
Cleaned up more twitterservice code. Twitter usernames now have random digits appended upon name collision. Added the option for admins to allow twitter sign up even if site registration is disabled.
git-svn-id: http://code.elgg.org/elgg/trunk@8169 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod/twitterservice/twitterservice_lib.php')
-rw-r--r--mod/twitterservice/twitterservice_lib.php56
1 files changed, 36 insertions, 20 deletions
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