Skip to content

Commit

Permalink
Merge pull request #5620 from BOINC/dpa_unique_name
Browse files Browse the repository at this point in the history
web: add option for making user name unique
  • Loading branch information
AenBleidd committed May 15, 2024
2 parents 38520e1 + 132c45a commit 308bac6
Show file tree
Hide file tree
Showing 27 changed files with 318 additions and 137 deletions.
2 changes: 1 addition & 1 deletion db/constraints.sql
Expand Up @@ -12,7 +12,7 @@ alter table user
add unique(email_addr),
add unique(authenticator),
add index ind_tid (teamid),
add index user_name(name),
add unique(name),
add index user_tot (total_credit desc),
-- db_dump.C
add index user_avg (expavg_credit desc),
Expand Down
4 changes: 2 additions & 2 deletions html/inc/bootstrap.inc
Expand Up @@ -81,7 +81,7 @@ function navbar_right($user) {
if ($user) {
echo sprintf('
<li><a href=%s%s>%s</a></li>
', url_base(), USER_HOME, $user->name
', url_base(), HOME_PAGE, $user->name
);
$url_tokens = url_tokens($user->authenticator);
echo sprintf('<li><a href="%slogout.php?%s">Log out</a></li>',
Expand Down Expand Up @@ -156,7 +156,7 @@ function sample_navbar(

$x = array();
if ($user) {
$x[] = array(tra("Account"), $url_prefix.USER_HOME);
$x[] = array(tra("Account"), $url_prefix.HOME_PAGE);
$x[] = array(tra("Join"), $url_prefix."join.php");
$x[] = array(tra("Preferences"), $url_prefix."prefs.php?subset=project");
}
Expand Down
1 change: 1 addition & 0 deletions html/inc/forum.inc
Expand Up @@ -809,6 +809,7 @@ function check_banished($user) {
}

function post_rules() {
if (defined('FORUM_RULES')) return FORUM_RULES;
if (function_exists("project_forum_post_rules")) {
$project_rules=project_forum_post_rules();
} else {
Expand Down
20 changes: 13 additions & 7 deletions html/inc/friend.inc
@@ -1,7 +1,7 @@
<?php
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2008 University of California
// Copyright (C) 2024 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
Expand All @@ -16,6 +16,8 @@
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.

// code related to 'friend' features

// The following two are what gets put into notification email digests
//
function friend_notify_req_email_line($notify) {
Expand All @@ -36,9 +38,13 @@ function friend_notify_accept_email_line($notify) {
function friend_notify_req_web_line($notify) {
$user = BoincUser::lookup_id($notify->opaque);
if (!$user) return null;
return "
<a href=friend.php?action=query&userid=$notify->opaque>Friendship request</a> from <a href=show_user.php?userid=$user->id>$user->name</a>
";
return sprintf(
'<a href=friend.php?action=query&userid=%d>Friendship request</a> from <a href=%s?userid=%d>%s</a>',
$notify->opaque,
SHOW_USER_PAGE,
$user->id,
$user->name
);
}

function friend_notify_accept_web_line($notify) {
Expand All @@ -61,7 +67,7 @@ $src_user->name says: $msg

$message .= "
Please accept or decline by visiting
".secure_url_base().USER_HOME."
".secure_url_base().HOME_PAGE."
--------------------------
To change email preferences, visit:
Expand All @@ -83,7 +89,7 @@ $dest_user->name says: $msg

$message .= "
Visit your Account page at
".secure_url_base().USER_HOME."
".secure_url_base().HOME_PAGE."
--------------------------
To change email preferences, visit:
Expand Down Expand Up @@ -112,7 +118,7 @@ function friend_accept_rss($notify, &$title, &$msg, &$url) {
}
$title = "Friendship confirmation";
$msg = "$src_user->name has confirmed you as a friend";
$url = secure_url_base().USER_HOME;
$url = secure_url_base().HOME_PAGE;
}

// delete friendship connections
Expand Down
1 change: 1 addition & 0 deletions html/inc/more.inc
Expand Up @@ -31,6 +31,7 @@ function show_text_more($text, $nchars) {
//
function show_text_more_aux($text, $nchars) {
static $count = 0;
if (!$text) return '';

$n = strlen($text);
if ($n < $nchars) {
Expand Down
17 changes: 12 additions & 5 deletions html/inc/pm.inc
Expand Up @@ -28,6 +28,7 @@ function pm_header() {
}

function pm_rules() {
if (defined('PM_RULES')) return PM_RULES;
$x = "<table><tr><td align=left><small>";
$x .= tra("
<ul>
Expand Down Expand Up @@ -113,8 +114,8 @@ function pm_form($replyto, $userid, $error = null) {
);
}

$subject = null;
$content = null;
$subject = '';
$content = '';
if ($replyto) {
$message = BoincPrivateMessage::lookup_id($replyto);
if (!$message || $message->userid != $g_logged_in_user->id) {
Expand All @@ -126,7 +127,7 @@ function pm_form($replyto, $userid, $error = null) {
if (!$user) {
error_page("Sender no longer exists");
}
$writeto = $userid." (".$user->name.")";
$writeto = UNIQUE_USER_NAME?$user->name:$userid." (".$user->name.")";
$subject = $message->subject;
if (substr($subject, 0, 3) != "re:") {
$subject = "re: ".$subject;
Expand All @@ -136,7 +137,7 @@ function pm_form($replyto, $userid, $error = null) {
if (!$user) {
error_page("Sender no longer exists");
}
$writeto = $userid." (".$user->name.")";
$writeto = UNIQUE_USER_NAME?$user->name:$userid." (".$user->name.")";
} else {
$writeto = sanitize_tags(post_str("to", true));
$subject = post_str("subject", true);
Expand All @@ -154,7 +155,13 @@ function pm_form($replyto, $userid, $error = null) {
echo "<input type=\"hidden\" name=\"action\" value=\"send\">\n";
echo form_tokens($g_logged_in_user->authenticator);
start_table();
row2(tra("To")."<br /><small>".tra("User IDs or unique usernames, separated with commas")."</small>",
row2(
sprintf('%s <br><small>%s</small>',
tra("To"),
UNIQUE_USER_NAME
?tra('User names, separated with commas')
:tra("User IDs or unique usernames, separated with commas")
),
"<input type=\"text\" class=\"form-control\" name=\"to\" value=\"$writeto\">",
null, '20%'
);
Expand Down
64 changes: 48 additions & 16 deletions html/inc/user.inc
Expand Up @@ -286,7 +286,9 @@ function show_user_info_private($user) {
.$delete_account_str
);
}
row2(tra("User ID")."<br/><p class=\"small\">".tra("Used in community functions")."</p>", $user->id);
if (!UNIQUE_USER_NAME) {
row2(tra("User ID")."<br/><p class=\"small\">".tra("Used in community functions")."</p>", $user->id);
}
if (!NO_COMPUTING) {
row2(
tra("Account keys"),
Expand Down Expand Up @@ -323,27 +325,41 @@ function show_preference_links() {
}
}

// return describing a friend: their name, and profile picture if it exists
//
function friend_links($user) {
if (is_banished($user)) {
return "";
}
$x = "<table height=\"100\" width=\"150\" border=\"0\" cellpadding=\"4\"><tr><td class=\"friend\">";
$x = sprintf(
'<a href="%s%s?userid=%d" style="%s">%s</a>',
url_base(),
SHOW_USER_PAGE,
$user->id,
'vertical-align:top',
$user->name
);
if ($user->has_profile) {
$profile = BoincProfile::lookup_fields("has_picture", "userid=$user->id");
if ($profile && $profile->has_picture) {
$img_url = profile_thumb_url($user->id);
} else {
$img_url = url_base()."img/head_20.png";
}
$title = tra("View the profile of %1", $user->name);
$alt = tra("Profile");
$x .= ' <a href="'.url_base().'view_profile.php?userid='.$user->id.'"><img title="'.$title.'" src="'.$img_url.'" alt="'.$alt.'"></a><br>';
$x .= sprintf(
'<a href="%sview_profile.php?userid=%d"><img title="%s" src="%s" alt="%s"></a><br>',
url_base(),
$user->id,
tra("View the profile of %1", $user->name),
$img_url,
tra("Profile")
);
}
$x .= " <a href=\"".url_base()."show_user.php?userid=".$user->id."\">".$user->name."</a>";
if (function_exists("project_user_links")) {
$x .= project_user_links($user);
}
$x .= "</td></tr></table>\n";
$x .= '</div>';
return $x;
}

Expand All @@ -359,13 +375,26 @@ function user_links($user, $badge_height=0, $name_limit=0) {
$x = "";
if ($user->has_profile) {
$img_url = url_base()."img/head_20.png";
$x .= ' <a href="'.url_base().'view_profile.php?userid='.$user->id.'"><img title="View the profile of '.$user->name.'" src="'.$img_url.'" alt="Profile"></a>';
$x .= sprintf(
' <a href="%s%s?userid=%d"><img title="View the profile of %s" src="%s" alt="Profile"></a>',
url_base(),
'view_profile.php',
$user->id,
$user->name,
$img_url
);
}
$name = $user->name;
if ($name_limit && strlen($name) > $name_limit) {
$name = substr($name, 0, $name_limit)."...";
}
$x .= " <a href=\"".url_base()."show_user.php?userid=".$user->id."\">".$name."</a>";
$x .= sprintf(
'<a href="%s%s?userid=%d">%s</a>',
url_base(),
SHOW_USER_PAGE,
$user->id,
$name
);
if (function_exists("project_user_links")){
$x .= project_user_links($user);
}
Expand Down Expand Up @@ -441,25 +470,26 @@ function show_community_private($user) {
}

$friends = BoincFriend::enum("user_src=$user->id and reciprocated=1");
$x = "<a href=\"user_search.php\">".tra("Find friends")."</a><br/>\n";
$n = count($friends);
if ($n) {
$x = '';
if ($friends) {
foreach($friends as $friend) {
$fuser = BoincUser::lookup_id($friend->user_dest);
if (!$fuser) continue;
$x .= friend_links($fuser);
}
row2(tra("Friends")." ($n)", $x);
} else {
row2(tra("Friends"), $x);
} else {
row2(tra("Friends"), '---');
}
}

// show summary of dynamic and static info (public)
//
function show_user_summary_public($user) {
global $g_logged_in_user;
row2(tra("User ID"), $user->id);
if (!UNIQUE_USER_NAME) {
row2(tra("User ID"), $user->id);
}
row2(tra("%1 member since", PROJECT), date_str($user->create_time));
if (USER_COUNTRY) {
row2(tra("Country"), $user->country);
Expand Down Expand Up @@ -505,6 +535,8 @@ function get_community_links_object($user){
return $cache_object;
}

// show community links of another user (described by $clo)
//
function community_links($clo, $logged_in_user){
$user = $clo->user;
$team = $clo->team;
Expand Down Expand Up @@ -538,11 +570,11 @@ function community_links($clo, $logged_in_user){
}

if ($friends) {
$x = "";
$x = '';
foreach($friends as $friend) {
$x .= friend_links($friend);
}
row2(tra("Friends")." (".sizeof($friends).")", $x);
row2(tra('Friends'), $x);
}
}

Expand Down
21 changes: 21 additions & 0 deletions html/inc/user_util.inc
Expand Up @@ -90,6 +90,10 @@ function is_valid_user_name($name, &$reason) {
$reason = tra("user name may not contain HTML tags");
return false;
}
if (is_numeric($name)) {
$reason = tra("user name may not be a number");
return false;
}
return true;
}

Expand Down Expand Up @@ -228,6 +232,23 @@ function validate_post_make_user() {
if (!is_valid_user_name($new_name, $reason)) {
show_error($reason);
}
if (UNIQUE_USER_NAME) {
$u = BoincUser::lookup_name($new_name);
if ($u) {
page_head("That name is in use");
echo "<p>The following user names are taken;
please go back and use a different one.<p>
";
$users = BoincUser::enum(
sprintf("name like '%s%%'", $new_name)
);
foreach ($users as $u){
echo "<p>$u->name\n";
}
page_tail();
exit;
}
}

$new_email_addr = strtolower(post_str("new_email_addr"));
if (!is_valid_email_addr($new_email_addr)) {
Expand Down
26 changes: 22 additions & 4 deletions html/inc/util.inc
Expand Up @@ -91,9 +91,21 @@ if (!defined('NO_STATS')) {
if (!defined('NO_GLOBAL_PREFS')) {
define('NO_GLOBAL_PREFS', false);
}
if (!defined('USER_HOME')) {
define('USER_HOME', 'home.php');

// the 'home page' of the logged-in user.
// go here after login, account creation, team operations, etc.
//
if (!defined('HOME_PAGE')) {
define('HOME_PAGE', 'home.php');
}

// the page showing another user.
// Link to here wherever we show a user name.
//
if (!defined('SHOW_USER_PAGE')) {
define('SHOW_USER_PAGE', 'show_user.php');
}

if (!defined('POST_MAX_LINKS')) {
define('POST_MAX_LINKS', 0);
}
Expand All @@ -103,6 +115,9 @@ if (!defined('DARK_MODE')) {
if (!defined('VALIDATE_EMAIL_TO_POST')) {
define('VALIDATE_EMAIL_TO_POST', false);
}
if (!defined('UNIQUE_USER_NAME')) {
define('UNIQUE_USER_NAME', false);
}

// don't allow anything between .php and ? in URL
//
Expand Down Expand Up @@ -550,10 +565,13 @@ function rowify($string) {
echo "<tr><td>$string</td></tr>";
}

function row_array($x) {
function row_array($x, $attrs=null) {
echo "<tr>\n";
$i = 0;
foreach ($x as $h) {
echo "<td>$h</td>\n";
$a = $attrs?$attrs[$i]:"";
echo "<td $a>$h</td>\n";
$i++;
}
echo "</tr>\n";
}
Expand Down
1 change: 1 addition & 0 deletions html/project.sample/project.inc
Expand Up @@ -47,6 +47,7 @@ display_errors();

//-------------- enable/disable web features

define('UNIQUE_USER_NAME', true);
define("FORUM_QA_MERGED_MODE", true);
// Set to true to merge Message boards and Q&A section
define ("DISABLE_PROFILES", true);
Expand Down

0 comments on commit 308bac6

Please sign in to comment.