This function can be used to limit the number of concurrent user sessions by the same user to a specified number of sessions.To implement follow the steps below (has only been tested on SQL Server with SQL Auth.
Step 1) Paste this function in to the top of the Common Script workflow module (NOTE: You will need to change the string "SiteAdminDB" to the value of the site admin DB, by default this is "qcsiteadmin_db"
Function user_IsLoggedIn(theUser) On Error Resume Next Dim SiteAdminDB : SiteAdminDB = "qcsiteadmin_db_ALM_11_50" Dim TDC, COM, SQL, RecSet Set TDC = TDConnection Set COM = TDC.Command SQL = "SELECT COUNT(LS_ID) FROM " & SiteAdminDB & ".td.LOGIN_SESSIONS " &_ "WHERE LS_USER_NAME = " & "'" & theUser & "'" & " AND LS_CLIENT_TYPE <> 'SiteAdmin'" COM.CommandText = SQL Set RecSet = COM.Execute RC = RecSet(0) 'MsgBox "RC is: " & RC user_IsLoggedIn = RC 'MsgBox "User has " & user_IsLoggedIn & " sessions logged." On Error GoTo 0 End Function
Step 2) In the CanLogin function in the Common Script workflow module paste the following code (NOTE: You will need to commend out CanLogin = DefaultRes)
Dim userSessions : userSessions = user_IsLoggedIn(UserName) 'MsgBox "The number of active user sessions is: " & userSessions If userSessions >= 2 Then CanLogin = False MsgBox "You already have " & userSessions & " ALM session(s) established. No Concurrent Login Sessions allowed.", vbCritical, "NO MILTI SESSION LOGINS" Else CanLogin = True End If 'CanLogin = DefaultRes
You have implemented the user sessions limiter workflow. If you wish to change the number of concurrent user sessions to more than 1 then change the comparison operator value integer in the if statement.
If you try and log-in and your profile has a current session you will receive the following error message. The text can be adjusted.