check user login
This commit is contained in:
parent
1108fa47e0
commit
cd23c5b974
@ -6,6 +6,9 @@
|
||||
Public Property Email As String
|
||||
Public Property Language As String
|
||||
|
||||
Public Property HasAccess As Boolean
|
||||
Public Property IsAdmin As Boolean
|
||||
|
||||
Public ReadOnly Property FullName() As String
|
||||
Get
|
||||
Return Prename + " " + Name
|
||||
|
||||
@ -27,15 +27,7 @@ Public Class ConfigModel
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function GetUserId() As Integer
|
||||
Try
|
||||
Dim oUserId As Integer = Database.GetScalarValue($"SELECT GUID FROM TBDD_USER WHERE USERNAME = '{Environment.UserName}'")
|
||||
Return oUserId
|
||||
|
||||
Catch ex As Exception
|
||||
Return 0
|
||||
End Try
|
||||
End Function
|
||||
|
||||
|
||||
End Class
|
||||
|
||||
@ -21,6 +21,29 @@ Public Class UserModel
|
||||
Return oUser
|
||||
End Function
|
||||
|
||||
Public Function CheckUserLogin(pUser As User) As User
|
||||
Try
|
||||
Dim oSql = $"SELECT * FROM [dbo].[FNDD_LOGIN_USER_MODULE] ('{pUser.Username}', 'SIG_PMENV_CR', 1)"
|
||||
Dim oTable As DataTable = Database.GetDatatable(oSql)
|
||||
|
||||
If oTable?.Rows.Count = 0 Then
|
||||
Return pUser
|
||||
End If
|
||||
|
||||
Dim oRow = oTable.Rows.Item(0)
|
||||
Dim oHasAccess = oRow.ItemEx("MODULE_ACCESS", False)
|
||||
Dim oIsAdmin = oRow.ItemEx("IS_ADMIN", False)
|
||||
|
||||
pUser.HasAccess = oHasAccess
|
||||
pUser.IsAdmin = oIsAdmin
|
||||
|
||||
Return pUser
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return pUser
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function SelectUser() As User
|
||||
Try
|
||||
Dim oSql = $"SELECT * FROM [dbo].[TBDD_USER] WHERE GUID = {State.UserId}"
|
||||
@ -47,4 +70,15 @@ Public Class UserModel
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function SelectUserId() As Integer
|
||||
Try
|
||||
Dim oUserId As Integer = Database.GetScalarValue($"SELECT GUID FROM TBDD_USER WHERE USERNAME = '{Environment.UserName}'")
|
||||
Return oUserId
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return 0
|
||||
End Try
|
||||
End Function
|
||||
|
||||
End Class
|
||||
|
||||
@ -44,9 +44,7 @@ Public Class frmMain
|
||||
ConfigManager.Save()
|
||||
Application.Restart()
|
||||
Else
|
||||
FormHelper.ShowErrorMessage(New ApplicationException("No Database configured. Application will close!"), "Form Load")
|
||||
Application.Exit()
|
||||
|
||||
Throw New ApplicationException("No Database configured. Application will close!")
|
||||
End If
|
||||
End If
|
||||
|
||||
@ -61,24 +59,42 @@ Public Class frmMain
|
||||
.Database = Database
|
||||
}
|
||||
|
||||
If Database.DBInitialized = True Then
|
||||
Dim ConfigModel = New ConfigModel(State)
|
||||
State.DbConfig = ConfigModel.LoadConfiguration()
|
||||
State.UserId = ConfigModel.GetUserId()
|
||||
If Database.DBInitialized = False Then
|
||||
Throw New ApplicationException("Could not connect to the database. Application will close!")
|
||||
End If
|
||||
|
||||
Dim ConfigModel = New ConfigModel(State)
|
||||
State.DbConfig = ConfigModel.LoadConfiguration()
|
||||
|
||||
Dim oUserModel = New UserModel(State)
|
||||
State.UserId = oUserModel.SelectUserId()
|
||||
|
||||
Dim oUser = oUserModel.SelectUser()
|
||||
oUser = oUserModel.CheckUserLogin(oUser)
|
||||
|
||||
If oUser.HasAccess = False Then
|
||||
Throw New ApplicationException("User is not activated for this module. Please contact your administrator. Application will close!")
|
||||
End If
|
||||
|
||||
If Not String.IsNullOrEmpty(State.DbConfig.ExternalProgramName) Then
|
||||
Me.Text = State.DbConfig.ExternalProgramName
|
||||
Text = State.DbConfig.ExternalProgramName
|
||||
End If
|
||||
|
||||
Controller = New EnvelopeListController(State)
|
||||
|
||||
LoadEnvelopeData()
|
||||
|
||||
Catch ex As ApplicationException
|
||||
Logger.Error(ex)
|
||||
MsgBox(ex.Message, MsgBoxStyle.Critical, Text)
|
||||
Application.Exit()
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
End Try
|
||||
MsgBox($"Unexpected error: {ex.Message}", MsgBoxStyle.Critical, Text)
|
||||
Application.Exit()
|
||||
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Sub LoadEnvelopeData()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user