Find the User Who's Currently Logged In

This forum is for programmers who have questions about the source code.
Post Reply
tholmes
Posts: 16
Joined: Fri Feb 16, 2018 10:39 am

Find the User Who's Currently Logged In

Post by tholmes » Tue Jun 05, 2018 7:46 pm

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

User avatar
cmcgehee
Posts: 711
Joined: Tue Aug 25, 2015 5:06 pm
Location: Salem, Oregon

Re: Find the User Who's Currently Logged In

Post by cmcgehee » Wed Jun 06, 2018 7:37 am

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.
Chris McGehee
Open Dental Software
http://www.opendental.com

tholmes
Posts: 16
Joined: Fri Feb 16, 2018 10:39 am

Re: Find the User Who's Currently Logged In

Post by tholmes » Thu Jun 07, 2018 6:32 pm

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).

User avatar
cmcgehee
Posts: 711
Joined: Tue Aug 25, 2015 5:06 pm
Location: Salem, Oregon

Re: Find the User Who's Currently Logged In

Post by cmcgehee » Sat Jun 09, 2018 11:16 am

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.
Chris McGehee
Open Dental Software
http://www.opendental.com

tholmes
Posts: 16
Joined: Fri Feb 16, 2018 10:39 am

Re: Find the User Who's Currently Logged In

Post by tholmes » Fri Jun 15, 2018 9:58 am

Great, thanks Chris!

JLM
Posts: 128
Joined: Wed Dec 05, 2012 12:52 pm

Re: Find the User Who's Currently Logged In

Post by JLM » Mon Jul 09, 2018 9:18 am

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();
        }
    }
}

User avatar
jsalmon
Posts: 1551
Joined: Tue Nov 30, 2010 12:33 pm
Contact:

Re: Find the User Who's Currently Logged In

Post by jsalmon » Mon Jul 09, 2018 9:36 am

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?
The best thing about a boolean is even if you are wrong, you are only off by a bit.

Jason Salmon
Open Dental Software
http://www.opendental.com

JLM
Posts: 128
Joined: Wed Dec 05, 2012 12:52 pm

Re: Find the User Who's Currently Logged In

Post by JLM » Mon Jul 09, 2018 10:31 am

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

User avatar
jsalmon
Posts: 1551
Joined: Tue Nov 30, 2010 12:33 pm
Contact:

Re: Find the User Who's Currently Logged In

Post by jsalmon » Mon Jul 09, 2018 12:49 pm

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
The best thing about a boolean is even if you are wrong, you are only off by a bit.

Jason Salmon
Open Dental Software
http://www.opendental.com

JLM
Posts: 128
Joined: Wed Dec 05, 2012 12:52 pm

Re: Find the User Who's Currently Logged In

Post by JLM » Mon Jul 09, 2018 2:48 pm

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

allends
Posts: 235
Joined: Fri Aug 23, 2013 11:29 am

Re: Find the User Who's Currently Logged In

Post by allends » Mon Jul 09, 2018 3:45 pm

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?
Allen
Open Dental Software
http://www.opendental.com

JLM
Posts: 128
Joined: Wed Dec 05, 2012 12:52 pm

Re: Find the User Who's Currently Logged In

Post by JLM » Mon Jul 09, 2018 7:52 pm

What happens if you ran three instances of OpenDental and logged in to three different users?
:lol: 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

Post Reply