Exemple #1
0
 /**
  * Add the address passed in by the user
  *
  * @return void
  */
 function addAddress()
 {
     $user = common_current_user();
     $email = $this->trimmed('email');
     // Some validation
     if (!$email) {
         $this->showForm(_('未填写邮箱地址'));
         return;
     }
     $email = common_canonical_email($email);
     if (!$email) {
         $this->showForm(_('邮件地址格式错误'));
         return;
     }
     if (!Validate::email($email, common_config('email', 'check_domain'))) {
         $this->showForm(_('邮件地址格式错误'));
         return;
     } else {
         if ($user->email == $email) {
             $this->showForm(_('新邮件地址与原邮件地址相同'));
             return;
         } else {
             if ($this->emailExists($email)) {
                 $this->showForm(_('此邮件地址属于其他用户'));
                 return;
             }
         }
     }
     $confirm = new Confirm_address();
     $confirm->address = $email;
     $confirm->address_type = 'email';
     $confirm->user_id = $user->id;
     $confirm->code = common_confirmation_code(64);
     $result = $confirm->insert();
     if ($result === false) {
         common_log_db_error($confirm, 'INSERT', __FILE__);
         $this->serverError(_('生成验证邮件失败,请返回重试'));
         return;
     }
     mail_confirm_address($user, $confirm->code, $user->nickname, $email);
     $msg = _('验证邮件已经发送,请稍候查看邮箱以确认验证信息');
     $this->showForm($msg, true);
 }
Exemple #2
0
 /**
  * Register a new user account and profile and set up default subscriptions.
  * If a new-user welcome message is configured, this will be sent.
  *
  * @param array $fields associative array of optional properties
  *              string 'bio'
  *              string 'email'
  *              bool 'email_confirmed' pass true to mark email as pre-confirmed
  *              string 'fullname'
  *              string 'homepage'
  *              string 'location' informal string description of geolocation
  *              float 'lat' decimal latitude for geolocation
  *              float 'lon' decimal longitude for geolocation
  *              int 'location_id' geoname identifier
  *              int 'location_ns' geoname namespace to interpret location_id
  *              string 'nickname' REQUIRED
  *              string 'password' (may be missing for eg OpenID registrations)
  *              string 'code' invite code
  *              ?string 'uri' permalink to notice; defaults to local notice URL
  * @return mixed User object or false on failure
  */
 static function register($fields)
 {
     // MAGICALLY put fields into current scope
     extract($fields);
     $profile = new Profile();
     if (!empty($email)) {
         $email = common_canonical_email($email);
     }
     $nickname = common_canonical_nickname($nickname);
     $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__);
         return false;
     }
     $profile->profileurl = common_profile_url($nickname);
     if (!empty($fullname)) {
         $profile->fullname = $fullname;
     }
     if (!empty($homepage)) {
         $profile->homepage = $homepage;
     }
     if (!empty($bio)) {
         $profile->bio = $bio;
     }
     if (!empty($location)) {
         $profile->location = $location;
         $loc = Location::fromName($location);
         if (!empty($loc)) {
             $profile->lat = $loc->lat;
             $profile->lon = $loc->lon;
             $profile->location_id = $loc->location_id;
             $profile->location_ns = $loc->location_ns;
         }
     }
     $profile->created = common_sql_now();
     $user = new User();
     $user->nickname = $nickname;
     // Users who respond to invite email have proven their ownership of that address
     if (!empty($code)) {
         $invite = Invitation::staticGet($code);
         if ($invite && $invite->address && $invite->address_type == 'email' && $invite->address == $email) {
             $user->email = $invite->address;
         }
     }
     if (isset($email_confirmed) && $email_confirmed) {
         $user->email = $email;
     }
     // This flag is ignored but still set to 1
     $user->inboxed = 1;
     // Set default-on options here, otherwise they'll be disabled
     // initially for sites using caching, since the initial encache
     // doesn't know about the defaults in the database.
     $user->emailnotifysub = 1;
     $user->emailnotifyfav = 1;
     $user->emailnotifynudge = 1;
     $user->emailnotifymsg = 1;
     $user->emailnotifyattn = 1;
     $user->emailmicroid = 1;
     $user->emailpost = 1;
     $user->jabbermicroid = 1;
     $user->viewdesigns = 1;
     $user->created = common_sql_now();
     if (Event::handle('StartUserRegister', array(&$user, &$profile))) {
         $profile->query('BEGIN');
         $id = $profile->insert();
         if (empty($id)) {
             common_log_db_error($profile, 'INSERT', __FILE__);
             return false;
         }
         $user->id = $id;
         if (!empty($uri)) {
             $user->uri = $uri;
         } else {
             $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();
         if (!$result) {
             common_log_db_error($user, 'INSERT', __FILE__);
             return false;
         }
         // Everyone gets an inbox
         $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__);
                 return false;
             }
         }
         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 {
                 Subscription::start($user, $defuser);
             }
         }
         $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;
 }
