MyBB Community Forums

Full Version: Show custom profile field instead of username in roster
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Since I'm the admin for our schools forum, I've set the login-names to the same as the ones used in the school intranet. This makes for dull names like "ABC12345". Those are hardly human-readable. Yet it makes it easy for the students to log in sicne they already use the intranet and thus alredy know their own login-names.

I've created a custom profile field where I've entered their real names in the profile, but there's still the problem of getting this to show in the actual forum.

For example:

Moderated By: AAA999999
User(s) browsing this forum: ABC12345

Doesn't tell the students nearly as much as:

Moderated By: Mr Smith
User(s) browsing this forum: Jim Jones

They told me in the General support forum that this wasn't a standard feature.

I was told to try this:

http://community.mybboard.net/showthread...8#pid88958' Wrote: [ -> ]Open inc/functions_user.php.
Find:
	$query = $db->query("SELECT uid,username,password,salt,loginkey,remember FROM ".TABLE_PREFIX."users WHERE username='".$db->escape_string($username)."' LIMIT 1");
Replace with:
	$query = $db->query("SELECT u.uid,u.username,u.password,u.salt,u.loginkey,u.remember FROM (".TABLE_PREFIX."users u, ".TABLE_PREFIX."userfields uf) WHERE uf.ufid=u.uid AND uf.fid4='".$db->escape_string($username)."' LIMIT 1");

Replace fid4 with your custom profile field ID. Make the username the real name of the user, and the custom profile field the AAA11111 whatever login ID. (Make a backup of your database first, no guarantees of this working).

But that should theoretically allow users to login with the AAA11111 stuff, and still show the real name everywhere else.

but instead I only got this:
my forum Wrote:You have entered an invalid username. Usernames can only contain alphanumeric characters.
You have 2 more login attempts.

Does anyone have any other ideas for me?

(Since this now is about code mods, I thought I'd move my question here instead of asking in the general support forum)
Ok need a bit more modification:

In inc/functions_user.php
Find:
/**
 * Checks if $username already exists in the database.
 *
 * @param string The username for check for.
 * @return boolean True when exists, false when not.
 */
function username_exists($username)
{
	global $db;
	$query = $db->query("SELECT * FROM ".TABLE_PREFIX."users WHERE username='".$db->escape_string($username)."' LIMIT 1");
	if($db->fetch_array($query))
	{
		return true;
	}
	else
	{
		return false;
	}
}
After that, add this:
/**
 * Checks if $username already exists in the database as a login name.
 *
 * @param string The username for check for.
 * @return boolean True when exists, false when not.
 */
function loginname_exists($username)
{
	global $db;
	$query = $db->query("SELECT u.uid FROM (".TABLE_PREFIX."users u, ".TABLE_PREFIX."userfields uf) WHERE uf.ufid = u.uid AND uf.fid4='".$db->escape_string($username)."' LIMIT 1");
	if($db->fetch_array($query))
	{
		return true;
	}
	else
	{
		return false;
	}
}
(Remember to replace fid4 with your custom profile field ID)

And another modification in member.php:
Find:
if(!username_exists($mybb->input['username']))
Replace with:
if(!loginname_exists($mybb->input['username']))


Again, the custom profile field fidX should contain the AAA11111 login ID and the username field in mybb_users should contain the user's full name.
no luck

Now I get

Parse error: syntax error, unexpected T_VARIABLE in /hsphere/local/home/skogen/teach.bolmdahl.com/inc/functions_user.php on line 74
when I try to visit the forums.
line 74 is (according to gedit)
$user = $db->fetch_array($query);
the whole section is
/**

 * Checks a password with a supplied username.

 *

 * @param string The username of the user.

 * @param string The md5()'ed password.

 * @return boolean|array False when no match, array with user info when match.

 */

function validate_password_from_username($username, $password)

{

	global $db;

	$query = $db->query("SELECT u.uid,u.username,u.password,u.salt,u.loginkey,u.remember FROM (".TABLE_PREFIX."users u, ".TABLE_PREFIX."userfields uf) WHERE uf.ufid=u.uid AND uf.fid4='".$db->escape_string($username)."' LIMIT 1"

	$user = $db->fetch_array($query);

	if(!$user['uid'])

	{

		return false;

	}

	else

	{

		return validate_password_from_uid($user['uid'], $password, $user);

	}

}
You forgot the closing parenthesis and semi-colon in the $query line:

$query = $db->query("SELECT u.uid,u.username,u.password,u.salt,u.loginkey,u.remember FROM (".TABLE_PREFIX."users u, ".TABLE_PREFIX."userfields uf) WHERE uf.ufid=u.uid AND uf.fid4='".$db->escape_string($username)."' LIMIT 1");
woopie!
It worked!

Thanks a million for all the help Big Grin