function isNewNickname($str) { if (!Nickname::isValid($str)) { return false; } if (!User::allowed_nickname($str)) { return false; } if (User::staticGet('nickname', $str)) { return false; } return true; }
function trySave() { $cur = common_current_user(); if (!$cur->isAdmin($this->group)) { // TRANS: Client error displayed trying to edit a group while not being a group admin. $this->clientError(_('You must be an admin to edit the group.'), 403); return; } if (Event::handle('StartGroupSaveForm', array($this))) { $nickname = Nickname::normalize($this->trimmed('newnickname')); $fullname = $this->trimmed('fullname'); $homepage = $this->trimmed('homepage'); $description = $this->trimmed('description'); $location = $this->trimmed('location'); $aliasstring = $this->trimmed('aliases'); $private = $this->boolean('private'); if ($private) { $force_scope = 1; $join_policy = User_group::JOIN_POLICY_MODERATE; } else { $force_scope = 0; $join_policy = User_group::JOIN_POLICY_OPEN; } if ($this->nicknameExists($nickname)) { // TRANS: Group edit form validation error. $this->showForm(_('Nickname already in use. Try another one.')); return; } else { if (!User_group::allowedNickname($nickname)) { // TRANS: Group edit form validation error. $this->showForm(_('Not a valid nickname.')); return; } else { if (!is_null($homepage) && strlen($homepage) > 0 && !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) { // TRANS: Group edit form validation error. $this->showForm(_('Homepage is not a valid URL.')); return; } else { if (!is_null($fullname) && mb_strlen($fullname) > 255) { // TRANS: Group edit form validation error. $this->showForm(_('Full name is too long (maximum 255 characters).')); return; } else { if (User_group::descriptionTooLong($description)) { $this->showForm(sprintf(_m('Description is too long (maximum %d character).', 'Description is too long (maximum %d characters).', User_group::maxDescription()), User_group::maxDescription())); return; } else { if (!is_null($location) && mb_strlen($location) > 255) { // TRANS: Group edit form validation error. $this->showForm(_('Location is too long (maximum 255 characters).')); return; } } } } } } if (!empty($aliasstring)) { $aliases = array_map('common_canonical_nickname', array_unique(preg_split('/[\\s,]+/', $aliasstring))); } else { $aliases = array(); } if (count($aliases) > common_config('group', 'maxaliases')) { // TRANS: Group edit form validation error. // TRANS: %d is the maximum number of allowed aliases. $this->showForm(sprintf(_m('Too many aliases! Maximum %d allowed.', 'Too many aliases! Maximum %d allowed.', common_config('group', 'maxaliases')), common_config('group', 'maxaliases'))); return; } foreach ($aliases as $alias) { if (!Nickname::isValid($alias)) { // TRANS: Group edit form validation error. $this->showForm(sprintf(_('Invalid alias: "%s"'), $alias)); return; } if ($this->nicknameExists($alias)) { // TRANS: Group edit form validation error. $this->showForm(sprintf(_('Alias "%s" already in use. Try another one.'), $alias)); return; } // XXX assumes alphanum nicknames if (strcmp($alias, $nickname) == 0) { // TRANS: Group edit form validation error. $this->showForm(_('Alias can\'t be the same as nickname.')); return; } } // Comprobamos si hay algo que actualizar, o si no ha cambiado nada el usuario. $part1 = false; if ($this->group->nickname == $nickname && $this->group->fullname == $fullname && $this->group->homepage == $homepage && $this->group->description == $description && $this->group->location == $location && $this->group->mainpage == common_local_url('showgroup', array('nickname' => $nickname)) && $this->group->join_policy == $join_policy && $this->group->force_scope == $force_scope) { $part1 = true; } else { $this->group->query('BEGIN'); $orig = clone $this->group; $this->group->nickname = $nickname; $this->group->fullname = $fullname; $this->group->homepage = $homepage; $this->group->description = $description; $this->group->location = $location; $this->group->mainpage = common_local_url('showgroup', array('nickname' => $nickname)); $this->group->join_policy = $join_policy; $this->group->force_scope = $force_scope; $result = $this->group->update($orig); if (!$result) { common_log_db_error($this->group, 'UPDATE', __FILE__); // TRANS: Server error displayed when editing a group fails. $this->serverError(_('Could not update group.')); } } $newaliases = array_unique($aliases); $oldaliases = $this->group->getAliases(); $diffAlias1 = array_diff($oldaliases, $newaliases); $diffAlias2 = array_diff($newaliases, $oldaliases); if ($part1 && (empty($diffAlias1) && empty($diffAlias2))) { $this->showForm(_('Nada que actualizar')); return; } if (!empty($diffAlias1) || !empty($diffAlias2)) { if ($part1) { $this->group->query('BEGIN'); $orig = clone $this->group; } $result = $this->group->setAliases($aliases); if (!$result) { // TRANS: Server error displayed when group aliases could not be added. $this->serverError(_('Could not create aliases.')); } } if ($nickname != $orig->nickname) { common_log(LOG_INFO, "Saving local group info."); $local = Local_group::staticGet('group_id', $this->group->id); $local->setNickname($nickname); } $this->group->query('COMMIT'); Event::handle('EndGroupSaveForm', array($this)); } if ($this->group->nickname != $orig->nickname) { common_redirect(common_local_url('editgroup', array('nickname' => $nickname)), 303); } else { // TRANS: Group edit form success message. $this->showForm(_('Options saved.')); } }
function trySave() { if (Event::handle('StartGroupSaveForm', array($this))) { try { $nickname = Nickname::normalize($this->trimmed('nickname')); } catch (NicknameException $e) { $this->showForm($e->getMessage()); } $fullname = $this->trimmed('fullname'); $homepage = $this->trimmed('homepage'); $description = $this->trimmed('description'); $location = $this->trimmed('location'); $aliasstring = $this->trimmed('aliases'); if ($this->nicknameExists($nickname)) { // TRANS: Group create form validation error. $this->showForm(_('Nickname already in use. Try another one.')); return; } else { if (!User_group::allowedNickname($nickname)) { // TRANS: Group create form validation error. $this->showForm(_('Not a valid nickname.')); return; } else { if (!is_null($homepage) && strlen($homepage) > 0 && !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) { // TRANS: Group create form validation error. $this->showForm(_('Homepage is not a valid URL.')); return; } else { if (!is_null($fullname) && mb_strlen($fullname) > 255) { // TRANS: Group create form validation error. $this->showForm(_('Full name is too long (maximum 255 characters).')); return; } else { if (User_group::descriptionTooLong($description)) { // TRANS: Group create form validation error. // TRANS: %d is the maximum number of allowed characters. $this->showForm(sprintf(_m('Description is too long (maximum %d character).', 'Description is too long (maximum %d characters).', User_group::maxDescription()), User_group::maxDescription())); return; } else { if (!is_null($location) && mb_strlen($location) > 255) { // TRANS: Group create form validation error. $this->showForm(_('Location is too long (maximum 255 characters).')); return; } } } } } } if (!empty($aliasstring)) { $aliases = array_map('common_canonical_nickname', array_unique(preg_split('/[\\s,]+/', $aliasstring))); } else { $aliases = array(); } if (count($aliases) > common_config('group', 'maxaliases')) { // TRANS: Group create form validation error. // TRANS: %d is the maximum number of allowed aliases. $this->showForm(sprintf(_m('Too many aliases! Maximum %d allowed.', 'Too many aliases! Maximum %d allowed.', common_config('group', 'maxaliases')), common_config('group', 'maxaliases'))); return; } foreach ($aliases as $alias) { if (!Nickname::isValid($alias)) { // TRANS: Group create form validation error. // TRANS: %s is the invalid alias. $this->showForm(sprintf(_('Invalid alias: "%s"'), $alias)); return; } if ($this->nicknameExists($alias)) { // TRANS: Group create form validation error. %s is the already used alias. $this->showForm(sprintf(_('Alias "%s" already in use. Try another one.'), $alias)); return; } // XXX assumes alphanum nicknames if (strcmp($alias, $nickname) == 0) { // TRANS: Group create form validation error. $this->showForm(_('Alias cannot be the same as nickname.')); return; } } $cur = common_current_user(); // Checked in prepare() above assert(!is_null($cur)); $group = User_group::register(array('nickname' => $nickname, 'fullname' => $fullname, 'homepage' => $homepage, 'description' => $description, 'location' => $location, 'aliases' => $aliases, 'userid' => $cur->id, 'local' => true)); $this->group = $group; Event::handle('EndGroupSaveForm', array($this)); common_redirect($group->homeUrl(), 303); } }
function bestNewNickname($display, $sreg) { // Try the passed-in nickname if (!empty($sreg['nickname'])) { $nickname = common_nicknamize($sreg['nickname']); if (Nickname::isValid($nickname, true)) { return $nickname; } } // Try the full name if (!empty($sreg['fullname'])) { $fullname = common_nicknamize($sreg['fullname']); if (Nickname::isValid($fullname, true)) { return $fullname; } } // Try the URL $from_url = $this->openidToNickname($display); if ($from_url && Nickname::isValid($from_url, true)) { return $from_url; } // XXX: others? return null; }
/** * Validate params for the new group * * @return void */ function validateParams() { if ($this->groupNicknameExists($this->nickname)) { $this->clientError(_('Nickname already in use. Try another one.'), 403, $this->format); return false; } else { if (!User_group::allowedNickname($this->nickname)) { $this->clientError(_('Not a valid nickname.'), 403, $this->format); return false; } elseif (!is_null($this->homepage) && strlen($this->homepage) > 0 && !Validate::uri($this->homepage, array('allowed_schemes' => array('http', 'https')))) { $this->clientError(_('Homepage is not a valid URL.'), 403, $this->format); return false; } elseif (!is_null($this->fullname) && mb_strlen($this->fullname) > 255) { $this->clientError(_('Full name is too long (maximum 255 characters).'), 403, $this->format); return false; } elseif (User_group::descriptionTooLong($this->description)) { $this->clientError(sprintf(_m('Description is too long (maximum %d character).', 'Description is too long (maximum %d characters).', User_group::maxDescription()), User_group::maxDescription()), 403, $this->format); return false; } elseif (!is_null($this->location) && mb_strlen($this->location) > 255) { $this->clientError(_('Location is too long (maximum 255 characters).'), 403, $this->format); return false; } } if (!empty($this->aliasstring)) { $this->aliases = array_map('common_canonical_nickname', array_unique(preg_split('/[\\s,]+/', $this->aliasstring))); } else { $this->aliases = array(); } if (count($this->aliases) > common_config('group', 'maxaliases')) { $this->clientError(sprintf(_m('Too many aliases! Maximum %d allowed.', 'Too many aliases! Maximum %d allowed.', common_config('group', 'maxaliases')), common_config('group', 'maxaliases')), 403, $this->format); return false; } foreach ($this->aliases as $alias) { if (!Nickname::isValid($alias)) { $this->clientError(sprintf(_('Invalid alias: "%s".'), $alias), 403, $this->format); return false; } if ($this->groupNicknameExists($alias)) { $this->clientError(sprintf(_('Alias "%s" already in use. Try another one.'), $alias), 403, $this->format); return false; } // XXX assumes alphanum nicknames if (strcmp($alias, $this->nickname) == 0) { $this->clientError(_('Alias can\'t be the same as nickname.'), 403, $this->format); return false; } } // Everything looks OK return true; }