Exemple #3
0
 /**
  * Add the address passed in by the user
  *
  * @return void
  */
 function addAddress()
 {
     $user = common_current_user();
     $email = $this->trimmed('email');
     // Some validation
     if (!$email) {
         // TRANS: Message given saving e-mail address without having provided one.
         $this->showForm(_('No email address.'));
         return;
     }
     $email = common_canonical_email($email);
     if (!$email) {
         // TRANS: Message given saving e-mail address that cannot be normalised.
         $this->showForm(_('Cannot normalize that email address'));
         return;
     }
     if (!Validate::email($email, common_config('email', 'check_domain'))) {
         // TRANS: Message given saving e-mail address that not valid.
         $this->showForm(_('Not a valid email address.'));
         return;
     } else {
         if ($user->email == $email) {
             // TRANS: Message given saving e-mail address that is already set.
             $this->showForm(_('That is already your email address.'));
             return;
         } else {
             if ($this->emailExists($email)) {
                 // TRANS: Message given saving e-mail address that is already set for another user.
                 $this->showForm(_('That email address already belongs ' . 'to another user.'));
                 return;
             }
         }
     }
     $confirm = new Confirm_address();
     $confirm->address = $email;
     $confirm->address_type = 'email';
     $confirm->user_id = $user->id;
     $confirm->code = common_confirmation_code(64);
     $result = $confirm->insert();
     if ($result === false) {
         common_log_db_error($confirm, 'INSERT', __FILE__);
         // TRANS: Server error thrown on database error adding e-mail confirmation code.
         $this->serverError(_('Couldn\'t insert confirmation code.'));
         return;
     }
     mail_confirm_address($user, $confirm->code, $user->nickname, $email);
     // TRANS: Message given saving valid e-mail address that is to be confirmed.
     $msg = _('A confirmation code was sent to the email address you added. ' . 'Check your inbox (and spam box!) for the code and instructions ' . 'on how to use it.');
     $this->showForm($msg, true);
 }
  -e email     Email to register

