From 70a4f8c0e26bfdb76f595ce501c6e84a8011fea8 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 29 Jan 2010 15:15:23 -0500 Subject: method to get the site owner --- classes/User.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'classes/User.php') diff --git a/classes/User.php b/classes/User.php index 6ea975202..b70049617 100644 --- a/classes/User.php +++ b/classes/User.php @@ -925,4 +925,30 @@ class User extends Memcached_DataObject return $share; } } + + static function siteOwner() + { + $owner = self::cacheGet('user:site_owner'); + + if ($owner === false) { // cache miss + + $pr = new Profile_role(); + + $pr->role = Profile_role::OWNER; + + $pr->orderBy('created'); + + $pr->limit(0, 1); + + if ($pr->fetch($true)) { + $owner = User::staticGet('id', $pr->profile_id); + } else { + $owner = null; + } + + self::cacheSet('user:site_owner', $owner); + } + + return $owner; + } } -- cgit v1.2.3-54-g00ecf From 8cb8b357a4383f7afb1e09fcd264aa41ac1502a6 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 29 Jan 2010 17:54:54 -0500 Subject: add hooks for user registration --- EVENTS.txt | 9 +++ classes/User.php | 171 +++++++++++++++++++++++++++++-------------------------- 2 files changed, 98 insertions(+), 82 deletions(-) (limited to 'classes/User.php') diff --git a/EVENTS.txt b/EVENTS.txt index 1ed670697..3317c80de 100644 --- a/EVENTS.txt +++ b/EVENTS.txt @@ -699,3 +699,12 @@ StartShowContentLicense: Showing the default license for content EndShowContentLicense: Showing the default license for content - $action: the current action + +StartUserRegister: When a new user is being registered +- &$profile: new profile data (no ID) +- &$user: new user account (no ID or URI) + +EndUserRegister: When a new user has been registered +- &$profile: new profile data +- &$user: new user account + diff --git a/classes/User.php b/classes/User.php index b70049617..022044aac 100644 --- a/classes/User.php +++ b/classes/User.php @@ -209,8 +209,6 @@ class User extends Memcached_DataObject $profile = new Profile(); - $profile->query('BEGIN'); - if(!empty($email)) { $email = common_canonical_email($email); @@ -220,7 +218,7 @@ class User extends Memcached_DataObject $profile->nickname = $nickname; if(! User::allowed_nickname($nickname)){ common_log(LOG_WARNING, sprintf("Attempted to register a nickname that is not allowed: %s", $profile->nickname), - __FILE__); + __FILE__); } $profile->profileurl = common_profile_url($nickname); @@ -248,16 +246,8 @@ class User extends Memcached_DataObject $profile->created = common_sql_now(); - $id = $profile->insert(); - - if (empty($id)) { - common_log_db_error($profile, 'INSERT', __FILE__); - return false; - } - $user = new User(); - $user->id = $id; $user->nickname = $nickname; if (!empty($password)) { // may not have a password for OpenID users @@ -282,109 +272,126 @@ class User extends Memcached_DataObject $user->inboxed = 1; $user->created = common_sql_now(); - $user->uri = common_user_uri($user); - $result = $user->insert(); + if (Event::handle('StartUserRegister', array(&$user, &$profile))) { - if (!$result) { - common_log_db_error($user, 'INSERT', __FILE__); - return false; - } + $profile->query('BEGIN'); - // Everyone gets an inbox + $id = $profile->insert(); - $inbox = new Inbox(); + if (empty($id)) { + common_log_db_error($profile, 'INSERT', __FILE__); + return false; + } - $inbox->user_id = $user->id; - $inbox->notice_ids = ''; + $user->id = $id; + $user->uri = common_user_uri($user); - $result = $inbox->insert(); + $result = $user->insert(); - if (!$result) { - common_log_db_error($inbox, 'INSERT', __FILE__); - return false; - } + if (!$result) { + common_log_db_error($user, 'INSERT', __FILE__); + return false; + } - // Everyone is subscribed to themself + // Everyone gets an inbox - $subscription = new Subscription(); - $subscription->subscriber = $user->id; - $subscription->subscribed = $user->id; - $subscription->created = $user->created; + $inbox = new Inbox(); - $result = $subscription->insert(); + $inbox->user_id = $user->id; + $inbox->notice_ids = ''; - if (!$result) { - common_log_db_error($subscription, 'INSERT', __FILE__); - return false; - } - - if (!empty($email) && !$user->email) { - - $confirm = new Confirm_address(); - $confirm->code = common_confirmation_code(128); - $confirm->user_id = $user->id; - $confirm->address = $email; - $confirm->address_type = 'email'; + $result = $inbox->insert(); - $result = $confirm->insert(); if (!$result) { - common_log_db_error($confirm, 'INSERT', __FILE__); + common_log_db_error($inbox, 'INSERT', __FILE__); return false; } - } - if (!empty($code) && $user->email) { - $user->emailChanged(); - } + // Everyone is subscribed to themself - // Default system subscription + $subscription = new Subscription(); + $subscription->subscriber = $user->id; + $subscription->subscribed = $user->id; + $subscription->created = $user->created; - $defnick = common_config('newuser', 'default'); + $result = $subscription->insert(); - if (!empty($defnick)) { - $defuser = User::staticGet('nickname', $defnick); - if (empty($defuser)) { - common_log(LOG_WARNING, sprintf("Default user %s does not exist.", $defnick), - __FILE__); - } else { - $defsub = new Subscription(); - $defsub->subscriber = $user->id; - $defsub->subscribed = $defuser->id; - $defsub->created = $user->created; + if (!$result) { + common_log_db_error($subscription, 'INSERT', __FILE__); + return false; + } + + if (!empty($email) && !$user->email) { + + $confirm = new Confirm_address(); + $confirm->code = common_confirmation_code(128); + $confirm->user_id = $user->id; + $confirm->address = $email; + $confirm->address_type = 'email'; - $result = $defsub->insert(); + $result = $confirm->insert(); if (!$result) { - common_log_db_error($defsub, 'INSERT', __FILE__); + common_log_db_error($confirm, 'INSERT', __FILE__); return false; } } - } - $profile->query('COMMIT'); + if (!empty($code) && $user->email) { + $user->emailChanged(); + } - if (!empty($email) && !$user->email) { - mail_confirm_address($user, $confirm->code, $profile->nickname, $email); - } + // Default system subscription - // Welcome message + $defnick = common_config('newuser', 'default'); - $welcome = common_config('newuser', 'welcome'); + if (!empty($defnick)) { + $defuser = User::staticGet('nickname', $defnick); + if (empty($defuser)) { + common_log(LOG_WARNING, sprintf("Default user %s does not exist.", $defnick), + __FILE__); + } else { + $defsub = new Subscription(); + $defsub->subscriber = $user->id; + $defsub->subscribed = $defuser->id; + $defsub->created = $user->created; - if (!empty($welcome)) { - $welcomeuser = User::staticGet('nickname', $welcome); - if (empty($welcomeuser)) { - common_log(LOG_WARNING, sprintf("Welcome user %s does not exist.", $defnick), - __FILE__); - } else { - $notice = Notice::saveNew($welcomeuser->id, - sprintf(_('Welcome to %1$s, @%2$s!'), - common_config('site', 'name'), - $user->nickname), - 'system'); + $result = $defsub->insert(); + if (!$result) { + common_log_db_error($defsub, 'INSERT', __FILE__); + return false; + } + } } + + $profile->query('COMMIT'); + + if (!empty($email) && !$user->email) { + mail_confirm_address($user, $confirm->code, $profile->nickname, $email); + } + + // Welcome message + + $welcome = common_config('newuser', 'welcome'); + + if (!empty($welcome)) { + $welcomeuser = User::staticGet('nickname', $welcome); + if (empty($welcomeuser)) { + common_log(LOG_WARNING, sprintf("Welcome user %s does not exist.", $defnick), + __FILE__); + } else { + $notice = Notice::saveNew($welcomeuser->id, + sprintf(_('Welcome to %1$s, @%2$s!'), + common_config('site', 'name'), + $user->nickname), + 'system'); + + } + } + + Event::handle('EndUserRegister', array(&$profile, &$user)); } return $user; -- cgit v1.2.3-54-g00ecf From fb36094eb176055f175e69bf9e6f11ff477cc11c Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 31 Jan 2010 22:55:07 -0500 Subject: buggy fetch for site owner --- classes/User.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'classes/User.php') diff --git a/classes/User.php b/classes/User.php index 022044aac..4013fbc83 100644 --- a/classes/User.php +++ b/classes/User.php @@ -945,9 +945,9 @@ class User extends Memcached_DataObject $pr->orderBy('created'); - $pr->limit(0, 1); + $pr->limit(1); - if ($pr->fetch($true)) { + if ($pr->find(true)) { $owner = User::staticGet('id', $pr->profile_id); } else { $owner = null; -- cgit v1.2.3-54-g00ecf From f9cb1c32650ff755b79837594fabb20f64e0fe1f Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Feb 2010 00:47:50 -0500 Subject: restructuring of User::registerNew() lost password munging --- classes/User.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'classes/User.php') diff --git a/classes/User.php b/classes/User.php index 4013fbc83..0ab816b57 100644 --- a/classes/User.php +++ b/classes/User.php @@ -250,10 +250,6 @@ class User extends Memcached_DataObject $user->nickname = $nickname; - if (!empty($password)) { // may not have a password for OpenID users - $user->password = common_munge_password($password, $id); - } - // Users who respond to invite email have proven their ownership of that address if (!empty($code)) { @@ -286,6 +282,9 @@ class User extends Memcached_DataObject $user->id = $id; $user->uri = common_user_uri($user); + if (!empty($password)) { // may not have a password for OpenID users + $user->password = common_munge_password($password, $id); + } $result = $user->insert(); -- cgit v1.2.3-54-g00ecf