123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083 |
- <?php
- defined('GNUSOCIAL') || die();
- class User extends Managed_DataObject
- {
- const SUBSCRIBE_POLICY_OPEN = 0;
- const SUBSCRIBE_POLICY_MODERATE = 1;
-
-
- public $__table = 'user';
- public $id;
- public $nickname;
- public $password;
- public $email;
- public $incomingemail;
- public $emailnotifysub;
- public $emailnotifyfav;
- public $emailnotifynudge;
- public $emailnotifymsg;
- public $emailnotifyattn;
- public $language;
- public $timezone;
- public $emailpost;
- public $sms;
- public $carrier;
- public $smsnotify;
- public $smsreplies;
- public $smsemail;
- public $uri;
- public $autosubscribe;
- public $subscribe_policy;
- public $urlshorteningservice;
- public $private_stream;
- public $created;
- public $modified;
-
-
- public static function schemaDef()
- {
- return array(
- 'description' => 'local users',
- 'fields' => array(
- 'id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to profile table'),
- 'nickname' => array('type' => 'varchar', 'length' => 64, 'description' => 'nickname or username, duped in profile'),
- 'password' => array('type' => 'varchar', 'length' => 191, 'description' => 'salted password, can be null for OpenID users'),
- 'email' => array('type' => 'varchar', 'length' => 191, 'description' => 'email address for password recovery etc.'),
- 'incomingemail' => array('type' => 'varchar', 'length' => 191, 'description' => 'email address for post-by-email'),
- 'emailnotifysub' => array('type' => 'bool', 'default' => true, 'description' => 'Notify by email of subscriptions'),
- 'emailnotifyfav' => array('type' => 'int', 'size' => 'tiny', 'default' => null, 'description' => 'Notify by email of favorites'),
- 'emailnotifynudge' => array('type' => 'bool', 'default' => true, 'description' => 'Notify by email of nudges'),
- 'emailnotifymsg' => array('type' => 'bool', 'default' => true, 'description' => 'Notify by email of direct messages'),
- 'emailnotifyattn' => array('type' => 'bool', 'default' => true, 'description' => 'Notify by email of @-replies'),
- 'language' => array('type' => 'varchar', 'length' => 50, 'description' => 'preferred language'),
- 'timezone' => array('type' => 'varchar', 'length' => 50, 'description' => 'timezone'),
- 'emailpost' => array('type' => 'bool', 'default' => true, 'description' => 'Post by email'),
- 'sms' => array('type' => 'varchar', 'length' => 64, 'description' => 'sms phone number'),
- 'carrier' => array('type' => 'int', 'description' => 'foreign key to sms_carrier'),
- 'smsnotify' => array('type' => 'bool', 'default' => false, 'description' => 'whether to send notices to SMS'),
- 'smsreplies' => array('type' => 'bool', 'default' => false, 'description' => 'whether to send notices to SMS on replies'),
- 'smsemail' => array('type' => 'varchar', 'length' => 191, 'description' => 'built from sms and carrier'),
- 'uri' => array('type' => 'varchar', 'length' => 191, 'description' => 'universally unique identifier, usually a tag URI'),
- 'autosubscribe' => array('type' => 'bool', 'default' => false, 'description' => 'automatically subscribe to users who subscribe to us'),
- 'subscribe_policy' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => '0 = anybody can subscribe; 1 = require approval'),
- 'urlshorteningservice' => array('type' => 'varchar', 'length' => 50, 'default' => 'internal', 'description' => 'service to use for auto-shortening URLs'),
- 'private_stream' => array('type' => 'bool', 'default' => false, 'description' => 'whether to limit all notices to followers only'),
- 'created' => array('type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'),
- 'modified' => array('type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'),
- ),
- 'primary key' => array('id'),
- 'unique keys' => array(
- 'user_nickname_key' => array('nickname'),
- 'user_email_key' => array('email'),
- 'user_incomingemail_key' => array('incomingemail'),
- 'user_sms_key' => array('sms'),
- 'user_uri_key' => array('uri'),
- ),
- 'foreign keys' => array(
- 'user_id_fkey' => array('profile', array('id' => 'id')),
- 'user_carrier_fkey' => array('sms_carrier', array('carrier' => 'id')),
- ),
- 'indexes' => array(
- 'user_created_idx' => array('created'),
- 'user_smsemail_idx' => array('smsemail'),
- ),
- );
- }
- protected $_profile = array();
-
- public function getProfile()
- {
- if (!isset($this->_profile[$this->id])) {
- $profile = Profile::getKV('id', $this->id);
- if (!$profile instanceof Profile) {
- throw new UserNoProfileException($this);
- }
- $this->_profile[$this->id] = $profile;
- }
- return $this->_profile[$this->id];
- }
- public function sameAs(Profile $other)
- {
- return $this->getProfile()->sameAs($other);
- }
- public function getUri()
- {
- return $this->uri;
- }
- public function getNickname()
- {
- return $this->getProfile()->getNickname();
- }
- public static function getByNickname($nickname)
- {
- $user = User::getKV('nickname', $nickname);
- if (!$user instanceof User) {
- throw new NoSuchUserException(array('nickname' => $nickname));
- }
- return $user;
- }
- public function isSubscribed(Profile $other)
- {
- return $this->getProfile()->isSubscribed($other);
- }
- public function hasPendingSubscription(Profile $other)
- {
- return $this->getProfile()->hasPendingSubscription($other);
- }
-
- public function getCurrentNotice()
- {
- return $this->getProfile()->getCurrentNotice();
- }
- public function getCarrier()
- {
- return Sms_carrier::getKV('id', $this->carrier);
- }
- public function hasBlocked(Profile $other)
- {
- return $this->getProfile()->hasBlocked($other);
- }
-
- public static function register(array $fields, $accept_email_fail = false)
- {
-
- extract($fields);
- $profile = new Profile();
- if (!empty($email)) {
- $email = common_canonical_email($email);
- }
-
- $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;
-
- 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;
- }
-
-
-
- $user->emailnotifysub = true;
- $user->emailnotifynudge = true;
- $user->emailnotifymsg = true;
- $user->emailnotifyattn = true;
- $user->emailpost = true;
- $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');
-
- throw new ServerException(_m('Could not insert profile data for new user.'));
- }
-
-
- if ($profile->hasRole(Profile_role::DELETED)) {
- $profile->revokeRole(Profile_role::DELETED);
- }
- $user->id = $id;
- if (!empty($uri)) {
- $user->uri = $uri;
- } else {
- $user->uri = common_user_uri($user);
- }
- if (!empty($password)) {
- $user->password = common_munge_password($password);
- }
- $result = $user->insert();
- if ($result === false) {
- common_log_db_error($user, 'INSERT', __FILE__);
- $profile->query('ROLLBACK');
-
- throw new ServerException(_m('Could not insert user data for new user.'));
- }
-
- $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');
-
- throw new ServerException(_m('Could not insert subscription data for new user.'));
- }
-
- if (!empty($invite)) {
- $invite->convert($user);
- }
- if (!empty($email) && empty($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===false) {
- common_log_db_error($confirm, 'INSERT', __FILE__);
- $profile->query('ROLLBACK');
-
- throw new ServerException(_m('Could not insert email confirmation data for new user.'));
- }
- }
- if (!empty($code) && $user->email) {
- $user->emailChanged();
- }
-
- $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) && empty($user->email)) {
- try {
- $confirm->sendConfirmation();
- } catch (EmailException $e) {
- common_log(LOG_ERR, "Could not send user registration email for user id=={$profile->getID()}: {$e->getMessage()}");
- if (!$accept_email_fail) {
- throw $e;
- }
- }
- }
-
- $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'),
- $profile->getNickname()
- ),
- 'system'
- );
- }
- }
- Event::handle('EndUserRegister', array($profile));
- }
- if (!$user instanceof User || empty($user->id)) {
- throw new ServerException('User could not be registered. Probably an event hook that failed.');
- }
- return $user;
- }
-
- public function emailChanged()
- {
- $invites = new Invitation();
- $invites->address = $this->email;
- $invites->address_type = 'email';
- if ($invites->find()) {
- while ($invites->fetch()) {
- try {
- $other = Profile::getByID($invites->user_id);
- Subscription::start($other, $this->getProfile());
- } catch (NoResultException $e) {
-
- } catch (AlreadyFulfilledException $e) {
-
- } catch (Exception $e) {
- common_log(LOG_ERR, 'On-invitation-completion subscription failed when subscribing '._ve($invites->user_id).' to '.$this->getProfile()->getID().': '._ve($e->getMessage()));
- }
- }
- }
- }
- public function mutuallySubscribed(Profile $other)
- {
- return $this->getProfile()->mutuallySubscribed($other);
- }
- public function mutuallySubscribedUsers()
- {
- $user = new User();
-
- $user->query(sprintf(
- 'SELECT %1$s.* ' .
- 'FROM subscription AS sub1 INNER JOIN %1$s ON sub1.subscribed = %1$s.id ' .
- 'INNER JOIN subscription AS sub2 ON %1$s.id = sub2.subscriber ' .
- 'WHERE sub1.subscriber = %2$d AND sub2.subscribed = %2$d ' .
- 'ORDER BY %1$s.nickname',
- $user->escapedTableName(),
- $this->id
- ));
- return $user;
- }
- public function getReplies($offset = 0, $limit = NOTICES_PER_PAGE, $since_id = 0, $before_id = 0)
- {
- return $this->getProfile()->getReplies($offset, $limit, $since_id, $before_id);
- }
- public function getTaggedNotices($tag, $offset = 0, $limit = NOTICES_PER_PAGE, $since_id = 0, $before_id = 0)
- {
- return $this->getProfile()->getTaggedNotices($tag, $offset, $limit, $since_id, $before_id);
- }
- public function getNotices($offset = 0, $limit = NOTICES_PER_PAGE, $since_id = 0, $before_id = 0)
- {
- return $this->getProfile()->getNotices($offset, $limit, $since_id, $before_id);
- }
- public function block(Profile $other)
- {
-
-
- if ($this->id == $other->id) {
- common_log(
- LOG_WARNING,
- sprintf(
- "Profile ID %d (%s) tried to block themself.",
- $this->id,
- $this->nickname
- )
- );
- return false;
- }
- $block = new Profile_block();
-
- $block->query('BEGIN');
- $block->blocker = $this->id;
- $block->blocked = $other->id;
- $result = $block->insert();
- if (!$result) {
- common_log_db_error($block, 'INSERT', __FILE__);
- return false;
- }
- $self = $this->getProfile();
- if (Subscription::exists($other, $self)) {
- Subscription::cancel($other, $self);
- }
- if (Subscription::exists($self, $other)) {
- Subscription::cancel($self, $other);
- }
- $block->query('COMMIT');
- return true;
- }
- public function unblock(Profile $other)
- {
-
- $block = Profile_block::exists($this->getProfile(), $other);
- if (!$block) {
- return false;
- }
- $result = $block->delete();
- if (!$result) {
- common_log_db_error($block, 'DELETE', __FILE__);
- return false;
- }
- return true;
- }
- public function isMember(User_group $group)
- {
- return $this->getProfile()->isMember($group);
- }
- public function isAdmin(User_group $group)
- {
- return $this->getProfile()->isAdmin($group);
- }
- public function getGroups($offset = 0, $limit = null)
- {
- return $this->getProfile()->getGroups($offset, $limit);
- }
-
- public function joinGroup(User_group $group)
- {
- return $this->getProfile()->joinGroup($group);
- }
-
- public function leaveGroup(User_group $group)
- {
- return $this->getProfile()->leaveGroup($group);
- }
- public function getSubscribed($offset = 0, $limit = null)
- {
- return $this->getProfile()->getSubscribed($offset, $limit);
- }
- public function getSubscribers($offset = 0, $limit = null)
- {
- return $this->getProfile()->getSubscribers($offset, $limit);
- }
- public function getTaggedSubscribers($tag, $offset = 0, $limit = null)
- {
- return $this->getProfile()->getTaggedSubscribers($tag, $offset, $limit);
- }
- public function getTaggedSubscriptions($tag, $offset = 0, $limit = null)
- {
- return $this->getProfile()->getTaggedSubscriptions($tag, $offset, $limit);
- }
- public function hasRight($right)
- {
- return $this->getProfile()->hasRight($right);
- }
- public function delete($useWhere = false)
- {
- if (empty($this->id)) {
- common_log(LOG_WARNING, "Ambiguous User->delete(); skipping related tables.");
- return parent::delete($useWhere);
- }
- try {
- if (!$this->hasRole(Profile_role::DELETED)) {
- $profile = $this->getProfile();
- $profile->delete();
- }
- } catch (UserNoProfileException $unp) {
- common_log(LOG_INFO, "User {$this->nickname} has no profile; continuing deletion.");
- }
- $related = array(
- 'Confirm_address',
- 'Remember_me',
- 'Foreign_link',
- 'Invitation',
- );
- Event::handle('UserDeleteRelated', array($this, &$related));
- foreach ($related as $cls) {
- $inst = new $cls();
- $inst->user_id = $this->id;
- $inst->delete();
- }
- $this->_deleteTags();
- $this->_deleteBlocks();
- return parent::delete($useWhere);
- }
- public function _deleteTags()
- {
- $tag = new Profile_tag();
- $tag->tagger = $this->id;
- $tag->delete();
- }
- public function _deleteBlocks()
- {
- $block = new Profile_block();
- $block->blocker = $this->id;
- $block->delete();
-
- }
- public function hasRole($name)
- {
- return $this->getProfile()->hasRole($name);
- }
- public function grantRole($name)
- {
- return $this->getProfile()->grantRole($name);
- }
- public function revokeRole($name)
- {
- return $this->getProfile()->revokeRole($name);
- }
- public function isSandboxed()
- {
- return $this->getProfile()->isSandboxed();
- }
- public function isSilenced()
- {
- return $this->getProfile()->isSilenced();
- }
- public function receivesEmailNotifications()
- {
-
-
-
- if (empty($this->email) || !$this->emailnotifyattn) {
- return false;
- }
-
- if ($this->isSandboxed() || $this->isSilenced()) {
- return false;
- }
- return true;
- }
- public function repeatedByMe($offset = 0, $limit = 20, $since_id = null, $max_id = null)
- {
-
-
- $stream = new RepeatedByMeNoticeStream($this->getProfile(), Profile::current());
- return $stream->getNotices($offset, $limit, $since_id, $max_id);
- }
- public function repeatsOfMe($offset = 0, $limit = 20, $since_id = null, $max_id = null)
- {
-
-
- $stream = new RepeatsOfMeNoticeStream($this->getProfile(), Profile::current());
- return $stream->getNotices($offset, $limit, $since_id, $max_id);
- }
- public function repeatedToMe($offset = 0, $limit = 20, $since_id = null, $max_id = null)
- {
- return $this->getProfile()->repeatedToMe($offset, $limit, $since_id, $max_id);
- }
- public static function siteOwner()
- {
- $owner = self::cacheGet('user:site_owner');
- if ($owner === false) {
- $pr = new Profile_role();
- $pr->role = Profile_role::OWNER;
- $pr->orderBy('created');
- $pr->limit(1);
- if (!$pr->find(true)) {
- throw new NoResultException($pr);
- }
- $owner = User::getKV('id', $pr->profile_id);
- self::cacheSet('user:site_owner', $owner);
- }
- if ($owner instanceof User) {
- return $owner;
- }
- throw new ServerException(_('No site owner configured.'));
- }
-
- public static function singleUser()
- {
- if (!common_config('singleuser', 'enabled')) {
-
- throw new ServerException(_('Single-user mode code called when not enabled.'));
- }
- if ($nickname = common_config('singleuser', 'nickname')) {
- $user = User::getKV('nickname', $nickname);
- if ($user instanceof User) {
- return $user;
- }
- }
-
-
- return User::siteOwner();
- }
-
- public static function singleUserNickname()
- {
- try {
- $user = User::singleUser();
- return $user->nickname;
- } catch (Exception $e) {
- if (common_config('singleuser', 'enabled') && common_config('singleuser', 'nickname')) {
- 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.");
- return common_config('singleuser', 'nickname');
- }
- throw $e;
- }
- }
-
- public function shortenLinks($text, $always=false)
- {
- return common_shorten_links($text, $always, $this);
- }
-
- public function getConnectedApps($offset = 0, $limit = null)
- {
- $qry =
- 'SELECT u.* ' .
- 'FROM oauth_application_user u, oauth_application a ' .
- 'WHERE u.profile_id = %d ' .
- 'AND a.id = u.application_id ' .
- 'AND u.access_type > 0 ' .
- 'ORDER BY u.created DESC ';
- if ($offset > 0) {
- $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
- }
- $apps = new Oauth_application_user();
- $cnt = $apps->query(sprintf($qry, $this->id));
- return $apps;
- }
-
- public function __sleep()
- {
- $vars = parent::__sleep();
- $skip = array('_profile');
- return array_diff($vars, $skip);
- }
- public static function recoverPassword($nore)
- {
- require_once INSTALLDIR . '/lib/util/mail.php';
-
- $confirm_email = null;
- if (common_is_email($nore)) {
- $user = User::getKV('email', common_canonical_email($nore));
-
- if (!$user instanceof User) {
-
-
-
- $confirm_email = new Confirm_address();
- $confirm_email->address = common_canonical_email($nore);
- $confirm_email->address_type = 'email';
- if ($confirm_email->find(true)) {
- $user = User::getKV('id', $confirm_email->user_id);
- }
- }
-
- if (!$user instanceof User) {
- if (common_config('site', 'fakeaddressrecovery')) {
-
-
- return;
- }
-
- throw new ClientException(_('No user with that email address exists here.'));
- }
- } else {
-
- $user = User::getKV('nickname', common_canonical_nickname($nore));
- if (!$user instanceof User) {
-
- throw new ClientException(_('No user with that nickname exists here.'));
- }
- }
-
- if (empty($user->email) && $confirm_email === null) {
- $confirm_email = new Confirm_address();
- $confirm_email->user_id = $user->id;
- $confirm_email->address_type = 'email';
- $confirm_email->find();
- if (!$confirm_email->fetch()) {
-
- $confirm_email = null;
- }
- }
- if (empty($user->email) && !$confirm_email instanceof Confirm_address) {
-
- throw new ClientException(_('No registered email address for that user.'));
- }
-
- $confirm = new Confirm_address();
- $confirm->code = common_confirmation_code(128);
- $confirm->address_type = 'recover';
- $confirm->user_id = $user->id;
- $confirm->address = $user->email ?: $confirm_email->address;
- if (!$confirm->insert()) {
- common_log_db_error($confirm, 'INSERT', __FILE__);
-
- throw new ServerException(_('Error saving address confirmation.'));
- }
-
- $body = "Hey, $user->nickname.";
- $body .= "\n\n";
- $body .= 'Someone just asked for a new password ' .
- 'for this account on ' . common_config('site', 'name') . '.';
- $body .= "\n\n";
- $body .= 'If it was you, and you want to confirm, use the URL below:';
- $body .= "\n\n";
- $body .= "\t" . common_local_url(
- 'recoverpassword',
- ['code' => $confirm->code]
- );
- $body .= "\n\n";
- $body .= 'If not, just ignore this message.';
- $body .= "\n\n";
- $body .= 'Thanks for your time, ';
- $body .= "\n";
- $body .= common_config('site', 'name');
- $body .= "\n";
- $headers = _mail_prepare_headers('recoverpassword', $user->nickname, $user->nickname);
-
- mail_to_user($user, _('Password recovery requested'), $body, $headers, $confirm->address);
- }
- public function streamModeOnly()
- {
- if (common_config('oldschool', 'enabled')) {
- $osp = Old_school_prefs::getKV('user_id', $this->id);
- if (!empty($osp)) {
- return $osp->stream_mode_only;
- }
- }
- return false;
- }
- public function streamNicknames()
- {
- if (common_config('oldschool', 'enabled')) {
- $osp = Old_school_prefs::getKV('user_id', $this->id);
- if (!empty($osp)) {
- return $osp->stream_nicknames;
- }
- }
- return false;
- }
- public function registrationActivity()
- {
- $profile = $this->getProfile();
- $service = new ActivityObject();
- $service->type = ActivityObject::SERVICE;
- $service->title = common_config('site', 'name');
- $service->link = common_root_url();
- $service->id = $service->link;
- $act = new Activity();
- $act->actor = $profile->asActivityObject();
- $act->verb = ActivityVerb::JOIN;
- $act->objects[] = $service;
- $act->id = TagURI::mint(
- 'user:register:%d',
- $this->id
- );
- $act->time = strtotime($this->created);
- $act->title = _("Register");
- $act->content = sprintf(
- _('%1$s joined %2$s.'),
- $profile->getBestName(),
- $service->title
- );
- return $act;
- }
- public function isPrivateStream()
- {
- return $this->getProfile()->isPrivateStream();
- }
- public function hasPassword()
- {
- return !empty($this->password);
- }
- public function setPassword($password)
- {
- $orig = clone($this);
- $this->password = common_munge_password($password, $this->getProfile());
- if ($this->validate() !== true) {
-
- throw new ServerException(_('Error saving user; invalid.'));
- }
- if (!$this->update($orig)) {
- common_log_db_error($this, 'UPDATE', __FILE__);
-
-
- throw new ServerException(_('Cannot save new password.'));
- }
- }
- public function delPref($namespace, $topic)
- {
- return $this->getProfile()->delPref($namespace, $topic);
- }
- public function getPref($namespace, $topic, $default=null)
- {
- return $this->getProfile()->getPref($namespace, $topic, $default);
- }
- public function getConfigPref($namespace, $topic)
- {
- return $this->getProfile()->getConfigPref($namespace, $topic);
- }
- public function setPref($namespace, $topic, $data)
- {
- return $this->getProfile()->setPref($namespace, $topic, $data);
- }
- }
|