END_OF_REGISTERBYEMAIL_HELP;
require_once INSTALLDIR . '/scripts/commandline.inc';
$email = get_option_value('e', 'email');
$parts = explode('@', $email);
$nickname = common_nicknamize($parts[0]);
$user = User::getKV('nickname', $nickname);
if (!empty($user)) {
    $confirm = new Confirm_address();
    $confirm->user_id = $user->id;
    $confirm->address_type = 'email';
    if ($confirm->find(true)) {
        $url = common_local_url('confirmfirstemail', array('code' => $confirm->code));
        print "{$url}\n";
    } else {
        print "User not waiting for confirmation.\n";
    }
    exit;
}
$user = User::register(array('nickname' => $nickname, 'password' => null));
$confirm = new Confirm_address();
$confirm->code = common_confirmation_code(128);
$confirm->user_id = $user->id;
$confirm->address = $email;
$confirm->address_type = 'email';
$confirm->insert();
$url = common_local_url('confirmfirstemail', array('code' => $confirm->code));
print "{$url}\n";
mail_confirm_address($user, $confirm->code, $user->nickname, $email, $url);
Exemple #5
0
 /**
  * Add the address passed in by the user
  *
  * @return void
  */
 function addAddress()
 {
     $user = common_current_user();
     $email = $this->trimmed('email');
     // Some validation
     if (!$email) {
         $this->showForm(_('No email address.'));
         return;
     }
     $email = common_canonical_email($email);
     if (!$email) {
         $this->showForm(_('Cannot normalize that email address'));
         return;
     }
     if (!Validate::email($email, true)) {
         $this->showForm(_('Not a valid email address'));
         return;
     } else {
         if ($user->email == $email) {
             $this->showForm(_('That is already your email address.'));
             return;
         } else {
             if ($this->emailExists($email)) {
                 $this->showForm(_('That email address already belongs ' . 'to another user.'));
                 return;
             }
         }
     }
     $confirm = new Confirm_address();
     $confirm->address = $email;
     $confirm->address_type = 'email';
     $confirm->user_id = $user->id;
     $confirm->code = common_confirmation_code(64);
     $result = $confirm->insert();
     if ($result === false) {
         common_log_db_error($confirm, 'INSERT', __FILE__);
         $this->serverError(_('Couldn\'t insert confirmation code.'));
         return;
     }
     mail_confirm_address($user, $confirm->code, $user->nickname, $email);
     $msg = _('A confirmation code was sent to the email address you added. ' . 'Check your inbox (and spam box!) for the code and instructions ' . 'on how to use it.');
     $this->showForm($msg, true);
 }
 /**
  * Add the address passed in by the user
  *
  * @return void
  */
 function addAddress()
 {
     $user = $this->scoped->getUser();
     $email = $this->trimmed('email');
     // Some validation
     if (empty($email)) {
         // TRANS: Message given saving e-mail address without having provided one.
         throw new ClientException(_('No email address.'));
     }
     $email = common_canonical_email($email);
     if (empty($email)) {
         // TRANS: Message given saving e-mail address that cannot be normalised.
         throw new ClientException(_('Cannot normalize that email address.'));
     }
     if (!Validate::email($email, common_config('email', 'check_domain'))) {
         // TRANS: Message given saving e-mail address that not valid.
         throw new ClientException(_('Not a valid email address.'));
     } else {
         if ($user->email == $email) {
             // TRANS: Message given saving e-mail address that is already set.
             throw new ClientException(_('That is already your email address.'));
         } else {
             if ($this->emailExists($email)) {
                 // TRANS: Message given saving e-mail address that is already set for another user.
                 throw new ClientException(_('That email address already belongs to another user.'));
             }
         }
     }
     if (Event::handle('StartAddEmailAddress', array($user, $email))) {
         $confirm = new Confirm_address();
         $confirm->address = $email;
         $confirm->address_type = 'email';
         $confirm->user_id = $user->getID();
         $confirm->code = common_confirmation_code(64);
         $result = $confirm->insert();
         if ($result === false) {
             common_log_db_error($confirm, 'INSERT', __FILE__);
             // TRANS: Server error thrown on database error adding e-mail confirmation code.
             throw new ServerException(_('Could not insert confirmation code.'));
         }
         common_debug('Sending confirmation address for user ' . $user->getID() . ' to email ' . $email);
         mail_confirm_address($user, $confirm->code, $user->getNickname(), $email);
         Event::handle('EndAddEmailAddress', array($user, $email));
     }
     // TRANS: Message given saving valid e-mail address that is to be confirmed.
     return _('A confirmation code was sent to the email address you added. ' . 'Check your inbox (and spam box!) for the code and instructions ' . 'on how to use it.');
 }
