* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-if (!defined('STATUSNET') && !defined('LACONICA')) {
- exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Table Definition for user
*/
-require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
-require_once 'Validate.php';
-
class User extends Managed_DataObject
{
const SUBSCRIBE_POLICY_OPEN = 0;
function isSubscribed($other)
{
- $profile = $this->getProfile();
- return $profile->isSubscribed($other);
+ return $this->getProfile()->isSubscribed($other);
}
function hasPendingSubscription($other)
{
- $profile = $this->getProfile();
- return $profile->hasPendingSubscription($other);
+ return $this->getProfile()->hasPendingSubscription($other);
}
// 'update' won't write key columns, so we have to do it ourselves.
{
$this->_connect();
$parts = array();
- foreach (array('nickname', 'email', 'incomingemail', 'sms', 'carrier', 'smsemail', 'language', 'timezone') as $k) {
+ foreach (array('nickname', 'email', 'incomingemail', 'sms', 'carrier', 'smsemail') as $k) {
if (strcmp($this->$k, $orig->$k) != 0) {
$parts[] = $k . ' = ' . $this->_quote($this->$k);
}
return $result;
}
- /**
- * Check whether the given nickname is potentially usable, or if it's
- * excluded by any blacklists on this system.
- *
- * WARNING: INPUT IS NOT VALIDATED OR NORMALIZED. NON-NORMALIZED INPUT
- * OR INVALID INPUT MAY LEAD TO FALSE RESULTS.
- *
- * @param string $nickname
- * @return boolean true if clear, false if blacklisted
- */
- static function allowed_nickname($nickname)
- {
- // XXX: should already be validated for size, content, etc.
- $blacklist = common_config('nickname', 'blacklist');
-
- //all directory and file names should be blacklisted
- $d = dir(INSTALLDIR);
- while (false !== ($entry = $d->read())) {
- $blacklist[]=$entry;
- }
- $d->close();
-
- //all top level names in the router should be blacklisted
- $router = Router::get();
- foreach(array_keys($router->m->getPaths()) as $path){
- if(preg_match('/^\/(.*?)[\/\?]/',$path,$matches)){
- $blacklist[]=$matches[1];
- }
- }
- return !in_array($nickname, $blacklist);
- }
-
/**
* Get the most recent notice posted by this user, if any.
*
*/
function getCurrentNotice()
{
- $profile = $this->getProfile();
- return $profile->getCurrentNotice();
+ return $this->getProfile()->getCurrentNotice();
}
function getCarrier()
function hasBlocked($other)
{
- $profile = $this->getProfile();
- return $profile->hasBlocked($other);
+ return $this->getProfile()->hasBlocked($other);
}
/**
$profile = new Profile();
- if(!empty($email))
- {
+ if (!empty($email)) {
$email = common_canonical_email($email);
}
- $nickname = common_canonical_nickname($nickname);
- $profile->nickname = $nickname;
- if(! User::allowed_nickname($nickname)){
- common_log(LOG_WARNING, sprintf("Attempted to register a nickname that is not allowed: %s", $profile->nickname),
- __FILE__);
+ try {
+ $profile->nickname = Nickname::normalize($nickname, true);
+ } catch (NicknameException $e) {
+ common_log(LOG_WARNING, sprintf('Bad nickname during User registration for %s: %s', $nickname, $e->getMessage()), __FILE__);
return false;
}
- $profile->profileurl = common_profile_url($nickname);
+
+ $profile->profileurl = common_profile_url($profile->nickname);
if (!empty($fullname)) {
$profile->fullname = $fullname;
$user = new User();
- $user->nickname = $nickname;
+ $user->nickname = $profile->nickname;
$invite = null;
$profile->query('BEGIN');
$id = $profile->insert();
-
- if (empty($id)) {
+ if ($id === false) {
common_log_db_error($profile, 'INSERT', __FILE__);
return false;
}
$result = $user->insert();
- if (!$result) {
+ if ($result === false) {
common_log_db_error($user, 'INSERT', __FILE__);
+ $profile->query('ROLLBACK');
return false;
}
if (!$result) {
common_log_db_error($subscription, 'INSERT', __FILE__);
+ $profile->query('ROLLBACK');
return false;
}
if (!$result) {
common_log_db_error($confirm, 'INSERT', __FILE__);
+ $profile->query('ROLLBACK');
return false;
}
}
function hasFave($notice)
{
- $profile = $this->getProfile();
- return $profile->hasFave($notice);
+ return $this->getProfile()->hasFave($notice);
}
function mutuallySubscribed($other)
{
- $profile = $this->getProfile();
- return $profile->mutuallySubscribed($other);
+ return $this->getProfile()->mutuallySubscribed($other);
}
function mutuallySubscribedUsers()
}
function getTaggedNotices($tag, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0) {
- $profile = $this->getProfile();
- return $profile->getTaggedNotices($tag, $offset, $limit, $since_id, $before_id);
+ 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)
{
- $profile = $this->getProfile();
- return $profile->getNotices($offset, $limit, $since_id, $before_id);
+ return $this->getProfile()->getNotices($offset, $limit, $since_id, $before_id);
}
function favoriteNotices($own=false, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
function blowFavesCache()
{
- $profile = $this->getProfile();
- $profile->blowFavesCache();
+ $this->getProfile()->blowFavesCache();
}
function getSelfTags()
function isMember($group)
{
- $profile = $this->getProfile();
- return $profile->isMember($group);
+ return $this->getProfile()->isMember($group);
}
function isAdmin($group)
{
- $profile = $this->getProfile();
- return $profile->isAdmin($group);
+ return $this->getProfile()->isAdmin($group);
}
function getGroups($offset=0, $limit=null)
{
- $profile = $this->getProfile();
- return $profile->getGroups($offset, $limit);
+ return $this->getProfile()->getGroups($offset, $limit);
}
/**
*/
function joinGroup(User_group $group)
{
- $profile = $this->getProfile();
- return $profile->joinGroup($group);
+ return $this->getProfile()->joinGroup($group);
}
/**
*/
function leaveGroup(User_group $group)
{
- $profile = $this->getProfile();
- return $profile->leaveGroup($group);
+ return $this->getProfile()->leaveGroup($group);
}
function getSubscribed($offset=0, $limit=null)
{
- $profile = $this->getProfile();
- return $profile->getSubscribed($offset, $limit);
+ return $this->getProfile()->getSubscribed($offset, $limit);
}
function getSubscribers($offset=0, $limit=null)
{
- $profile = $this->getProfile();
- return $profile->getSubscribers($offset, $limit);
+ return $this->getProfile()->getSubscribers($offset, $limit);
}
function getTaggedSubscribers($tag, $offset=0, $limit=null)
function hasRight($right)
{
- $profile = $this->getProfile();
- return $profile->hasRight($right);
+ return $this->getProfile()->hasRight($right);
}
function delete()
{
+ if (empty($this->id)) {
+ common_log(LOG_WARNING, "Ambiguous User->delete(); skipping related tables.");
+ return parent::delete();
+ }
+
try {
$profile = $this->getProfile();
$profile->delete();
function hasRole($name)
{
- $profile = $this->getProfile();
- return $profile->hasRole($name);
+ return $this->getProfile()->hasRole($name);
}
function grantRole($name)
{
- $profile = $this->getProfile();
- return $profile->grantRole($name);
+ return $this->getProfile()->grantRole($name);
}
function revokeRole($name)
{
- $profile = $this->getProfile();
- return $profile->revokeRole($name);
+ return $this->getProfile()->revokeRole($name);
}
function isSandboxed()
{
- $profile = $this->getProfile();
- return $profile->isSandboxed();
+ return $this->getProfile()->isSandboxed();
}
function isSilenced()
{
- $profile = $this->getProfile();
- return $profile->isSilenced();
+ return $this->getProfile()->isSilenced();
}
function repeatedByMe($offset=0, $limit=20, $since_id=null, $max_id=null)