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 $inboxed; // tinyint(1)
59 public $private_stream; // tinyint(1) default_0
60 public $created; // datetime() not_null
61 public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
63 /* the code above is auto generated do not remove the tag below */
66 public static function schemaDef()
69 'description' => 'local users',
71 'id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to profile table'),
72 'nickname' => array('type' => 'varchar', 'length' => 64, 'description' => 'nickname or username, duped in profile'),
73 'password' => array('type' => 'varchar', 'length' => 255, 'description' => 'salted password, can be null for OpenID users'),
74 'email' => array('type' => 'varchar', 'length' => 255, 'description' => 'email address for password recovery etc.'),
75 'incomingemail' => array('type' => 'varchar', 'length' => 255, 'description' => 'email address for post-by-email'),
76 'emailnotifysub' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Notify by email of subscriptions'),
77 'emailnotifyfav' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Notify by email of favorites'),
78 'emailnotifynudge' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Notify by email of nudges'),
79 'emailnotifymsg' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Notify by email of direct messages'),
80 'emailnotifyattn' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Notify by email of @-replies'),
81 'emailmicroid' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'whether to publish email microid'),
82 'language' => array('type' => 'varchar', 'length' => 50, 'description' => 'preferred language'),
83 'timezone' => array('type' => 'varchar', 'length' => 50, 'description' => 'timezone'),
84 'emailpost' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Post by email'),
85 'sms' => array('type' => 'varchar', 'length' => 64, 'description' => 'sms phone number'),
86 'carrier' => array('type' => 'int', 'description' => 'foreign key to sms_carrier'),
87 'smsnotify' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'whether to send notices to SMS'),
88 'smsreplies' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'whether to send notices to SMS on replies'),
89 'smsemail' => array('type' => 'varchar', 'length' => 255, 'description' => 'built from sms and carrier'),
90 'uri' => array('type' => 'varchar', 'length' => 255, 'description' => 'universally unique identifier, usually a tag URI'),
91 'autosubscribe' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'automatically subscribe to users who subscribe to us'),
92 'subscribe_policy' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => '0 = anybody can subscribe; 1 = require approval'),
93 'urlshorteningservice' => array('type' => 'varchar', 'length' => 50, 'default' => 'internal', 'description' => 'service to use for auto-shortening URLs'),
94 'inboxed' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'has an inbox been created for this user?'),
95 'private_stream' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'whether to limit all notices to followers only'),
97 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
98 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
100 'primary key' => array('id'),
101 'unique keys' => array(
102 'user_nickname_key' => array('nickname'),
103 'user_email_key' => array('email'),
104 'user_incomingemail_key' => array('incomingemail'),
105 'user_sms_key' => array('sms'),
106 'user_uri_key' => array('uri'),
108 'foreign keys' => array(
109 'user_id_fkey' => array('profile', array('id' => 'id')),
110 'user_carrier_fkey' => array('sms_carrier', array('carrier' => 'id')),
113 'user_smsemail_idx' => array('smsemail'),
118 protected $_profile = null;
123 * @throws UserNoProfileException if user has no profile
125 public function getProfile()
127 if (!($this->_profile instanceof Profile)) {
128 $this->_profile = Profile::getKV('id', $this->id);
129 if (!($this->_profile instanceof Profile)) {
130 throw new UserNoProfileException($this);
134 return $this->_profile;
137 function isSubscribed(Profile $other)
139 return $this->getProfile()->isSubscribed($other);
142 function hasPendingSubscription($other)
144 return $this->getProfile()->hasPendingSubscription($other);
147 // 'update' won't write key columns, so we have to do it ourselves.
149 function updateKeys(&$orig)
153 foreach (array('nickname', 'email', 'incomingemail', 'sms', 'carrier', 'smsemail') as $k) {
154 if (strcmp($this->$k, $orig->$k) != 0) {
155 $parts[] = $k . ' = ' . $this->_quote($this->$k);
158 if (count($parts) == 0) {
162 $toupdate = implode(', ', $parts);
164 $table = common_database_tablename($this->tableName());
165 $qry = 'UPDATE ' . $table . ' SET ' . $toupdate .
166 ' WHERE id = ' . $this->id;
168 $result = $this->query($qry);
176 * Get the most recent notice posted by this user, if any.
178 * @return mixed Notice or null
180 function getCurrentNotice()
182 return $this->getProfile()->getCurrentNotice();
185 function getCarrier()
187 return Sms_carrier::getKV('id', $this->carrier);
190 function hasBlocked($other)
192 return $this->getProfile()->hasBlocked($other);
196 * Register a new user account and profile and set up default subscriptions.
197 * If a new-user welcome message is configured, this will be sent.
199 * @param array $fields associative array of optional properties
202 * bool 'email_confirmed' pass true to mark email as pre-confirmed
205 * string 'location' informal string description of geolocation
206 * float 'lat' decimal latitude for geolocation
207 * float 'lon' decimal longitude for geolocation
208 * int 'location_id' geoname identifier
209 * int 'location_ns' geoname namespace to interpret location_id
210 * string 'nickname' REQUIRED
211 * string 'password' (may be missing for eg OpenID registrations)
212 * string 'code' invite code
213 * ?string 'uri' permalink to notice; defaults to local notice URL
214 * @return mixed User object or false on failure
216 static function register(array $fields) {
218 // MAGICALLY put fields into current scope
222 $profile = new Profile();
224 if (!empty($email)) {
225 $email = common_canonical_email($email);
229 $profile->nickname = Nickname::normalize($nickname, true);
230 } catch (NicknameException $e) {
231 common_log(LOG_WARNING, sprintf('Bad nickname during User registration for %s: %s', $nickname, $e->getMessage()), __FILE__);
235 $profile->profileurl = common_profile_url($profile->nickname);
237 if (!empty($fullname)) {
238 $profile->fullname = $fullname;
240 if (!empty($homepage)) {
241 $profile->homepage = $homepage;
244 $profile->bio = $bio;
246 if (!empty($location)) {
247 $profile->location = $location;
249 $loc = Location::fromName($location);
252 $profile->lat = $loc->lat;
253 $profile->lon = $loc->lon;
254 $profile->location_id = $loc->location_id;
255 $profile->location_ns = $loc->location_ns;
259 $profile->created = common_sql_now();
263 $user->nickname = $profile->nickname;
267 // Users who respond to invite email have proven their ownership of that address
270 $invite = Invitation::getKV($code);
271 if ($invite && $invite->address && $invite->address_type == 'email' && $invite->address == $email) {
272 $user->email = $invite->address;
276 if(isset($email_confirmed) && $email_confirmed) {
277 $user->email = $email;
280 // This flag is ignored but still set to 1
284 // Set default-on options here, otherwise they'll be disabled
285 // initially for sites using caching, since the initial encache
286 // doesn't know about the defaults in the database.
287 $user->emailnotifysub = 1;
288 $user->emailnotifyfav = 1;
289 $user->emailnotifynudge = 1;
290 $user->emailnotifymsg = 1;
291 $user->emailnotifyattn = 1;
292 $user->emailmicroid = 1;
293 $user->emailpost = 1;
294 $user->jabbermicroid = 1;
296 $user->created = common_sql_now();
298 if (Event::handle('StartUserRegister', array($profile))) {
300 $profile->query('BEGIN');
302 $id = $profile->insert();
304 common_log_db_error($profile, 'INSERT', __FILE__);
313 $user->uri = common_user_uri($user);
316 if (!empty($password)) { // may not have a password for OpenID users
317 $user->password = common_munge_password($password, $id);
320 $result = $user->insert();
322 if ($result === false) {
323 common_log_db_error($user, 'INSERT', __FILE__);
324 $profile->query('ROLLBACK');
328 // Everyone is subscribed to themself
330 $subscription = new Subscription();
331 $subscription->subscriber = $user->id;
332 $subscription->subscribed = $user->id;
333 $subscription->created = $user->created;
335 $result = $subscription->insert();
338 common_log_db_error($subscription, 'INSERT', __FILE__);
339 $profile->query('ROLLBACK');
343 // Mark that this invite was converted
345 if (!empty($invite)) {
346 $invite->convert($user);
349 if (!empty($email) && !$user->email) {
351 $confirm = new Confirm_address();
352 $confirm->code = common_confirmation_code(128);
353 $confirm->user_id = $user->id;
354 $confirm->address = $email;
355 $confirm->address_type = 'email';
357 $result = $confirm->insert();
360 common_log_db_error($confirm, 'INSERT', __FILE__);
361 $profile->query('ROLLBACK');
366 if (!empty($code) && $user->email) {
367 $user->emailChanged();
370 // Default system subscription
372 $defnick = common_config('newuser', 'default');
374 if (!empty($defnick)) {
375 $defuser = User::getKV('nickname', $defnick);
376 if (empty($defuser)) {
377 common_log(LOG_WARNING, sprintf("Default user %s does not exist.", $defnick),
380 Subscription::start($profile, $defuser->getProfile());
384 $profile->query('COMMIT');
386 if (!empty($email) && !$user->email) {
387 mail_confirm_address($user, $confirm->code, $profile->nickname, $email);
392 $welcome = common_config('newuser', 'welcome');
394 if (!empty($welcome)) {
395 $welcomeuser = User::getKV('nickname', $welcome);
396 if (empty($welcomeuser)) {
397 common_log(LOG_WARNING, sprintf("Welcome user %s does not exist.", $defnick),
400 $notice = Notice::saveNew($welcomeuser->id,
401 // TRANS: Notice given on user registration.
402 // TRANS: %1$s is the sitename, $2$s is the registering user's nickname.
403 sprintf(_('Welcome to %1$s, @%2$s!'),
404 common_config('site', 'name'),
410 Event::handle('EndUserRegister', array($profile));
416 // Things we do when the email changes
417 function emailChanged()
420 $invites = new Invitation();
421 $invites->address = $this->email;
422 $invites->address_type = 'email';
424 if ($invites->find()) {
425 while ($invites->fetch()) {
427 $other = Profile::getKV('id', $invites->user_id);
428 if (!($other instanceof Profile)) { // remove when getKV throws exceptions
431 Subscription::start($other, $this->getProfile());
432 } catch (Exception $e) {
439 function hasFave($notice)
441 return $this->getProfile()->hasFave($notice);
444 function mutuallySubscribed($other)
446 return $this->getProfile()->mutuallySubscribed($other);
449 function mutuallySubscribedUsers()
451 // 3-way join; probably should get cached
452 $UT = common_config('db','type')=='pgsql'?'"user"':'user';
453 $qry = "SELECT $UT.* " .
454 "FROM subscription sub1 JOIN $UT ON sub1.subscribed = $UT.id " .
455 "JOIN subscription sub2 ON $UT.id = sub2.subscriber " .
456 'WHERE sub1.subscriber = %d and sub2.subscribed = %d ' .
457 "ORDER BY $UT.nickname";
459 $user->query(sprintf($qry, $this->id, $this->id));
464 function getReplies($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
466 return Reply::stream($this->id, $offset, $limit, $since_id, $before_id);
469 function getTaggedNotices($tag, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0) {
470 return $this->getProfile()->getTaggedNotices($tag, $offset, $limit, $since_id, $before_id);
473 function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
475 return $this->getProfile()->getNotices($offset, $limit, $since_id, $before_id);
478 function favoriteNotices($own=false, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
480 return $this->getProfile()->favoriteNotices($own, $offset, $limit, $since_id, $max_id);
483 function blowFavesCache()
485 $this->getProfile()->blowFavesCache();
488 function getSelfTags()
490 return Profile_tag::getTagsArray($this->id, $this->id, $this->id);
493 function setSelfTags($newtags, $privacy)
495 return Profile_tag::setTags($this->id, $this->id, $newtags, $privacy);
498 function block(Profile $other)
500 // Add a new block record
502 // no blocking (and thus unsubbing from) yourself
504 if ($this->id == $other->id) {
505 common_log(LOG_WARNING,
507 "Profile ID %d (%s) tried to block themself.",
515 $block = new Profile_block();
517 // Begin a transaction
519 $block->query('BEGIN');
521 $block->blocker = $this->id;
522 $block->blocked = $other->id;
524 $result = $block->insert();
527 common_log_db_error($block, 'INSERT', __FILE__);
531 $self = $this->getProfile();
532 if (Subscription::exists($other, $self)) {
533 Subscription::cancel($other, $self);
535 if (Subscription::exists($self, $other)) {
536 Subscription::cancel($self, $other);
539 $block->query('COMMIT');
544 function unblock(Profile $other)
546 // Get the block record
548 $block = Profile_block::exists($this->getProfile(), $other);
554 $result = $block->delete();
557 common_log_db_error($block, 'DELETE', __FILE__);
564 function isMember(User_group $group)
566 return $this->getProfile()->isMember($group);
569 function isAdmin(User_group $group)
571 return $this->getProfile()->isAdmin($group);
574 function getGroups($offset=0, $limit=null)
576 return $this->getProfile()->getGroups($offset, $limit);
580 * Request to join the given group.
581 * May throw exceptions on failure.
583 * @param User_group $group
584 * @return Group_member
586 function joinGroup(User_group $group)
588 return $this->getProfile()->joinGroup($group);
592 * Leave a group that this user is a member of.
594 * @param User_group $group
596 function leaveGroup(User_group $group)
598 return $this->getProfile()->leaveGroup($group);
601 function getSubscribed($offset=0, $limit=null)
603 return $this->getProfile()->getSubscribed($offset, $limit);
606 function getSubscribers($offset=0, $limit=null)
608 return $this->getProfile()->getSubscribers($offset, $limit);
611 function getTaggedSubscribers($tag, $offset=0, $limit=null)
613 return $this->getProfile()->getTaggedSubscribers($tag, $offset, $limit);
616 function getTaggedSubscriptions($tag, $offset=0, $limit=null)
618 return $this->getProfile()->getTaggedSubscriptions($tag, $offset, $limit);
621 function hasRight($right)
623 return $this->getProfile()->hasRight($right);
626 function delete($useWhere=false)
628 if (empty($this->id)) {
629 common_log(LOG_WARNING, "Ambiguous User->delete(); skipping related tables.");
630 return parent::delete($useWhere);
634 $profile = $this->getProfile();
636 } catch (UserNoProfileException $unp) {
637 common_log(LOG_INFO, "User {$this->nickname} has no profile; continuing deletion.");
640 $related = array('Fave',
647 Event::handle('UserDeleteRelated', array($this, &$related));
649 foreach ($related as $cls) {
651 $inst->user_id = $this->id;
655 $this->_deleteTags();
656 $this->_deleteBlocks();
658 return parent::delete($useWhere);
661 function _deleteTags()
663 $tag = new Profile_tag();
664 $tag->tagger = $this->id;
668 function _deleteBlocks()
670 $block = new Profile_block();
671 $block->blocker = $this->id;
673 // XXX delete group block? Reset blocker?
676 function hasRole($name)
678 return $this->getProfile()->hasRole($name);
681 function grantRole($name)
683 return $this->getProfile()->grantRole($name);
686 function revokeRole($name)
688 return $this->getProfile()->revokeRole($name);
691 function isSandboxed()
693 return $this->getProfile()->isSandboxed();
696 function isSilenced()
698 return $this->getProfile()->isSilenced();
701 function repeatedByMe($offset=0, $limit=20, $since_id=null, $max_id=null)
703 $stream = new RepeatedByMeNoticeStream($this);
704 return $stream->getNotices($offset, $limit, $since_id, $max_id);
708 function repeatsOfMe($offset=0, $limit=20, $since_id=null, $max_id=null)
710 $stream = new RepeatsOfMeNoticeStream($this);
712 return $stream->getNotices($offset, $limit, $since_id, $max_id);
716 function repeatedToMe($offset=0, $limit=20, $since_id=null, $max_id=null)
718 // TRANS: Exception thrown when trying view "repeated to me".
719 throw new Exception(_('Not implemented since inbox change.'));
722 public static function siteOwner()
724 $owner = self::cacheGet('user:site_owner');
726 if ($owner === false) { // cache miss
728 $pr = new Profile_role();
729 $pr->role = Profile_role::OWNER;
730 $pr->orderBy('created');
733 if (!$pr->find(true)) {
734 throw new NoResultException($pr);
737 $owner = User::getKV('id', $pr->profile_id);
739 self::cacheSet('user:site_owner', $owner);
742 if ($owner instanceof User) {
746 throw new ServerException(_('No site owner configured.'));
750 * Pull the primary site account to use in single-user mode.
751 * If a valid user nickname is listed in 'singleuser':'nickname'
752 * in the config, this will be used; otherwise the site owner
753 * account is taken by default.
756 * @throws ServerException if no valid single user account is present
757 * @throws ServerException if called when not in single-user mode
759 public static function singleUser()
761 if (!common_config('singleuser', 'enabled')) {
762 // TRANS: Server exception.
763 throw new ServerException(_('Single-user mode code called when not enabled.'));
766 if ($nickname = common_config('singleuser', 'nickname')) {
767 $user = User::getKV('nickname', $nickname);
768 if ($user instanceof User) {
773 // If there was no nickname or no user by that nickname,
774 // try the site owner. Throws exception if not configured.
775 return User::siteOwner();
779 * This is kind of a hack for using external setup code that's trying to
780 * build single-user sites.
782 * Will still return a username if the config singleuser/nickname is set
783 * even if the account doesn't exist, which normally indicates that the
784 * site is horribly misconfigured.
786 * At the moment, we need to let it through so that router setup can
787 * complete, otherwise we won't be able to create the account.
789 * This will be easier when we can more easily create the account and
790 * *then* switch the site to 1user mode without jumping through hoops.
793 * @throws ServerException if no valid single user account is present
794 * @throws ServerException if called when not in single-user mode
796 static function singleUserNickname()
799 $user = User::singleUser();
800 return $user->nickname;
801 } catch (Exception $e) {
802 if (common_config('singleuser', 'enabled') && common_config('singleuser', 'nickname')) {
803 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.");
804 return common_config('singleuser', 'nickname');
811 * Find and shorten links in the given text using this user's URL shortening
814 * By default, links will be left untouched if the text is shorter than the
815 * configured maximum notice length. Pass true for the $always parameter
816 * to force all links to be shortened regardless.
818 * Side effects: may save file and file_redirection records for referenced URLs.
820 * @param string $text
821 * @param boolean $always
824 public function shortenLinks($text, $always=false)
826 return common_shorten_links($text, $always, $this);
830 * Get a list of OAuth client applications that have access to this
833 function getConnectedApps($offset = 0, $limit = null)
837 'FROM oauth_application_user u, oauth_application a ' .
838 'WHERE u.profile_id = %d ' .
839 'AND a.id = u.application_id ' .
840 'AND u.access_type > 0 ' .
841 'ORDER BY u.created DESC ';
844 if (common_config('db','type') == 'pgsql') {
845 $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
847 $qry .= ' LIMIT ' . $offset . ', ' . $limit;
851 $apps = new Oauth_application_user();
853 $cnt = $apps->query(sprintf($qry, $this->id));
859 * Magic function called at serialize() time.
861 * We use this to drop a couple process-specific references
862 * from DB_DataObject which can cause trouble in future
865 * @return array of variable names to include in serialization.
870 $vars = parent::__sleep();
871 $skip = array('_profile');
872 return array_diff($vars, $skip);
875 static function recoverPassword($nore)
877 $user = User::getKV('email', common_canonical_email($nore));
881 $user = User::getKV('nickname', common_canonical_nickname($nore));
882 } catch (NicknameException $e) {
887 // See if it's an unconfirmed email address
890 // Warning: it may actually be legit to have multiple folks
891 // who have claimed, but not yet confirmed, the same address.
892 // We'll only send to the first one that comes up.
893 $confirm_email = new Confirm_address();
894 $confirm_email->address = common_canonical_email($nore);
895 $confirm_email->address_type = 'email';
896 $confirm_email->find();
897 if ($confirm_email->fetch()) {
898 $user = User::getKV($confirm_email->user_id);
900 $confirm_email = null;
903 $confirm_email = null;
907 // TRANS: Information on password recovery form if no known username or e-mail address was specified.
908 throw new ClientException(_('No user with that email address or username.'));
912 // Try to get an unconfirmed email address if they used a user name
914 if (!$user->email && !$confirm_email) {
915 $confirm_email = new Confirm_address();
916 $confirm_email->user_id = $user->id;
917 $confirm_email->address_type = 'email';
918 $confirm_email->find();
919 if (!$confirm_email->fetch()) {
920 $confirm_email = null;
924 if (!$user->email && !$confirm_email) {
925 // TRANS: Client error displayed on password recovery form if a user does not have a registered e-mail address.
926 throw new ClientException(_('No registered email address for that user.'));
930 // Success! We have a valid user and a confirmed or unconfirmed email address
932 $confirm = new Confirm_address();
933 $confirm->code = common_confirmation_code(128);
934 $confirm->address_type = 'recover';
935 $confirm->user_id = $user->id;
936 $confirm->address = (!empty($user->email)) ? $user->email : $confirm_email->address;
938 if (!$confirm->insert()) {
939 common_log_db_error($confirm, 'INSERT', __FILE__);
940 // TRANS: Server error displayed if e-mail address confirmation fails in the database on the password recovery form.
941 throw new ServerException(_('Error saving address confirmation.'));
945 // @todo FIXME: needs i18n.
946 $body = "Hey, $user->nickname.";
948 $body .= 'Someone just asked for a new password ' .
949 'for this account on ' . common_config('site', 'name') . '.';
951 $body .= 'If it was you, and you want to confirm, use the URL below:';
953 $body .= "\t".common_local_url('recoverpassword',
954 array('code' => $confirm->code));
956 $body .= 'If not, just ignore this message.';
958 $body .= 'Thanks for your time, ';
960 $body .= common_config('site', 'name');
963 $headers = _mail_prepare_headers('recoverpassword', $user->nickname, $user->nickname);
964 // TRANS: Subject for password recovery e-mail.
965 mail_to_user($user, _('Password recovery requested'), $body, $headers, $confirm->address);
968 function streamModeOnly()
970 if (common_config('oldschool', 'enabled')) {
971 $osp = Old_school_prefs::getKV('user_id', $this->id);
973 return $osp->stream_mode_only;
980 function conversationTree()
982 if (common_config('oldschool', 'enabled')) {
983 $osp = Old_school_prefs::getKV('user_id', $this->id);
985 return $osp->conversation_tree;
992 function streamNicknames()
994 if (common_config('oldschool', 'enabled')) {
995 $osp = Old_school_prefs::getKV('user_id', $this->id);
997 return $osp->stream_nicknames;
1003 function registrationActivity()
1005 $profile = $this->getProfile();
1007 $service = new ActivityObject();
1009 $service->type = ActivityObject::SERVICE;
1010 $service->title = common_config('site', 'name');
1011 $service->link = common_root_url();
1012 $service->id = $service->link;
1014 $act = new Activity();
1016 $act->actor = ActivityObject::fromProfile($profile);
1017 $act->verb = ActivityVerb::JOIN;
1019 $act->objects[] = $service;
1021 $act->id = TagURI::mint('user:register:%d',
1024 $act->time = strtotime($this->created);
1026 $act->title = _("Register");
1028 $act->content = sprintf(_('%1$s joined %2$s.'),
1029 $profile->getBestName(),