Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
'-- Authenticate the user
Dim userInfo As SFSUsersBO = Nothing
Dim loginResult As Login.LoginResult
Using userInfo
loginResult = Login.AuthenticateUser(Me.Username, Me.Password, "", userInfo)
'-- Based on result, we need to configure the app.
' The shared UserContext class handles the hard work of
' determining the default project, then setting permissions, etc.
Select Case loginResult
Case Login.LoginResult.Success
UserContext.SetUserContext(LoggedInUser.CreateNew(userInfo))
Case Login.LoginResult.AdminLoggedOn
UserContext.SetUserContext(New AdminUser(Now))
Case Login.LoginResult.SecMaintUserLoggedOn
UserContext.SetUserContext(New SecurityMaintenanceUser(Now))
Case Login.LoginResult.Failure
End Select
End Using
'-- Raise the attempt login event
' This will handle any messages for user who's logon failed.
Me.OnAttemptLogin()
End Sub
Public Shared Sub SetCurrentProject(ByVal projectID As Integer, ByVal reloginUser As Boolean)
'-- Does user have access to all projects?
Dim userHasAllProjectAccess As Boolean = (_allProjectAccess = PermissionAction.Grant)
'-- Check that the parameters are valid, i.e. is this project
' ID valid for the user. There are two possible causes
' for problems here. The first is that the default project
' table is corrupt and is pointing to a project that has
' been deleted or was imported from another server and
' doesn't exist. The other is that somebody is trying to
' break into the system
![Sad](http://forum.strataframe.net/Skins/Classic/Images/EmotIcons/Sad.gif)
If Array.IndexOf(_userProjectList, projectID) < 0 Then
Throw New ArgumentException("The project ID provided is invalid." _
, "projectID" _
, New Exception("The user does not have access to this project"))
End If
'-- Cache the project ID so it is easily accessible.
_currentProjectID = projectID
'-- Cache details about this project (client), so it is easily accessible
' to forms/methods that need the current project.
Using boProject As New Project.ProjectBO
boProject.FillByPrimaryKey(projectID)
_currentProjectName = boProject.ProjectName
'-- Other data about project you might need...
'-- Notify subscribers that project state has changed. This
' notifies any open forms that the project has changed.
boProject.NotifyProjectDataChanged()
'-- Set the current BO (which allows above to occur)
_currentProjectBO = boProject
'-- Configure the bo to monitor for data changes
AddHandler _currentProjectBO.ProjectDataChanged, AddressOf CurrentProject_DataChanged
End Using
'-- Handle setting roles
If Not userHasAllProjectAccess Then
'-- First clear any existing roles for the user.
ClearUserProjectRoles()
'-- Now set the roles defined
' Get the roles that can be defined by project
Using userProjectRoles As New SecUserProjectRoleBO
userProjectRoles.FillByUserProject(UserContext.CurrentUserID, _currentProjectID)
'-- For each role, add it to the SF user roles linking data
For Each projectRole As Data.DataRow In userProjectRoles.CurrentDataTable.Rows
'-- Open a BO to the SF user roles data
Using userSFRolesBO As New SFBO.SFSUsersXRolesBO
userSFRolesBO.FillAllByUser(UserContext.CurrentUserID)
userSFRolesBO.Add()
userSFRolesBO.ur_rl_pk = DirectCast(projectRole.Item("RoleID"), Integer)
userSFRolesBO.ur_us_pk = UserContext.CurrentUserID
userSFRolesBO.Save()
End Using
Next
End Using
End If
'-- If indicated, login user in (needed if user is changing projects)
If reloginUser Then
'-- Handle the case of admin users, who don't need refresh
If SecurityBasics.CurrentUser.IsAdministrator Then Return
'-- Login the user in again, which updates permissions
Using userSFBO As New SFBO.SFSUsersBO
userSFBO.FillByPrimaryKey(SecurityBasics.CurrentUser.UserPK)
LoggedInUser.SetLoggedOnUser(userSFBO)
End Using
End If
End Sub