12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082 |
- <?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_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);
- }
- }
|