add hooks for user registration
This commit is contained in:
parent
2a054a50fb
commit
8cb8b357a4
|
@ -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
|
||||
|
||||
|
|
199
classes/User.php
199
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();
|
||||
|
||||
$inbox->user_id = $user->id;
|
||||
$inbox->notice_ids = '';
|
||||
|
||||
$result = $inbox->insert();
|
||||
|
||||
if (!$result) {
|
||||
common_log_db_error($inbox, 'INSERT', __FILE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Everyone is subscribed to themself
|
||||
|
||||
$subscription = new Subscription();
|
||||
$subscription->subscriber = $user->id;
|
||||
$subscription->subscribed = $user->id;
|
||||
$subscription->created = $user->created;
|
||||
|
||||
$result = $subscription->insert();
|
||||
|
||||
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 = $confirm->insert();
|
||||
if (!$result) {
|
||||
common_log_db_error($confirm, 'INSERT', __FILE__);
|
||||
if (empty($id)) {
|
||||
common_log_db_error($profile, 'INSERT', __FILE__);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($code) && $user->email) {
|
||||
$user->emailChanged();
|
||||
}
|
||||
$user->id = $id;
|
||||
$user->uri = common_user_uri($user);
|
||||
|
||||
// Default system subscription
|
||||
$result = $user->insert();
|
||||
|
||||
$defnick = common_config('newuser', 'default');
|
||||
if (!$result) {
|
||||
common_log_db_error($user, 'INSERT', __FILE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
// Everyone gets an inbox
|
||||
|
||||
$result = $defsub->insert();
|
||||
$inbox = new Inbox();
|
||||
|
||||
$inbox->user_id = $user->id;
|
||||
$inbox->notice_ids = '';
|
||||
|
||||
$result = $inbox->insert();
|
||||
|
||||
if (!$result) {
|
||||
common_log_db_error($inbox, 'INSERT', __FILE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Everyone is subscribed to themself
|
||||
|
||||
$subscription = new Subscription();
|
||||
$subscription->subscriber = $user->id;
|
||||
$subscription->subscribed = $user->id;
|
||||
$subscription->created = $user->created;
|
||||
|
||||
$result = $subscription->insert();
|
||||
|
||||
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 = $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($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');
|
||||
|
||||
if (!empty($code) && $user->email) {
|
||||
$user->emailChanged();
|
||||
}
|
||||
|
||||
// Default system subscription
|
||||
|
||||
$defnick = common_config('newuser', 'default');
|
||||
|
||||
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;
|
||||
|
||||
$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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user