Page 1 of 1
Find the User Who's Currently Logged In
Posted: Tue Jun 05, 2018 7:46 pm
by tholmes
Open Dental supports the idea of user authentication/identity (
http://www.opendental.com/manual/security.html).
How do I programatically identify the currently "logged in" user to Open Dental? How does this behave when there's no authentication enabled in Open Dental?
E.G. Is there a Class/Method that I can call in OpenDentBusiness?
Thanks!
-Tyler
Re: Find the User Who's Currently Logged In
Posted: Wed Jun 06, 2018 7:37 am
by cmcgehee
You can identify the currently logged in user from OpenDentBusiness.Security.CurUser. This is guaranteed to be set when running the Open Dental program. If you are not using authentication, the first Admin user with no password will be set as the current user.
Re: Find the User Who's Currently Logged In
Posted: Thu Jun 07, 2018 6:32 pm
by tholmes
Thanks Chris. Any way to tell whether Auth has been turned on for a given install?
I.E. If I call OpenDentBusiness.Security.CurUser, and I get the Admin user, how do I know the difference between someone logging in as Admin (with Auth ON), vs. everyone being an Admin (with Auth OFF).
Re: Find the User Who's Currently Logged In
Posted: Sat Jun 09, 2018 11:16 am
by cmcgehee
Sure, you can call OpenDentBusiness.Userods.GetAdminUser. If the password on that user is blank, you can tell that everyone is logging in as the admin user.
Re: Find the User Who's Currently Logged In
Posted: Fri Jun 15, 2018 9:58 am
by tholmes
Great, thanks Chris!
Re: Find the User Who's Currently Logged In
Posted: Mon Jul 09, 2018 9:18 am
by JLM
I am interested in the same information. I want to create a utility to nag users to punch in on the timeclock if they login but haven't punched in.
The following code returns null for
user and the second line throws and exception about being unable to connect to any of the specified MySQL hosts. Apparently there is more that I need to know...
OD is running and I am logged in...
Thanks,
JLM
Code: Select all
namespace WindowsFormsApp5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Userod user = OpenDentBusiness.Security.CurUser;
Userod user2 = OpenDentBusiness.Userods.GetAdminUser();
}
}
}
Re: Find the User Who's Currently Logged In
Posted: Mon Jul 09, 2018 9:36 am
by jsalmon
JLM wrote:...The following code returns null for user and the second line throws and exception about being unable to connect to any of the specified MySQL hosts. Apparently there is more that I need to know...
OD is running and I am logged in...
All of those errors point to you not actually being logged into Open Dental yet. Maybe you launched your form too early? What plug-in hook are you using to launch your form with?
Re: Find the User Who's Currently Logged In
Posted: Mon Jul 09, 2018 10:31 am
by JLM
jsalmon wrote:JLM wrote:...The following code returns null for user and the second line throws and exception about being unable to connect to any of the specified MySQL hosts. Apparently there is more that I need to know...
OD is running and I am logged in...
All of those errors point to you not actually being logged into Open Dental yet. Maybe you launched your form too early? What plug-in hook are you using to launch your form with?
I am logged in (DrM appears in window bar) and the application is launched with OD running. I don't use any hooks. The application is free standing. The code shown earlier is the complete application so far as I am testing the concept. There must be some initialization that I am missing.
JLM
Re: Find the User Who's Currently Logged In
Posted: Mon Jul 09, 2018 12:49 pm
by jsalmon
You need to implement some sort of complicated Windows messaging system so the two "free standing" applications can talk to each other because how you are trying to user OpenDentBusiness isn't how applications talk to each other. You can't ask a standalone library (OpenDentBusiness.dll) who the currently logged in user is because the library doesn't have any context. The application (OpenDental.exe) has the context (memory and such) for what user is currently logged in and simply utilizes the library as blueprints if you will.
The easiest way to get this information is to convert your "free standing" application into a plug-in where you launch it from the ODToolBar in one of the main modules.
http://www.opendental.com/manual/plugins.html
Re: Find the User Who's Currently Logged In
Posted: Mon Jul 09, 2018 2:48 pm
by JLM
Actually, I have written code for other applications that 'expose themselves' in this exact fashion. They want utility writers to access the database through their interface instead of banging on the database yourself. It was a promising approach but not if I have to try to learn the plugin system. I will look at the db to see if I can determine who has punched in today and I can enumerate the windows and extract the user name from the window title to accomplish the same thing. Thanks for the info.
JLM
Re: Find the User Who's Currently Logged In
Posted: Mon Jul 09, 2018 3:45 pm
by allends
They want utility writers to access the database through their interface instead of banging on the database yourself.
That is exactly what the OpenDentBusiness.dll is for and we encourage you to use it for interfacing with the DB.
Security.CurUser is not a database field though. That field needs the context of OpenDental in order to tell who is logged in because it is set by the OpenDental program as an in-memory variable.
I highly recommend using our plug-in system to utilize variables that are set within OpenDental.exe.
If you still wish to not use the plug-in system and instead use the method you proposed then I can foresee one pitfall with that...
What happens if you ran three instances of OpenDental and logged in to three different users?
Re: Find the User Who's Currently Logged In
Posted: Mon Jul 09, 2018 7:52 pm
by JLM
What happens if you ran three instances of OpenDental and logged in to three different users?

Then I could crowd source the clock-ins. The latest user can nag the other two for me until everyone is clocked in.
thanks for the info.
JLM