1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072 |
- <?php
- if (!defined('GNUSOCIAL')) { exit(1); }
- 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' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Notify by email of subscriptions'),
- 'emailnotifyfav' => array('type' => 'int', 'size' => 'tiny', 'default' => null, 'description' => 'Notify by email of favorites'),
- 'emailnotifynudge' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Notify by email of nudges'),
- 'emailnotifymsg' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Notify by email of direct messages'),
- 'emailnotifyattn' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, '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' => 'int', 'size' => 'tiny', 'default' => 1, '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' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'whether to send notices to SMS'),
- 'smsreplies' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, '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' => 'int', 'size' => 'tiny', 'default' => 0, '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' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'whether to limit all notices to followers only'),
- 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
- 'modified' => array('type' => 'timestamp', 'not null' => true, '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();
- }
- static function getByNickname($nickname)
- {
- $user = User::getKV('nickname', $nickname);
- if (!$user instanceof User) {
- throw new NoSuchUserException(array('nickname' => $nickname));
- }
- return $user;
- }
- function isSubscribed(Profile $other)
- {
- return $this->getProfile()->isSubscribed($other);
- }
- function hasPendingSubscription(Profile $other)
- {
- return $this->getProfile()->hasPendingSubscription($other);
- }
-
- function getCurrentNotice()
- {
- return $this->getProfile()->getCurrentNotice();
- }
- function getCarrier()
- {
- return Sms_carrier::getKV('id', $this->carrier);
- }
- function hasBlocked(Profile $other)
- {
- return $this->getProfile()->hasBlocked($other);
- }
-
- 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 = 1;
- $user->emailnotifynudge = 1;
- $user->emailnotifymsg = 1;
- $user->emailnotifyattn = 1;
- $user->emailpost = 1;
- $user->created = common_sql_now();
- if (Event::handle('StartUserRegister', array($profile))) {
- $profile->query('BEGIN');
- $id = $profile->insert();
- if ($id === false) {
- common_log_db_error($profile, 'INSERT', __FILE__);
- $profile->query('ROLLBACK');
-
- 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;
- }
-
- 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()));
- }
- }
- }
- }
- function mutuallySubscribed(Profile $other)
- {
- return $this->getProfile()->mutuallySubscribed($other);
- }
- function mutuallySubscribedUsers()
- {
-
- $UT = common_config('db','type')=='pgsql'?'"user"':'user';
- $qry = "SELECT $UT.* " .
- "FROM subscription sub1 JOIN $UT ON sub1.subscribed = $UT.id " .
- "JOIN subscription sub2 ON $UT.id = sub2.subscriber " .
- 'WHERE sub1.subscriber = %d and sub2.subscribed = %d ' .
- "ORDER BY $UT.nickname";
- $user = new User();
- $user->query(sprintf($qry, $this->id, $this->id));
- return $user;
- }
- function getReplies($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
- {
- return $this->getProfile()->getReplies($offset, $limit, $since_id, $before_id);
- }
- 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);
- }
- function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
- {
- return $this->getProfile()->getNotices($offset, $limit, $since_id, $before_id);
- }
- 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;
- }
- 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;
- }
- function isMember(User_group $group)
- {
- return $this->getProfile()->isMember($group);
- }
- function isAdmin(User_group $group)
- {
- return $this->getProfile()->isAdmin($group);
- }
- function getGroups($offset=0, $limit=null)
- {
- return $this->getProfile()->getGroups($offset, $limit);
- }
-
- function joinGroup(User_group $group)
- {
- return $this->getProfile()->joinGroup($group);
- }
-
- function leaveGroup(User_group $group)
- {
- return $this->getProfile()->leaveGroup($group);
- }
- function getSubscribed($offset=0, $limit=null)
- {
- return $this->getProfile()->getSubscribed($offset, $limit);
- }
- function getSubscribers($offset=0, $limit=null)
- {
- return $this->getProfile()->getSubscribers($offset, $limit);
- }
- function getTaggedSubscribers($tag, $offset=0, $limit=null)
- {
- return $this->getProfile()->getTaggedSubscribers($tag, $offset, $limit);
- }
- function getTaggedSubscriptions($tag, $offset=0, $limit=null)
- {
- return $this->getProfile()->getTaggedSubscriptions($tag, $offset, $limit);
- }
- function hasRight($right)
- {
- return $this->getProfile()->hasRight($right);
- }
- 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);
- }
- function _deleteTags()
- {
- $tag = new Profile_tag();
- $tag->tagger = $this->id;
- $tag->delete();
- }
- function _deleteBlocks()
- {
- $block = new Profile_block();
- $block->blocker = $this->id;
- $block->delete();
-
- }
- function hasRole($name)
- {
- return $this->getProfile()->hasRole($name);
- }
- function grantRole($name)
- {
- return $this->getProfile()->grantRole($name);
- }
- function revokeRole($name)
- {
- return $this->getProfile()->revokeRole($name);
- }
- function isSandboxed()
- {
- return $this->getProfile()->isSandboxed();
- }
- function isSilenced()
- {
- return $this->getProfile()->isSilenced();
- }
- function receivesEmailNotifications()
- {
-
-
-
- if (empty($this->email) || !$this->emailnotifyattn) {
- return false;
- }
-
- if ($this->isSandboxed() || $this->isSilenced()) {
- return false;
- }
- return true;
- }
- 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);
- }
- 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();
- }
-
- 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);
- }
-
- 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) {
- if (common_config('db','type') == 'pgsql') {
- $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
- } else {
- $qry .= ' LIMIT ' . $offset . ', ' . $limit;
- }
- }
- $apps = new Oauth_application_user();
- $cnt = $apps->query(sprintf($qry, $this->id));
- return $apps;
- }
-
- function __sleep()
- {
- $vars = parent::__sleep();
- $skip = array('_profile');
- return array_diff($vars, $skip);
- }
- static function recoverPassword($nore)
- {
- require_once(INSTALLDIR . '/lib/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',
- array('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);
- }
- 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;
- }
- 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;
- }
- 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);
- }
- }
|