HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Show a display name instead of username
jspautsch
✭✭✭
I'd like for users and their posts to be labeled with a display name (e.g. "Jon Smith") that's separate from the username they use to login (which is how our SSO works). I've searched around a bit, as I could've sworn I saw someone else ask as similar question, but I couldn't find anything, so I was wondering if anyone else had any ideas as to how best to go about doing this.
I'll be delving into myself in a couple days, but first I wanted to see what the community had to say. Also I'd really like to keep it confined to a plugin and thereby avoid modifying any of the core files, but I'm new to Vanilla development and am not sure if that will be possible for this particular feature.
I'll be delving into myself in a couple days, but first I wanted to see what the community had to say. Also I'd really like to keep it confined to a plugin and thereby avoid modifying any of the core files, but I'm new to Vanilla development and am not sure if that will be possible for this particular feature.
0
Answers
For the rest, I made a plugin that did the following:
1) Added another column to the User table called DisplayName
2) Overrode the UserBuilder and UserAnchor functions to include DisplayName.
3) Setup event handlers for AfterDiscussionSummaryQuery, BeforeGetID (discussion model), AfterCommentQuery, and AfterActivityQuery (which I had to add into the core code myself) to add select statements that mirrored the Name statements in each function, except replaced with DisplayName instead.
This setup allowed me to change the link text to use display names, but left most of the links themselves intact (linking to usernames not display names). Mind you, even if the links to point to display names it doesn't seem to affect anything, seeing as the links really use User IDs.
I also don't have a way to set the display name, that's done separately in the code for my SSO login.
We're using SSO too, so that's not a problem.
Step 1: Make the following modifications... See next comment for the plugin code...
Note that this plugin overrides two methods: UserAnchor and UserBuilder. If you're using another plugin that also overrides these methods (like Gravatar), I'm pretty sure you'll need to modify them to include DisplayName as well.
I'm trying to use this but apparently I'm missing something, I'm using 2.0.18.8 and it doesn't display the Display Name, just a blank spot, which is a problem. I've attempted to disable the plugin so I could at least go back and have the username display, but it looks like it's stuck in there pretty good and can't disable it. When I click jsConnect in the dashboard and run Test URL it shows the display name as well as the correct other information, so I know it's making its way into Vanilla. Any suggestions? I am guessing something changed in the coding in between versions that the plugin code need some adjusting, just not sure quite where to look as I am new to using this forum and still trying to figure out it's in's and out's.
Are you using this plugin...
http://vanillaforums.org/addon/firstlastnames-plugin
or the instructions in this thread. Perhaps the plugin above is what you really want.
you can disable the plugin in the conf/config.php - by removing the line that refers to the plugin in question.
$Configuration['EnabledPlugins']['THEPLUGINNAMEYORARETRYINGTOREMOVE'] = ...
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
anyone been successful with this in 2.0.18.8? I will give it a go later today and report the experience.
Ok, figured out how to disable it, I had actually renamed it within my file structure and that worked also, but I have used your suggestion, thank you. I've completely reinstalled this and still no luck. I actually have a displayname coming thru and was hoping to use that, so I was using the code above. I noticed some changes such as in class.activitymodel.php, $this->FireEvent('AfterActivityQuery'); was already there, and in class.conversationmodel.php there was an extra field in there of u.Email, but I don't see those being a big issue. I could very well use the firstlastnames plugin you referenced, but in the forum I'd much rather not allow users to change information, I'd like the SSO system to maintain that in my regular site to keep everything all the same. I did try that plugin and it works until a new user tries to register and I presume since I have this vanillaforums.org/discussion/22681/disable-edit-my-account-and-change-password-for-sso working in there it will not let the user enter the first or last name at the sign in screen, therefore they can't register. jspautsch references a simple database update, that may be the part I'm missing; I must confess MySQL and phpmyadmin tend to throw me for a loop. I'm thinking that may be where I'm going wrong.
Well I feel like I should have egg on my face, after thinking about this a bit I realized that I have the jsConnect plugin working, and in order for the Display name field to send into the database like the name, email, ect, I needed to add DisplayName into the class.jsconnect.plugin.php file, now when a user is automatically registered the display name field comes along and is added properly. It just randomly came to me today, and after a quick test that is all it was and it is now working. Thanks for the suggestions.
Anyone a solution for 2.4 with display names?
2.4 hasn't been released for production, and now never will be (moving straight to 2.5)
To my opinion the approach is somewhat borked, but I'm not 100% sure what the requirements are. Is it for security? Is it just for fun?
I have just drafted* a small plugin which forces users to log into the forum with their mail address so that it wouldn't be possible to log into the forum with the user name displayed.
If you have security concerns, than that would be your solution.
If it is just for fun and you want to allow users to show cool names here and there, you might want to try the ProfileExtender plugin and learn how to add such a name to several places by making use of Vanillas event system.
* = it is more than just a proof of concept and already fully usable but in order to not mess anything up, there need to be a check in the setup process for duplicate mail addresses in the database. If some users have registered more than one account with the same mail address, they wouldn't be able to access all of their accounts
Thanks for your quick answers!
Sorry, I mean the current public 2.3.1...
It's just because I want to display the full name of a user for a serious forum. The usernames cannot have white spaces or typically german letters like "ä" "ü" "ö" "ß" - That's ok, because of the login i guess, but in my case I looking for a way to do it.
Currently I have found a way with the ProfileExtender plugin and a simple override based on the solution upward for the "UserAnchor" function, this is working on discussions but not in the activities or profile page. Have someone an Idea why? I guess for the profile page heading is another function to override required.
(My php skills are not perfect)