Exemple #7
0
 /**
  * Register a new user account and profile and set up default subscriptions.
  * If a new-user welcome message is configured, this will be sent.
  *
  * @param array $fields associative array of optional properties
  *              string 'bio'
  *              string 'email'
  *              bool 'email_confirmed' pass true to mark email as pre-confirmed
  *              string 'fullname'
  *              string 'homepage'
  *              string 'location' informal string description of geolocation
  *              float 'lat' decimal latitude for geolocation
  *              float 'lon' decimal longitude for geolocation
  *              int 'location_id' geoname identifier
  *              int 'location_ns' geoname namespace to interpret location_id
  *              string 'nickname' REQUIRED
  *              string 'password' (may be missing for eg OpenID registrations)
  *              string 'code' invite code
  *              ?string 'uri' permalink to notice; defaults to local notice URL
  * @return  User object
  * @throws  Exception on failure
  */
 static function register(array $fields)
 {
     // MAGICALLY put fields into current scope
     extract($fields);
     $profile = new Profile();
     if (!empty($email)) {
         $email = common_canonical_email($email);
     }
     // Normalize _and_ check whether it is in use. Throw NicknameException on failure.
     $profile->nickname = Nickname::normalize($nickname, true);
     $profile->profileurl = common_profile_url($profile->nickname);
     if (!empty($fullname)) {
         $profile->fullname = $fullname;
     }
     if (!empty($homepage)) {
         $profile->homepage = $homepage;
     }
     if (!empty($bio)) {
         $profile->bio = $bio;
     }
     if (!empty($location)) {
         $profile->location = $location;
         $loc = Location::fromName($location);
         if (!empty($loc)) {
             $profile->lat = $loc->lat;
             $profile->lon = $loc->lon;
             $profile->location_id = $loc->location_id;
             $profile->location_ns = $loc->location_ns;
         }
     }
     $profile->created = common_sql_now();
     $user = new User();
     $user->nickname = $profile->nickname;
     $invite = null;
     // Users who respond to invite email have proven their ownership of that address
     if (!empty($code)) {
         $invite = Invitation::getKV($code);
         if ($invite instanceof Invitation && $invite->address && $invite->address_type == 'email' && $invite->address == $email) {
             $user->email = $invite->address;
         }
     }
     if (isset($email_confirmed) && $email_confirmed) {
         $user->email = $email;
     }
     // Set default-on options here, otherwise they'll be disabled
     // initially for sites using caching, since the initial encache
     // doesn't know about the defaults in the database.
     $user->emailnotifysub = 1;
     $user->emailnotifynudge = 1;
     $user->emailnotifymsg = 1;
     $user->emailnotifyattn = 1;
     $user->emailmicroid = 1;
     $user->emailpost = 1;
     $user->jabbermicroid = 1;
     $user->created = common_sql_now();
     if (Event::handle('StartUserRegister', array($profile))) {
         $profile->query('BEGIN');
         $id = $profile->insert();
         if ($id === false) {
             common_log_db_error($profile, 'INSERT', __FILE__);
             $profile->query('ROLLBACK');
             // TRANS: Profile data could not be inserted for some reason.
             throw new ServerException(_m('Could not insert profile data for new user.'));
         }
         $user->id = $id;
         if (!empty($uri)) {
             $user->uri = $uri;
         } else {
             $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();
         if ($result === false) {
             common_log_db_error($user, 'INSERT', __FILE__);
             $profile->query('ROLLBACK');
             // TRANS: User data could not be inserted for some reason.
             throw new ServerException(_m('Could not insert user data for new user.'));
         }
         // 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__);
             $profile->query('ROLLBACK');
             // TRANS: Subscription data could not be inserted for some reason.
             throw new ServerException(_m('Could not insert subscription data for new user.'));
         }
         // Mark that this invite was converted
         if (!empty($invite)) {
             $invite->convert($user);
         }
         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__);
                 $profile->query('ROLLBACK');
                 // TRANS: Email confirmation data could not be inserted for some reason.
                 throw new ServerException(_m('Could not insert email confirmation data for new user.'));
             }
         }
         if (!empty($code) && $user->email) {
             $user->emailChanged();
         }
         // Default system subscription
         $defnick = common_config('newuser', 'default');
         if (!empty($defnick)) {
             $defuser = User::getKV('nickname', $defnick);
             if (empty($defuser)) {
                 common_log(LOG_WARNING, sprintf("Default user %s does not exist.", $defnick), __FILE__);
             } else {
                 Subscription::ensureStart($profile, $defuser->getProfile());
             }
         }
         $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::getKV('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));
     }
     if (!$user instanceof User) {
         throw new ServerException('User could not be registered. Probably an event hook that failed.');
     }
     return $user;
 }
Exemple #8
0
 static function register($fields)
 {
     # MAGICALLY put fields into current scope
     extract($fields);
     $profile = new Profile();
     $profile->query('BEGIN');
     $profile->nickname = $nickname;
     $profile->profileurl = common_profile_url($nickname);
     if (!empty($fullname)) {
         $profile->fullname = $fullname;
     }
     if (!empty($homepage)) {
         $profile->homepage = $homepage;
     }
     if (!empty($bio)) {
         $profile->bio = $bio;
     }
     if (!empty($location)) {
         $profile->location = $location;
     }
     $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
         $user->password = common_munge_password($password, $id);
     }
     # Users who respond to invite email have proven their ownership of that address
     if (!empty($code)) {
         $invite = Invitation::staticGet($code);
         if ($invite && $invite->address && $invite->address_type == 'email' && $invite->address == $email) {
             $user->email = $invite->address;
         }
     }
     $inboxes = common_config('inboxes', 'enabled');
     if ($inboxes === true || $inboxes == 'transitional') {
         $user->inboxed = 1;
     }
     $user->created = common_sql_now();
     $user->uri = common_user_uri($user);
     $result = $user->insert();
     if (!$result) {
         common_log_db_error($user, '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__);
             return false;
         }
     }
     if (!empty($code) && $user->email) {
         $user->emailChanged();
     }
     $profile->query('COMMIT');
     if ($email && !$user->email) {
         mail_confirm_address($user, $confirm->code, $profile->nickname, $email);
     }
     return $user;
 }