3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('GNUSOCIAL')) { exit(1); }
23 * Table Definition for user
26 class User extends Managed_DataObject
28 const SUBSCRIBE_POLICY_OPEN = 0;
29 const SUBSCRIBE_POLICY_MODERATE = 1;
32 /* the code below is auto generated do not remove the above tag */
34 public $__table = 'user'; // table name
35 public $id; // int(4) primary_key not_null
36 public $nickname; // varchar(64) unique_key
37 public $password; // varchar(255)
38 public $email; // varchar(255) unique_key
39 public $incomingemail; // varchar(255) unique_key
40 public $emailnotifysub; // tinyint(1) default_1
41 public $emailnotifyfav; // tinyint(1) default_1
42 public $emailnotifynudge; // tinyint(1) default_1
43 public $emailnotifymsg; // tinyint(1) default_1
44 public $emailnotifyattn; // tinyint(1) default_1
45 public $emailmicroid; // tinyint(1) default_1
46 public $language; // varchar(50)
47 public $timezone; // varchar(50)
48 public $emailpost; // tinyint(1) default_1
49 public $sms; // varchar(64) unique_key
50 public $carrier; // int(4)
51 public $smsnotify; // tinyint(1)
52 public $smsreplies; // tinyint(1)
53 public $smsemail; // varchar(255)
54 public $uri; // varchar(255) unique_key
55 public $autosubscribe; // tinyint(1)
56 public $subscribe_policy; // tinyint(1)
57 public $urlshorteningservice; // varchar(50) default_ur1.ca
58 public $private_stream; // tinyint(1) default_0
59 public $created; // datetime() not_null
60 public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
62 /* the code above is auto generated do not remove the tag below */
65 public static function schemaDef()
68 'description' => 'local users',
70 'id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to profile table'),
71 'nickname' => array('type' => 'varchar', 'length' => 64, 'description' => 'nickname or username, duped in profile'),
72 'password' => array('type' => 'varchar', 'length' => 255, 'description' => 'salted password, can be null for OpenID users'),
73 'email' => array('type' => 'varchar', 'length' => 255, 'description' => 'email address for password recovery etc.'),
74 'incomingemail' => array('type' => 'varchar', 'length' => 255, 'description' => 'email address for post-by-email'),
75 'emailnotifysub' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Notify by email of subscriptions'),
76 'emailnotifyfav' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Notify by email of favorites'),
77 'emailnotifynudge' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Notify by email of nudges'),
78 'emailnotifymsg' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Notify by email of direct messages'),
79 'emailnotifyattn' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Notify by email of @-replies'),
80 'emailmicroid' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'whether to publish email microid'),
81 'language' => array('type' => 'varchar', 'length' => 50, 'description' => 'preferred language'),
82 'timezone' => array('type' => 'varchar', 'length' => 50, 'description' => 'timezone'),
83 'emailpost' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Post by email'),
84 'sms' => array('type' => 'varchar', 'length' => 64, 'description' => 'sms phone number'),
85 'carrier' => array('type' => 'int', 'description' => 'foreign key to sms_carrier'),
86 'smsnotify' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'whether to send notices to SMS'),
87 'smsreplies' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'whether to send notices to SMS on replies'),
88 'smsemail' => array('type' => 'varchar', 'length' => 255, 'description' => 'built from sms and carrier'),
89 'uri' => array('type' => 'varchar', 'length' => 255, 'description' => 'universally unique identifier, usually a tag URI'),
90 'autosubscribe' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'automatically subscribe to users who subscribe to us'),
91 'subscribe_policy' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => '0 = anybody can subscribe; 1 = require approval'),
92 'urlshorteningservice' => array('type' => 'varchar', 'length' => 50, 'default' => 'internal', 'description' => 'service to use for auto-shortening URLs'),
93 'private_stream' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'whether to limit all notices to followers only'),
95 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
96 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
98 'primary key' => array('id'),
99 'unique keys' => array(
100 'user_nickname_key' => array('nickname'),
101 'user_email_key' => array('email'),
102 'user_incomingemail_key' => array('incomingemail'),
103 'user_sms_key' => array('sms'),
104 'user_uri_key' => array('uri'),
106 'foreign keys' => array(
107 'user_id_fkey' => array('profile', array('id' => 'id')),
108 'user_carrier_fkey' => array('sms_carrier', array('carrier' => 'id')),
111 'user_smsemail_idx' => array('smsemail'),
116 protected $_profile = null;
121 * @throws UserNoProfileException if user has no profile
123 public function getProfile()
125 if (!($this->_profile instanceof Profile)) {
126 $this->_profile = Profile::getKV('id', $this->id);
127 if (!($this->_profile instanceof Profile)) {
128 throw new UserNoProfileException($this);
132 return $this->_profile;
135 public function getUri()
140 public function getNickname()
142 return $this->getProfile()->getNickname();
145 function isSubscribed(Profile $other)
147 return $this->getProfile()->isSubscribed($other);
150 function hasPendingSubscription(Profile $other)
152 return $this->getProfile()->hasPendingSubscription($other);
155 // 'update' won't write key columns, so we have to do it ourselves.
157 function updateKeys(&$orig)
161 foreach (array('nickname', 'email', 'incomingemail', 'sms', 'carrier', 'smsemail') as $k) {
162 if (strcmp($this->$k, $orig->$k) != 0) {
163 $parts[] = $k . ' = ' . $this->_quote($this->$k);
166 if (count($parts) == 0) {
170 $toupdate = implode(', ', $parts);
172 $table = common_database_tablename($this->tableName());
173 $qry = 'UPDATE ' . $table . ' SET ' . $toupdate .
174 ' WHERE id = ' . $this->id;
176 $result = $this->query($qry);
184 * Get the most recent notice posted by this user, if any.
186 * @return mixed Notice or null
188 function getCurrentNotice()
190 return $this->getProfile()->getCurrentNotice();
193 function getCarrier()
195 return Sms_carrier::getKV('id', $this->carrier);
198 function hasBlocked($other)
200 return $this->getProfile()->hasBlocked($other);
204 * Register a new user account and profile and set up default subscriptions.
205 * If a new-user welcome message is configured, this will be sent.
207 * @param array $fields associative array of optional properties
210 * bool 'email_confirmed' pass true to mark email as pre-confirmed
213 * string 'location' informal string description of geolocation
214 * float 'lat' decimal latitude for geolocation
215 * float 'lon' decimal longitude for geolocation
216 * int 'location_id' geoname identifier
217 * int 'location_ns' geoname namespace to interpret location_id
218 * string 'nickname' REQUIRED
219 * string 'password' (may be missing for eg OpenID registrations)
220 * string 'code' invite code
221 * ?string 'uri' permalink to notice; defaults to local notice URL
222 * @return mixed User object or false on failure
224 static function register(array $fields) {
226 // MAGICALLY put fields into current scope
230 $profile = new Profile();
232 if (!empty($email)) {
233 $email = common_canonical_email($email);
237 $profile->nickname = Nickname::normalize($nickname, true);
238 } catch (NicknameException $e) {
239 common_log(LOG_WARNING, sprintf('Bad nickname during User registration for %s: %s', $nickname, $e->getMessage()), __FILE__);
243 $profile->profileurl = common_profile_url($profile->nickname);
245 if (!empty($fullname)) {
246 $profile->fullname = $fullname;
248 if (!empty($homepage)) {
249 $profile->homepage = $homepage;
252 $profile->bio = $bio;
254 if (!empty($location)) {
255 $profile->location = $location;
257 $loc = Location::fromName($location);
260 $profile->lat = $loc->lat;
261 $profile->lon = $loc->lon;
262 $profile->location_id = $loc->location_id;
263 $profile->location_ns = $loc->location_ns;
267 $profile->created = common_sql_now();
271 $user->nickname = $profile->nickname;
275 // Users who respond to invite email have proven their ownership of that address
278 $invite = Invitation::getKV($code);
279 if ($invite && $invite->address && $invite->address_type == 'email' && $invite->address == $email) {
280 $user->email = $invite->address;
284 if(isset($email_confirmed) && $email_confirmed) {
285 $user->email = $email;
288 // Set default-on options here, otherwise they'll be disabled
289 // initially for sites using caching, since the initial encache
290 // doesn't know about the defaults in the database.
291 $user->emailnotifysub = 1;
292 $user->emailnotifyfav = 1;
293 $user->emailnotifynudge = 1;
294 $user->emailnotifymsg = 1;
295 $user->emailnotifyattn = 1;
296 $user->emailmicroid = 1;
297 $user->emailpost = 1;
298 $user->jabbermicroid = 1;
300 $user->created = common_sql_now();
302 if (Event::handle('StartUserRegister', array($profile))) {
304 $profile->query('BEGIN');
306 $id = $profile->insert();
308 common_log_db_error($profile, 'INSERT', __FILE__);
317 $user->uri = common_user_uri($user);
320 if (!empty($password)) { // may not have a password for OpenID users
321 $user->password = common_munge_password($password, $id);
324 $result = $user->insert();
326 if ($result === false) {
327 common_log_db_error($user, 'INSERT', __FILE__);
328 $profile->query('ROLLBACK');
332 // Everyone is subscribed to themself
334 $subscription = new Subscription();
335 $subscription->subscriber = $user->id;
336 $subscription->subscribed = $user->id;
337 $subscription->created = $user->created;
339 $result = $subscription->insert();
342 common_log_db_error($subscription, 'INSERT', __FILE__);
343 $profile->query('ROLLBACK');
347 // Mark that this invite was converted
349 if (!empty($invite)) {
350 $invite->convert($user);
353 if (!empty($email) && !$user->email) {
355 $confirm = new Confirm_address();
356 $confirm->code = common_confirmation_code(128);
357 $confirm->user_id = $user->id;
358 $confirm->address = $email;
359 $confirm->address_type = 'email';
361 $result = $confirm->insert();
364 common_log_db_error($confirm, 'INSERT', __FILE__);
365 $profile->query('ROLLBACK');
370 if (!empty($code) && $user->email) {
371 $user->emailChanged();
374 // Default system subscription
376 $defnick = common_config('newuser', 'default');
378 if (!empty($defnick)) {
379 $defuser = User::getKV('nickname', $defnick);
380 if (empty($defuser)) {
381 common_log(LOG_WARNING, sprintf("Default user %s does not exist.", $defnick),
384 Subscription::start($profile, $defuser->getProfile());
388 $profile->query('COMMIT');
390 if (!empty($email) && !$user->email) {
391 mail_confirm_address($user, $confirm->code, $profile->nickname, $email);
396 $welcome = common_config('newuser', 'welcome');
398 if (!empty($welcome)) {
399 $welcomeuser = User::getKV('nickname', $welcome);
400 if (empty($welcomeuser)) {
401 common_log(LOG_WARNING, sprintf("Welcome user %s does not exist.", $defnick),
404 $notice = Notice::saveNew($welcomeuser->id,
405 // TRANS: Notice given on user registration.
406 // TRANS: %1$s is the sitename, $2$s is the registering user's nickname.
407 sprintf(_('Welcome to %1$s, @%2$s!'),
408 common_config('site', 'name'),
414 Event::handle('EndUserRegister', array($profile));
420 // Things we do when the email changes
421 function emailChanged()
424 $invites = new Invitation();
425 $invites->address = $this->email;
426 $invites->address_type = 'email';
428 if ($invites->find()) {
429 while ($invites->fetch()) {
431 $other = Profile::getKV('id', $invites->user_id);
432 if (!($other instanceof Profile)) { // remove when getKV throws exceptions
435 Subscription::start($other, $this->getProfile());
436 } catch (Exception $e) {
443 function hasFave($notice)
445 return $this->getProfile()->hasFave($notice);
448 function mutuallySubscribed(Profile $other)
450 return $this->getProfile()->mutuallySubscribed($other);
453 function mutuallySubscribedUsers()
455 // 3-way join; probably should get cached
456 $UT = common_config('db','type')=='pgsql'?'"user"':'user';
457 $qry = "SELECT $UT.* " .
458 "FROM subscription sub1 JOIN $UT ON sub1.subscribed = $UT.id " .
459 "JOIN subscription sub2 ON $UT.id = sub2.subscriber " .
460 'WHERE sub1.subscriber = %d and sub2.subscribed = %d ' .
461 "ORDER BY $UT.nickname";
463 $user->query(sprintf($qry, $this->id, $this->id));
468 function getReplies($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
470 return Reply::stream($this->id, $offset, $limit, $since_id, $before_id);
473 function getTaggedNotices($tag, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0) {
474 return $this->getProfile()->getTaggedNotices($tag, $offset, $limit, $since_id, $before_id);
477 function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
479 return $this->getProfile()->getNotices($offset, $limit, $since_id, $before_id);
482 function favoriteNotices($own=false, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
484 return $this->getProfile()->favoriteNotices($own, $offset, $limit, $since_id, $max_id);
487 function blowFavesCache()
489 $this->getProfile()->blowFavesCache();
492 function getSelfTags()
494 return Profile_tag::getTagsArray($this->id, $this->id, $this->id);
497 function setSelfTags($newtags, $privacy)
499 return Profile_tag::setTags($this->id, $this->id, $newtags, $privacy);
502 function block(Profile $other)
504 // Add a new block record
506 // no blocking (and thus unsubbing from) yourself
508 if ($this->id == $other->id) {
509 common_log(LOG_WARNING,
511 "Profile ID %d (%s) tried to block themself.",
519 $block = new Profile_block();
521 // Begin a transaction
523 $block->query('BEGIN');
525 $block->blocker = $this->id;
526 $block->blocked = $other->id;
528 $result = $block->insert();
531 common_log_db_error($block, 'INSERT', __FILE__);
535 $self = $this->getProfile();
536 if (Subscription::exists($other, $self)) {
537 Subscription::cancel($other, $self);
539 if (Subscription::exists($self, $other)) {
540 Subscription::cancel($self, $other);
543 $block->query('COMMIT');
548 function unblock(Profile $other)
550 // Get the block record
552 $block = Profile_block::exists($this->getProfile(), $other);
558 $result = $block->delete();
561 common_log_db_error($block, 'DELETE', __FILE__);
568 function isMember(User_group $group)
570 return $this->getProfile()->isMember($group);
573 function isAdmin(User_group $group)
575 return $this->getProfile()->isAdmin($group);
578 function getGroups($offset=0, $limit=null)
580 return $this->getProfile()->getGroups($offset, $limit);
584 * Request to join the given group.
585 * May throw exceptions on failure.
587 * @param User_group $group
588 * @return Group_member
590 function joinGroup(User_group $group)
592 return $this->getProfile()->joinGroup($group);
596 * Leave a group that this user is a member of.
598 * @param User_group $group
600 function leaveGroup(User_group $group)
602 return $this->getProfile()->leaveGroup($group);
605 function getSubscribed($offset=0, $limit=null)
607 return $this->getProfile()->getSubscribed($offset, $limit);
610 function getSubscribers($offset=0, $limit=null)
612 return $this->getProfile()->getSubscribers($offset, $limit);
615 function getTaggedSubscribers($tag, $offset=0, $limit=null)
617 return $this->getProfile()->getTaggedSubscribers($tag, $offset, $limit);
620 function getTaggedSubscriptions($tag, $offset=0, $limit=null)
622 return $this->getProfile()->getTaggedSubscriptions($tag, $offset, $limit);
625 function hasRight($right)
627 return $this->getProfile()->hasRight($right);
630 function delete($useWhere=false)
632 if (empty($this->id)) {
633 common_log(LOG_WARNING, "Ambiguous User->delete(); skipping related tables.");
634 return parent::delete($useWhere);
638 $profile = $this->getProfile();
640 } catch (UserNoProfileException $unp) {
641 common_log(LOG_INFO, "User {$this->nickname} has no profile; continuing deletion.");
644 $related = array('Fave',
651 Event::handle('UserDeleteRelated', array($this, &$related));
653 foreach ($related as $cls) {
655 $inst->user_id = $this->id;
659 $this->_deleteTags();
660 $this->_deleteBlocks();
662 return parent::delete($useWhere);
665 function _deleteTags()
667 $tag = new Profile_tag();
668 $tag->tagger = $this->id;
672 function _deleteBlocks()
674 $block = new Profile_block();
675 $block->blocker = $this->id;
677 // XXX delete group block? Reset blocker?
680 function hasRole($name)
682 return $this->getProfile()->hasRole($name);
685 function grantRole($name)
687 return $this->getProfile()->grantRole($name);
690 function revokeRole($name)
692 return $this->getProfile()->revokeRole($name);
695 function isSandboxed()
697 return $this->getProfile()->isSandboxed();
700 function isSilenced()
702 return $this->getProfile()->isSilenced();
705 function repeatedByMe($offset=0, $limit=20, $since_id=null, $max_id=null)
707 $stream = new RepeatedByMeNoticeStream($this);
708 return $stream->getNotices($offset, $limit, $since_id, $max_id);
712 function repeatsOfMe($offset=0, $limit=20, $since_id=null, $max_id=null)
714 $stream = new RepeatsOfMeNoticeStream($this);
716 return $stream->getNotices($offset, $limit, $since_id, $max_id);
720 function repeatedToMe($offset=0, $limit=20, $since_id=null, $max_id=null)
722 // TRANS: Exception thrown when trying view "repeated to me".
723 throw new Exception(_('Not implemented since inbox change.'));
726 public static function siteOwner()
728 $owner = self::cacheGet('user:site_owner');
730 if ($owner === false) { // cache miss
732 $pr = new Profile_role();
733 $pr->role = Profile_role::OWNER;
734 $pr->orderBy('created');
737 if (!$pr->find(true)) {
738 throw new NoResultException($pr);
741 $owner = User::getKV('id', $pr->profile_id);
743 self::cacheSet('user:site_owner', $owner);
746 if ($owner instanceof User) {
750 throw new ServerException(_('No site owner configured.'));
754 * Pull the primary site account to use in single-user mode.
755 * If a valid user nickname is listed in 'singleuser':'nickname'
756 * in the config, this will be used; otherwise the site owner
757 * account is taken by default.
760 * @throws ServerException if no valid single user account is present
761 * @throws ServerException if called when not in single-user mode
763 public static function singleUser()
765 if (!common_config('singleuser', 'enabled')) {
766 // TRANS: Server exception.
767 throw new ServerException(_('Single-user mode code called when not enabled.'));
770 if ($nickname = common_config('singleuser', 'nickname')) {
771 $user = User::getKV('nickname', $nickname);
772 if ($user instanceof User) {
777 // If there was no nickname or no user by that nickname,
778 // try the site owner. Throws exception if not configured.
779 return User::siteOwner();
783 * This is kind of a hack for using external setup code that's trying to
784 * build single-user sites.
786 * Will still return a username if the config singleuser/nickname is set
787 * even if the account doesn't exist, which normally indicates that the
788 * site is horribly misconfigured.
790 * At the moment, we need to let it through so that router setup can
791 * complete, otherwise we won't be able to create the account.
793 * This will be easier when we can more easily create the account and
794 * *then* switch the site to 1user mode without jumping through hoops.
797 * @throws ServerException if no valid single user account is present
798 * @throws ServerException if called when not in single-user mode
800 static function singleUserNickname()
803 $user = User::singleUser();
804 return $user->nickname;
805 } catch (Exception $e) {
806 if (common_config('singleuser', 'enabled') && common_config('singleuser', 'nickname')) {
807 common_log(LOG_WARNING, "Warning: code attempting to pull single-user nickname when the account does not exist. If this is not setup time, this is probably a bug.");
808 return common_config('singleuser', 'nickname');
815 * Find and shorten links in the given text using this user's URL shortening
818 * By default, links will be left untouched if the text is shorter than the
819 * configured maximum notice length. Pass true for the $always parameter
820 * to force all links to be shortened regardless.
822 * Side effects: may save file and file_redirection records for referenced URLs.
824 * @param string $text
825 * @param boolean $always
828 public function shortenLinks($text, $always=false)
830 return common_shorten_links($text, $always, $this);
834 * Get a list of OAuth client applications that have access to this
837 function getConnectedApps($offset = 0, $limit = null)
841 'FROM oauth_application_user u, oauth_application a ' .
842 'WHERE u.profile_id = %d ' .
843 'AND a.id = u.application_id ' .
844 'AND u.access_type > 0 ' .
845 'ORDER BY u.created DESC ';
848 if (common_config('db','type') == 'pgsql') {
849 $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
851 $qry .= ' LIMIT ' . $offset . ', ' . $limit;
855 $apps = new Oauth_application_user();
857 $cnt = $apps->query(sprintf($qry, $this->id));
863 * Magic function called at serialize() time.
865 * We use this to drop a couple process-specific references
866 * from DB_DataObject which can cause trouble in future
869 * @return array of variable names to include in serialization.
874 $vars = parent::__sleep();
875 $skip = array('_profile');
876 return array_diff($vars, $skip);
879 static function recoverPassword($nore)
881 $user = User::getKV('email', common_canonical_email($nore));
885 $user = User::getKV('nickname', common_canonical_nickname($nore));
886 } catch (NicknameException $e) {
891 // See if it's an unconfirmed email address
894 // Warning: it may actually be legit to have multiple folks
895 // who have claimed, but not yet confirmed, the same address.
896 // We'll only send to the first one that comes up.
897 $confirm_email = new Confirm_address();
898 $confirm_email->address = common_canonical_email($nore);
899 $confirm_email->address_type = 'email';
900 $confirm_email->find();
901 if ($confirm_email->fetch()) {
902 $user = User::getKV($confirm_email->user_id);
904 $confirm_email = null;
907 $confirm_email = null;
911 // TRANS: Information on password recovery form if no known username or e-mail address was specified.
912 throw new ClientException(_('No user with that email address or username.'));
916 // Try to get an unconfirmed email address if they used a user name
918 if (!$user->email && !$confirm_email) {
919 $confirm_email = new Confirm_address();
920 $confirm_email->user_id = $user->id;
921 $confirm_email->address_type = 'email';
922 $confirm_email->find();
923 if (!$confirm_email->fetch()) {
924 $confirm_email = null;
928 if (!$user->email && !$confirm_email) {
929 // TRANS: Client error displayed on password recovery form if a user does not have a registered e-mail address.
930 throw new ClientException(_('No registered email address for that user.'));
934 // Success! We have a valid user and a confirmed or unconfirmed email address
936 $confirm = new Confirm_address();
937 $confirm->code = common_confirmation_code(128);
938 $confirm->address_type = 'recover';
939 $confirm->user_id = $user->id;
940 $confirm->address = (!empty($user->email)) ? $user->email : $confirm_email->address;
942 if (!$confirm->insert()) {
943 common_log_db_error($confirm, 'INSERT', __FILE__);
944 // TRANS: Server error displayed if e-mail address confirmation fails in the database on the password recovery form.
945 throw new ServerException(_('Error saving address confirmation.'));
949 // @todo FIXME: needs i18n.
950 $body = "Hey, $user->nickname.";
952 $body .= 'Someone just asked for a new password ' .
953 'for this account on ' . common_config('site', 'name') . '.';
955 $body .= 'If it was you, and you want to confirm, use the URL below:';
957 $body .= "\t".common_local_url('recoverpassword',
958 array('code' => $confirm->code));
960 $body .= 'If not, just ignore this message.';
962 $body .= 'Thanks for your time, ';
964 $body .= common_config('site', 'name');
967 $headers = _mail_prepare_headers('recoverpassword', $user->nickname, $user->nickname);
968 // TRANS: Subject for password recovery e-mail.
969 mail_to_user($user, _('Password recovery requested'), $body, $headers, $confirm->address);
972 function streamModeOnly()
974 if (common_config('oldschool', 'enabled')) {
975 $osp = Old_school_prefs::getKV('user_id', $this->id);
977 return $osp->stream_mode_only;
984 function streamNicknames()
986 if (common_config('oldschool', 'enabled')) {
987 $osp = Old_school_prefs::getKV('user_id', $this->id);
989 return $osp->stream_nicknames;
995 function registrationActivity()
997 $profile = $this->getProfile();
999 $service = new ActivityObject();
1001 $service->type = ActivityObject::SERVICE;
1002 $service->title = common_config('site', 'name');
1003 $service->link = common_root_url();
1004 $service->id = $service->link;
1006 $act = new Activity();
1008 $act->actor = ActivityObject::fromProfile($profile);
1009 $act->verb = ActivityVerb::JOIN;
1011 $act->objects[] = $service;
1013 $act->id = TagURI::mint('user:register:%d',
1016 $act->time = strtotime($this->created);
1018 $act->title = _("Register");
1020 $act->content = sprintf(_('%1$s joined %2$s.'),
1021 $profile->getBestName(),