Answered by:
trying to modify a procedure, need help!

Question
-
User-307692219 posted
I'm trying to modify the following procedure so that new user accounts are created with two roles (roleid 1 and 4) by default. I know vbscript, but new to .net and can't figure out how to use the classes and methods.
Procedure that creates the new user and adds blank roles by default:
'******************************************************************************************************** 'Name: lnkAdd_Click 'Parameters: ' sender - The object calling the function, i.e. lnkAdd ' e - event arguments 'Returns: Nothing 'Purpose: Adds a user to the database. '******************************************************************************************************** Private Sub lnkAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkAdd.Click lnkAdd.Enabled = False Dim user As New orgz.User Dim roles As New System.Collections.Generic.List(Of orgz.Role) Dim map As New orgz.Map user.txtusername = user.getuseridbyusername() If (user.GetUserExistence() <= 0) Then If UCase(ConfigurationManager.AppSettings("authentication")) = "FORMS" Then user.txtusername = txtusername.Text user.txtpassword = txtpassword.Text Else Dim username As String = String.Empty username = user.getuseridbyusername() If username.Length < 1 Then Throw New Exception("Problem getting certificate for" & txtfname.Text & " " & txtlname.Text) End If user.txtusername = user.getuseridbyusername() user.txtpassword = "NOPASSWORDHERE" End If user.txtfirstname = orgz.Functions.scrubinput(txtfname.Text) user.txtlastname = orgz.Functions.scrubinput(txtlname.Text) user.txtrank = orgz.Functions.scrubinput(txtrank.Text) user.txtsquadron = orgz.Functions.scrubinput(txtsquadron.Text) user.txtoffice = orgz.Functions.scrubinput(txtoffice.Text) user.txtwing = orgz.Functions.scrubinput(txtwing.Text) user.txtinstallation = IIf(IsNothing(dpdinstallation.SelectedItem.Value), 0, dpdinstallation.SelectedItem.Value) user.txtemail = orgz.Functions.scrubinput(txtemail.Text) user.txtphone = orgz.Functions.scrubinput(txtphone.Text) user.defaultmap = map.GetDefaultMap() user.txtnotes = "" user.bolactivated = 0 user.dtepassexpire = DateAdd(DateInterval.Day, 365, Now()) user.roles = roles user.dtedateactivated = "1/1/1900" user.dtedatecreated = Now() user.adduser() lblresult.Text = "You have been successfully registered. You will recieve an email at your specified e-mail address when your account has been activated." sendmail() Else pnlresult.Visible = True pnlPreFill.Visible = False pnlform.Visible = False lblresult.Text = "" lblresult.Text = "You appear to already be registered in the system. If you are having trouble logging in, please contact your GIO." End If lnkAdd.Enabled = True pnlform.Visible = False pnlresult.Visible = True user = Nothing map = Nothing roles = Nothing End Sub #End Region
User class referenced in above procedure:Imports system.Data.OracleClient Imports System.Security.Cryptography Imports System.Text Imports System.DirectoryServices Namespace orgz Public Class User #Region " Constructors " '******************************************************************************************************** 'Name: New 'Parameters: None 'Returns: Nothing 'Purpose: Default Constructor '******************************************************************************************************** Public Sub New() End Sub '******************************************************************************************************** 'Name: New 'Parameters: ' userid - the userid (primary key) of the user ' username - the name of the user 'Returns: Nothing 'Purpose: populates the object with the suppleid data, used mainly to populate dropdownlists '******************************************************************************************************** Public Sub New(ByVal userid As Integer, ByVal username As String, ByVal txtemail As String) Me.userid = userid Me.txtusername = username Me.txtemail = txtemail End Sub '******************************************************************************************************** 'Name: New 'Parameters: ' userid - the userid (primary key) of the user ' username - the username of the user ' password - NOT USED ' email - the email address of the user ' firstname - the users firstname ' lastname - the users last name ' rank - the users rank ' phone - the users DSN phone ' squadron - the users squadron ' office - the users office symbol ' notes - notes about the user ' datecreated - the date the user was created in the system ' dateactivated - the date the user was activated ' bolactiveated - whether or not the user has been activated ' passexpire - date the password expires ' installation - which installation the user is at ' wing - which wing the user is with ' defaultmap - which map is the users default map ' roles - the users security roles ' lastlogin - the date of the users last login ' numlogin - the number of times the user has logged in 'Returns: Nothing 'Purpose: populates the object with the suppleid data, used mainly to populate dropdownlists '******************************************************************************************************** Public Sub New(ByVal userid As Integer, ByVal username As String, ByVal email As String, ByVal firstname As String, ByVal lastname As String, ByVal rank As String, ByVal phone As String, ByVal squadron As String, ByVal office As String, ByVal flight As String, ByVal notes As String, ByVal datecreated As Date, ByVal dateactivated As Date, ByVal activated As Boolean, ByVal passexpire As Date, ByVal installation As String, ByVal wing As String, ByVal roles As System.Collections.Generic.List(Of orgz.Role), ByVal defaultmap As orgz.Map, ByVal dtelastlogin As Date) Me.userid = userid Me.txtemail = email Me.txtusername = username Me.txtfirstname = firstname Me.txtlastname = lastname Me.txtrank = rank Me.txtphone = phone Me.txtsquadron = squadron Me.txtoffice = office Me.txtnotes = notes Me.dtedatecreated = datecreated Me.dtedateactivated = dateactivated Me.bolactivated = activated Me.dtepassexpire = passexpire Me.txtinstallation = installation Me.txtwing = wing Me.roles = roles Me.defaultmap = defaultmap Me.dtelastlogin = dtelastlogin End Sub #End Region #Region " Declarations " '******************************************************************************************************** 'Purpose: Private variables exposed as public properties. '******************************************************************************************************** Dim _userid As Integer Dim _txtemail As String Dim _txtusername As String Dim _txtpassword As String Dim _txtfirstname As String Dim _txtlastname As String Dim _txtrank As String Dim _txtphone As String Dim _txtsquadron As String Dim _txtoffice As String Dim _txtnotes As String Dim _dtedatecreated As Date Dim _dtedateactivated As Date Dim _bolactivated As Boolean Dim _dtepassexpire As Date Dim _txtinstallation As Integer Dim _txtwing As String Dim _defaultmap As orgz.Map Dim _roles As System.Collections.Generic.List(Of orgz.Role) Dim _lastlogin As Date Dim _numlogin As Long #End Region #Region " Properties " '******************************************************************************************************** 'Name: userid 'Purpose: the userid (primary key) of the user '******************************************************************************************************** Public Property userid() As Integer Get Return _userid End Get Set(ByVal Value As Integer) _userid = Value End Set End Property '******************************************************************************************************** 'Name: txtemail 'Purpose: the email address of the user '******************************************************************************************************** Public Property txtemail() As String Get Return _txtemail End Get Set(ByVal Value As String) _txtemail = Value End Set End Property '******************************************************************************************************** 'Name: txtusername 'Purpose: the username of the user '******************************************************************************************************** Public Property txtusername() As String Get Return _txtusername End Get Set(ByVal Value As String) _txtusername = Value End Set End Property '******************************************************************************************************** 'Name: txtpassword 'Purpose: NOT USED '******************************************************************************************************** Public Property txtpassword() As String Get Return _txtpassword End Get Set(ByVal Value As String) _txtpassword = Value End Set End Property '******************************************************************************************************** 'Name: txtfirstname 'Purpose: the users firstname '******************************************************************************************************** Public Property txtfirstname() As String Get Return _txtfirstname End Get Set(ByVal Value As String) _txtfirstname = Value End Set End Property '******************************************************************************************************** 'Name: txtlastname 'Purpose: the users last name '******************************************************************************************************** Public Property txtlastname() As String Get Return _txtlastname End Get Set(ByVal Value As String) _txtlastname = Value End Set End Property '******************************************************************************************************** 'Name: txtrank 'Purpose: the users rank '******************************************************************************************************** Public Property txtrank() As String Get Return _txtrank End Get Set(ByVal Value As String) _txtrank = Value End Set End Property '******************************************************************************************************** 'Name: txtphone 'Purpose: the users DSN phone '******************************************************************************************************** Public Property txtphone() As String Get Return _txtphone End Get Set(ByVal Value As String) _txtphone = Value End Set End Property '******************************************************************************************************** 'Name: txtsquadron 'Purpose: the users squadron '******************************************************************************************************** Public Property txtsquadron() As String Get Return _txtsquadron End Get Set(ByVal Value As String) _txtsquadron = Value End Set End Property '******************************************************************************************************** 'Name: txtoffice 'Purpose: the users office symbol '******************************************************************************************************** Public Property txtoffice() As String Get Return _txtoffice End Get Set(ByVal Value As String) _txtoffice = Value End Set End Property '******************************************************************************************************** 'Name: txtnotes 'Purpose: notes about the user '******************************************************************************************************** Public Property txtnotes() As String Get Return _txtnotes End Get Set(ByVal Value As String) _txtnotes = Value End Set End Property '******************************************************************************************************** 'Name: dtedatecreated 'Purpose: the date the user was created in the system '******************************************************************************************************** Public Property dtedatecreated() As Date Get Return _dtedatecreated End Get Set(ByVal Value As Date) _dtedatecreated = Value End Set End Property '******************************************************************************************************** 'Name: dtedateactivated 'Purpose: the date the user was activated '******************************************************************************************************** Public Property dtedateactivated() As Date Get Return _dtedatecreated End Get Set(ByVal Value As Date) _dtedateactivated = Value End Set End Property '******************************************************************************************************** 'Name: bolactivated 'Purpose: whether or not the user has been activated '******************************************************************************************************** Public Property bolactivated() As Boolean Get Return _bolactivated End Get Set(ByVal Value As Boolean) _bolactivated = Value End Set End Property '******************************************************************************************************** 'Name: dtepassexpire 'Purpose: date the password expires '******************************************************************************************************** Public Property dtepassexpire() As Date Get Return _dtepassexpire End Get Set(ByVal Value As Date) _dtepassexpire = Value End Set End Property '******************************************************************************************************** 'Name: txtinstallation 'Purpose: which installation the user is at '******************************************************************************************************** Public Property txtinstallation() As Integer Get Return _txtinstallation End Get Set(ByVal Value As Integer) _txtinstallation = Value End Set End Property '******************************************************************************************************** 'Name: txtwing 'Purpose: which wing the user is with '******************************************************************************************************** Public Property txtwing() As String Get Return _txtwing End Get Set(ByVal Value As String) _txtwing = Value End Set End Property '******************************************************************************************************** 'Name: roles 'Purpose: the users security roles '******************************************************************************************************** Public Property roles() As System.Collections.Generic.List(Of orgz.Role) Get Return _roles End Get Set(ByVal Value As System.Collections.Generic.List(Of orgz.Role)) _roles = Value End Set End Property '******************************************************************************************************** 'Name: defaultmap 'Purpose: which map is the users default map '******************************************************************************************************** Public Property defaultmap() As orgz.Map Get Return _defaultmap End Get Set(ByVal Value As orgz.Map) _defaultmap = Value End Set End Property '******************************************************************************************************** 'Name: FullName 'Purpose: the fullname of the user '******************************************************************************************************** Public ReadOnly Property FullName() As String Get Return String.Format("{0},{1}", _txtlastname, _txtfirstname) End Get End Property '******************************************************************************************************** 'Name: ProperName 'Purpose: the fullname of the user '******************************************************************************************************** Public ReadOnly Property ProperName() As String Get Return String.Format("{0} {1}", _txtfirstname, _txtlastname) End Get End Property '******************************************************************************************************** 'Name: dtelastlogin 'Purpose: the date of the users last login '******************************************************************************************************** Public Property dtelastlogin() As Date Get Return _lastlogin End Get Set(ByVal Value As Date) _lastlogin = Value End Set End Property '******************************************************************************************************** 'Name: numlogin 'Purpose: the number of times the user has logged in '******************************************************************************************************** Public Property numlogin() As Long Get Return _numlogin End Get Set(ByVal Value As Long) _numlogin = Value End Set End Property #End Region #Region " Action Methods " '******************************************************************************************************** 'Name: getuser 'Parameters: ' userid - the userid of the user that you want to retrieve 'Returns: a populated user object 'Purpose: Returns a user object populated with the data of the desired user. '******************************************************************************************************** Public Function getuser(ByVal userid As Integer) As User Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand Dim preader As OracleDataReader Dim u As New orgz.User Dim map As New orgz.Map cn.Open() With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.USER.GETUSER" .Parameters.Add("P_USERID", OracleType.Int16).Value = userid .Parameters.Add("P_RESULT", OracleType.Cursor).Direction = ParameterDirection.Output preader = .ExecuteReader(CommandBehavior.CloseConnection) End With While preader.Read() u = FillUser(preader) End While preader.Close() preader.Dispose() preader = Nothing cmd.Dispose() cn.Dispose() map = Nothing cmd = Nothing cn = Nothing Return u End Function Public Shared Function GetMapBase(ByVal str As String) As String Return IIf(InStr(str, "www.my.af.mil") > 0, ConfigurationManager.AppSettings("portalmapbase"), ConfigurationManager.AppSettings("mapbase")) End Function Public Shared Function GetLinkBase() As String Return IIf(HttpRuntime.AppDomainAppVirtualPath = "/", HttpRuntime.AppDomainAppVirtualPath, String.Format("{0}/", HttpRuntime.AppDomainAppVirtualPath)) End Function Public Shared Function GetHyperLinkBase(ByVal str As String) As String Return IIf(InStr(str, "www.my.af.mil") > 0, ConfigurationManager.AppSettings("portallinkbase"), ConfigurationManager.AppSettings("linkbase")) End Function '******************************************************************************************************** 'Name: GetUserByMap 'Parameters: ' mapid - the mapid of the map whose users you want 'Returns: a collection of user objects 'Purpose: Returns all users who have the given map as their default map. '******************************************************************************************************** Public Function GetUserByMap(ByVal mapid As Integer) As System.Collections.Generic.List(Of User) Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand Dim preader As OracleDataReader Dim u As New System.Collections.Generic.List(Of orgz.User) Dim map As New orgz.Map cn.Open() With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.USER.GETUSERBYMAP" .Parameters.Add("P_MAPID", OracleType.VarChar).Value = mapid .Parameters.Add("P_RESULT", OracleType.Cursor).Direction = ParameterDirection.Output preader = .ExecuteReader(CommandBehavior.CloseConnection) End With While preader.Read() u.Add(FillUser(preader)) End While preader.Close() preader.Dispose() preader = Nothing cmd.Dispose() cn.Dispose() map = Nothing cmd = Nothing cn = Nothing Return u End Function '******************************************************************************************************** 'Name: getuserbyletter 'Parameters: ' letter - the letter that you want to filter the returned list by ' sortfield - the field you want the returned list sorted on ' sortdirection - the direction, ASC or DESC, that you want the results sorted 'Returns: a sorted and filtered collection of user objects. 'Purpose: Returns all users whose lastnames start with the supplied letter. '******************************************************************************************************** Public Function getuserbyletter(ByVal letter As String, ByVal sortfield As String, ByVal sortdirection As String) As System.Collections.Generic.List(Of User) Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand Dim preader As OracleDataReader Dim u As New System.Collections.Generic.List(Of orgz.User) Dim map As New orgz.Map cn.Open() With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.USER.GETUSERBYLETTER" .Parameters.Add("P_RESULT", OracleType.Cursor).Direction = ParameterDirection.Output .Parameters.Add("P_LETTER", OracleType.VarChar).Value = letter .Parameters.Add("P_SORTFIELD", OracleType.VarChar).Value = sortfield .Parameters.Add("P_SORTDIRECTION", OracleType.VarChar).Value = sortdirection preader = .ExecuteReader(CommandBehavior.CloseConnection) End With While preader.Read() u.Add(FillUser(preader)) End While preader.Close() preader.Dispose() preader = Nothing cmd.Dispose() cn.Dispose() map = Nothing cmd = Nothing cn = Nothing Return u End Function '******************************************************************************************************** 'Name: updateuser 'Parameters: None 'Returns: Nothing 'Purpose: Updates a user in the database. '******************************************************************************************************** Public Sub updateuser() Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.USER.UPDATEUSER" .Parameters.Add("P_USERID", OracleType.Int32).Value = Me.userid .Parameters.Add("P_TXTUSERNAME", OracleType.VarChar, 50).Value = Me.txtusername .Parameters.Add("P_TXTEMAIL", OracleType.VarChar, 50).Value = Me.txtemail .Parameters.Add("P_TXTFIRSTNAME", OracleType.VarChar, 50).Value = Me.txtfirstname .Parameters.Add("P_TXTLASTNAME", OracleType.VarChar, 50).Value = Me.txtlastname .Parameters.Add("P_TXTRANK", OracleType.VarChar, 25).Value = Me.txtrank .Parameters.Add("P_TXTPHONE", OracleType.VarChar, 25).Value = Me.txtphone .Parameters.Add("P_TXTSQUADRON", OracleType.VarChar, 25).Value = Me.txtsquadron .Parameters.Add("P_TXTOFFICE", OracleType.VarChar, 50).Value = Me.txtoffice .Parameters.Add("P_TXTNOTES", OracleType.VarChar, 255).Value = Me.txtnotes .Parameters.Add("P_DTEDATEACTIVATED", OracleType.DateTime).Value = Me.dtedateactivated .Parameters.Add("P_BOLACTIVATED", OracleType.Int32).Value = CInt(Me.bolactivated) .Parameters.Add("P_TXTWING", OracleType.VarChar, 50).Value = Me.txtwing .Parameters.Add("P_TXTINSTALLATION", OracleType.Int32).Value = Me.txtinstallation .Parameters.Add("P_DTELASTLOGIN", OracleType.DateTime).Value = Me.dtelastlogin cn.Open() .ExecuteNonQuery() cn.Close() AddUserRoles(Me.userid, Me.roles) End With cmd.Dispose() cn.Dispose() cmd = Nothing cn = Nothing End Sub '******************************************************************************************************** 'Name: updateusername 'Parameters: None 'Returns: Nothing 'Purpose: Updates a user in the database. '******************************************************************************************************** Public Sub updateusername(ByVal username As String, ByVal userid As Integer) Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.USER.UPDATEUSERNAME" .Parameters.Add("P_USERNAME", OracleType.VarChar, 50).Value = username .Parameters.Add("P_USERID", OracleType.Int32).Value = userid cn.Open() .ExecuteNonQuery() cn.Close() End With cmd.Dispose() cn.Dispose() cmd = Nothing cn = Nothing End Sub '******************************************************************************************************** 'Name: adduser 'Parameters: None 'Returns: Nothing 'Purpose: Adds a user to the database. '******************************************************************************************************** Public Sub adduser() Dim cn As New OracleConnection cn.ConnectionString = ConfigurationManager.AppSettings("connectionstring") Dim cmd As New OracleCommand With cmd .Connection = cn .CommandText = "GPUSER.USER.ADDUSER" .CommandType = CommandType.StoredProcedure .Parameters.Add("p_userid", OracleType.VarChar, 50).Direction = ParameterDirection.Output .Parameters.Add("p_txtusername", OracleType.VarChar, 50).Value = Me.txtusername .Parameters.Add("p_txtemail", OracleType.VarChar, 50).Value = Me.txtemail .Parameters.Add("p_txtpassword", OracleType.Raw, 16).Value = hashpassword(Me.txtpassword) .Parameters.Add("p_txtfirstname", OracleType.VarChar, 50).Value = Me.txtfirstname .Parameters.Add("p_txtlastname", OracleType.VarChar, 50).Value = Me.txtlastname .Parameters.Add("p_txtrank", OracleType.VarChar, 50).Value = Me.txtrank .Parameters.Add("p_txtphone", OracleType.VarChar, 50).Value = Me.txtphone .Parameters.Add("p_txtsquadron", OracleType.VarChar, 50).Value = Me.txtsquadron .Parameters.Add("p_txtoffice", OracleType.VarChar, 50).Value = Me.txtoffice .Parameters.Add("p_txtnotes", OracleType.VarChar, 50).Value = Me.txtnotes .Parameters.Add("p_dtedatecreated", OracleType.DateTime).Value = Me.dtedatecreated .Parameters.Add("p_dtedateactivated", OracleType.DateTime).Value = Me.dtedateactivated .Parameters.Add("p_bolactivated", OracleType.Int16, 1).Value = Me.bolactivated .Parameters.Add("p_dtepassexpire", OracleType.DateTime, 50).Value = Me.dtepassexpire .Parameters.Add("p_txtinstallation", OracleType.VarChar, 50).Value = Me.txtinstallation .Parameters.Add("p_txtwing", OracleType.VarChar, 50).Value = Me.txtwing .Parameters.Add("p_dtelastlogin", OracleType.DateTime).Value = "1-JAN-1900" cn.Open() .ExecuteNonQuery() cn.Close() End With AddUserRoles(Me.userid, Me.roles) cmd.Dispose() cn.Dispose() cmd = Nothing cn = Nothing End Sub '******************************************************************************************************** 'Name: deleteuser 'Parameters: ' userid - the userid of the user you want to delete 'Returns: Nothing 'Purpose: Deletes a user from the database. '******************************************************************************************************** Public Sub deleteuser(ByVal userid As Integer) Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.USER.DELETEUSER" .Parameters.Add("P_USERID", OracleType.Int16).Value = userid cn.Open() .ExecuteNonQuery() cn.Close() End With cmd.Dispose() cn.Dispose() cmd = Nothing cn = Nothing End Sub '******************************************************************************************************** 'Name: getuserbyusername 'Parameters: ' username - the username of the desired user 'Returns: returns a populated user object 'Purpose: Returns a populated user object populated with data from the desired user. '******************************************************************************************************** Public Function getuserbyusername(ByVal username As String) As User Dim cn As New System.Data.OracleClient.OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleClient.OracleCommand Dim preader As OracleClient.OracleDataReader Dim u As New orgz.User Dim map As New orgz.Map cn.Open() With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.USER.GETUSERBYUSERNAME" .Parameters.Add("P_USERNAME", OracleClient.OracleType.VarChar).Value = UCase(username) .Parameters.Add("P_RESULT", OracleClient.OracleType.Cursor).Direction = ParameterDirection.Output preader = .ExecuteReader(CommandBehavior.CloseConnection) End With While preader.Read() u = FillUser(preader) End While If Len(u.txtusername) < 1 Then u = Nothing ElseIf Not (CBool(u.bolactivated)) Then u = Nothing End If preader.Close() preader.Dispose() preader = Nothing cmd.Dispose() cn.Dispose() cmd = Nothing cn = Nothing map = Nothing Return u End Function '******************************************************************************************************** 'Name: getuseridbyusername 'Parameters: ' username - the full httpcontext username of the currently authenticated user 'Returns: the parsed username 'Purpose: Parses out the username from the full httpcontext username '******************************************************************************************************** Public Function getuseridbyusername() As String Dim s As String = String.Empty If UCase(ConfigurationManager.AppSettings("authentication")) = "DOMAIN" Then s = System.Web.HttpContext.Current.Request.ServerVariables("LOGON_USER") s = s.Substring(s.IndexOf("\") + 1) ElseIf UCase(ConfigurationManager.AppSettings("authentication")) = "PORTAL" Then s = System.Web.HttpContext.Current.Request.ServerVariables("HTTP_CERTIFICATE_SUBJECT") If s = String.Empty Then s = System.Web.HttpContext.Current.Request.ServerVariables("CERT_SUBJECT") If UCase(s) = "WWW.MY.AF.MIL" Then s = String.Empty End If End If s = s.Substring(s.IndexOf("CN=") + 3) ElseIf UCase(ConfigurationManager.AppSettings("authentication")) = "FORMS" Then Try s = HttpContext.Current.User.Identity.Name Catch s = "" End Try ElseIf UCase(ConfigurationManager.AppSettings("authentication")) = "CAC" Then s = System.Web.HttpContext.Current.Request.ServerVariables("CERT_SUBJECT") s = s.Substring(s.IndexOf("CN=") + 3) 's = "ODOM.DAVID.ZACHARY.1277156322" If s.Length < 1 Or UCase(s) = "WWW.MY.AF.MIL" Then s = "" End If End If Return s End Function '******************************************************************************************************** 'Name: GetAllUsers 'Parameters: None 'Returns: a collection of user objects 'Purpose: Returns all users '******************************************************************************************************** Public Function GetAllUsers() As System.Collections.Generic.List(Of orgz.User) Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand Dim dr As OracleDataReader Dim users As New System.Collections.Generic.List(Of orgz.User) With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.USER.GETALLUSERS" .Parameters.Add("P_RESULT", OracleType.Cursor).Direction = ParameterDirection.Output cn.Open() dr = .ExecuteReader(CommandBehavior.CloseConnection) While dr.Read() users.Add(FillUser(dr)) End While dr.Close() End With dr.Dispose() dr = Nothing cmd.Dispose() cmd = Nothing cn.Dispose() cn = Nothing Return users users = Nothing End Function '******************************************************************************************************** 'Name: GetUsersByRole 'Parameters: ' roleid - the roleid of the desired uses 'Returns: a collection of user objects 'Purpose: Returns all users who are in a supplied role '******************************************************************************************************** Public Function GetUsersByRole(ByVal roleid As Integer) As System.Collections.Generic.List(Of orgz.User) Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand Dim dr As OracleDataReader Dim users As New System.Collections.Generic.List(Of orgz.User) With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.USER.GETUSERSBYROLE" .Parameters.Add("P_RESULT", OracleType.Cursor).Direction = ParameterDirection.Output .Parameters.Add("P_ROLEID", OracleType.Int32).Value = roleid cn.Open() dr = .ExecuteReader(CommandBehavior.CloseConnection) While dr.Read() users.Add(FillUser(dr)) End While dr.Close() End With dr.Dispose() dr = Nothing cmd.Dispose() cmd = Nothing cn.Dispose() cn = Nothing Return users users = Nothing End Function '******************************************************************************************************** 'Name: GetUsersNotInRole 'Parameters: ' roleid - the roleid of the desired uses 'Returns: a collection of user objects 'Purpose: Returns all users who are not in a supplied role '******************************************************************************************************** Public Function GetUsersNotInROle(ByVal roleid As Integer) As System.Collections.Generic.List(Of orgz.User) Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand Dim dr As OracleDataReader Dim users As New System.Collections.Generic.List(Of orgz.User) With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.USER.GETUSERSNOTINROLE" .Parameters.Add("P_RESULT", OracleType.Cursor).Direction = ParameterDirection.Output .Parameters.Add("P_ROLEID", OracleType.Int32).Value = roleid cn.Open() dr = .ExecuteReader(CommandBehavior.CloseConnection) While dr.Read() users.Add(FillUser(dr)) End While dr.Close() End With dr.Dispose() dr = Nothing cmd.Dispose() cmd = Nothing cn.Dispose() cn = Nothing Return users users = Nothing End Function '******************************************************************************************************** 'Name: GetUserExistence 'Parameters: None 'Returns: the recordcount matching the criteria supplied 'Purpose: If username is found, recordcount will be greater than 0 '******************************************************************************************************** Public Function GetUserExistence() As Integer Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand Dim count As Integer count = 0 With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.USER.GETUSEREXISTENCE" .Parameters.Add("p_username", OracleType.VarChar).Value = getuseridbyusername() .Parameters.Add("p_count", OracleType.Int32).Direction = ParameterDirection.Output cn.Open() .ExecuteNonQuery() count = .Parameters("p_count").Value End With cmd.Dispose() cmd = Nothing cn.Close() cn.Dispose() cn = Nothing Return count End Function #End Region #Region " Auxillary Methods " '******************************************************************************************************** 'Name: AddUserRoles 'Parameters: ' userid - the userid of the user you wish to add the roles to ' roles - the roles you wish to add to the user 'Returns: Nothing 'Purpose: Adds the supplied roles to the supplied user. '******************************************************************************************************** Private Sub AddUserRoles(ByVal userid As Integer, ByVal roles As System.Collections.Generic.List(Of orgz.Role)) Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand Dim role As orgz.Role cn.Open() With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.ROLES.DELETEUSERROLES" .Parameters.Add("P_USERID", OracleType.Int32).Value = userid .ExecuteNonQuery() .Parameters.Clear() .CommandText = "GPUSER.ROLES.ADDUSERROLES" For Each role In roles .Parameters.Clear() .Parameters.Add("P_USERID", OracleType.Int16).Value = userid .Parameters.Add("P_GROUPID", OracleType.Int16).Value = role.groupid .ExecuteNonQuery() Next End With cn.Close() cmd.Dispose() cn.Dispose() cmd = Nothing cn = Nothing End Sub '******************************************************************************************************** 'Name: hashpassword 'Parameters: ' str - the string to be encoded 'Returns: a bytearray of the hashcode 'Purpose: hashes information '******************************************************************************************************** Public Function AuthenticateUser(ByVal username As String, ByVal password As String) As Boolean Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand Dim user As New orgz.User Dim dr As OracleDataReader Dim result As Boolean cn.Open() user = Me.getuserbyusername(username) If Not (user Is Nothing) Then With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.USER.VALIDATEUSER" .Parameters.Clear() .Parameters.Add("P_USERNAME", OracleType.VarChar).Value = username .Parameters.Add("P_PASSWORD", OracleType.Raw).Value = hashpassword(password) .Parameters.Add("P_RESULT", OracleType.Cursor).Direction = ParameterDirection.Output dr = .ExecuteReader(CommandBehavior.CloseConnection) If dr.Read Then result = True Else result = False End If End With Else result = False End If cn.Dispose() cn = Nothing cmd.Dispose() cmd = Nothing user = Nothing Return result End Function '******************************************************************************************************** 'Name: GetUserMapRoles 'Parameters: ' userid = the ID of the user ' mapid = the ID of the map 'Returns: a collection of role objects 'Purpose: determines the role overlap of a map and a user '******************************************************************************************************** Public Function GetUserMapRoles(ByVal userid As Integer, ByVal mapid As Integer) As System.Collections.Generic.List(Of orgz.Role) Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand Dim dr As OracleDataReader Dim roles As New System.Collections.Generic.List(Of orgz.Role) cn.Open() With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.USER.GETUSERMAPROLES" .Parameters.Clear() .Parameters.Add("P_USERID", OracleType.Int16).Value = userid .Parameters.Add("P_MAPID", OracleType.Int16).Value = mapid .Parameters.Add("P_RESULT", OracleType.Cursor).Direction = ParameterDirection.Output dr = .ExecuteReader(CommandBehavior.CloseConnection) End With While dr.Read roles.Add(New Role(dr.Item("groupid"), dr.Item("groupname"), dr.Item("groupdescription"), dr.Item("groupdefault"))) End While cn.Dispose() cn = Nothing cmd.Dispose() cmd = Nothing Return roles End Function '******************************************************************************************************** 'Name: hashpassword 'Parameters: ' str - the string to be encoded 'Returns: a bytearray of the hashcode 'Purpose: hashes information '******************************************************************************************************** Private Function hashpassword(ByVal str As String) As Byte() Dim md5hasher As New MD5CryptoServiceProvider Dim encoder As New UTF8Encoding Dim hashedDataBytes As Byte() hashedDataBytes = md5hasher.ComputeHash(encoder.GetBytes(str)) md5hasher = Nothing encoder = Nothing Return hashedDataBytes End Function '******************************************************************************************************** 'Name: FillUser 'Parameters: ' dr - the datarecord to fill the user object from 'Returns: a populated user object 'Purpose: Populates a user obect from the supplied datarecord. '******************************************************************************************************** Private Function FillUser(ByRef dr As IDataRecord) As orgz.User Dim user As New orgz.User Dim map As New orgz.Map Dim roles As New System.Collections.Generic.List(Of orgz.Role) user.userid = dr.Item("userid") user.txtemail = IIf(IsDBNull(dr.Item("txtemail")), "", dr.Item("txtemail")) user.txtusername = IIf(IsDBNull(dr.Item("txtusername")), "", dr.Item("txtusername")) user.txtfirstname = IIf(IsDBNull(dr.Item("txtfirstname")), "", dr.Item("txtfirstname")) user.txtlastname = IIf(IsDBNull(dr.Item("txtlastname")), "", dr.Item("txtlastname")) user.txtrank = IIf(IsDBNull(dr.Item("txtrank")), "", dr.Item("txtrank")) user.txtphone = IIf(IsDBNull(dr.Item("txtphone")), "", dr.Item("txtphone")) user.txtsquadron = IIf(IsDBNull(dr.Item("txtsquadron")), "", dr.Item("txtsquadron")) user.txtoffice = IIf(IsDBNull(dr.Item("txtoffice")), "", dr.Item("txtoffice")) user.txtnotes = IIf(IsDBNull(dr.Item("txtnotes")), "", dr.Item("txtnotes")) user.dtedatecreated = IIf(IsDBNull(dr.Item("dtedatecreated")), "1/1/1900", dr.Item("dtedatecreated")) user.dtedateactivated = IIf(IsDBNull(dr.Item("dtedateactivated")), "1/1/1900", dr.Item("dtedateactivated")) user.bolactivated = IIf(IsDBNull(dr.Item("bolactivated")), False, CBool(dr.Item("bolactivated"))) user.dtepassexpire = IIf(IsDBNull(dr.Item("dtepassexpire")), "1/1/1900", dr.Item("dtepassexpire")) user.txtinstallation = IIf(IsDBNull(dr.Item("txtinstallation")), "0", dr.Item("txtinstallation")) user.txtwing = IIf(IsDBNull(dr.Item("txtwing")), "", dr.Item("txtwing")) user.roles = roles user.defaultmap = map user.dtelastlogin = IIf(IsDBNull(dr.Item("dtelastlogin")), "1-1-1900", dr.Item("dtelastlogin")) Try user.numlogin = dr.Item("numlogin") Catch ex As Exception user.numlogin = 0 End Try map = Nothing roles = Nothing Return user user = Nothing End Function '******************************************************************************************************** 'Name: UpdateLastLogin 'Parameters: None 'Returns: Nothing 'Purpose: Updates the last login data and the number of logins for the user. '******************************************************************************************************** Public Sub UpdateLastLogin() Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.USER.UPDATELASTLOGIN" .Parameters.Add("P_USERID", OracleType.Int32).Value = Me.userid .Parameters.Add("P_LASTLOGIN", OracleType.DateTime).Value = Me.dtelastlogin cn.Open() .ExecuteNonQuery() .Parameters.Clear() .CommandText = "GPUSER.LOGINS.UPDATELOGINS" .ExecuteNonQuery() cn.Close() End With cmd.Dispose() cn.Dispose() cmd = Nothing cn = Nothing End Sub '******************************************************************************************************** 'Name: FillUserRoles 'Parameters: None 'Returns: Nothing 'Purpose: populates the roles property for the current user. '******************************************************************************************************** Public Sub FillUserRoles() Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand Dim dr As OracleDataReader Dim roles As New System.Collections.Generic.List(Of orgz.Role) Dim role As New orgz.Role With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.USER.GETUSERROLES" .Parameters.Add("p_userid", OracleType.Int16).Value = Me.userid .Parameters.Add("p_result", OracleType.Cursor).Direction = ParameterDirection.Output cn.Open() dr = .ExecuteReader(CommandBehavior.CloseConnection) While dr.Read() roles.Add(role.fillrole(dr)) End While dr.Close() End With role = Nothing Me.roles = roles roles = Nothing cmd.Dispose() cmd = Nothing dr.Dispose() dr = Nothing cn.Close() cn.Dispose() cn = Nothing End Sub '******************************************************************************************************** 'Name: FillUserMap 'Parameters: None 'Returns: Nothing 'Purpose: fills the defaultmap property for the current user. '******************************************************************************************************** Public Sub FillUserMap() Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand Dim map As New orgz.Map Dim mapid As Integer With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.USER.GETUSERMAP" .Parameters.Add("p_userid", OracleType.Int16).Value = Me.userid .Parameters.Add("p_result", OracleType.Cursor).Direction = ParameterDirection.Output cn.Open() mapid = .ExecuteScalar If mapid <> 0 Then Me.defaultmap = map.getmap(mapid) Else Me.defaultmap = Nothing End If End With map = Nothing cmd.Dispose() cmd = Nothing cn.Close() cn.Dispose() cn = Nothing End Sub '******************************************************************************************************** 'Name: GetUsersFromListBox 'Parameters: ' DPD - The ListBox containing the user information 'Returns: A orgz.Users object containing the user information in the supplied ListBox 'Purpose: Returns a orgz.Users object containing the user information contained in the supplied ListBox '******************************************************************************************************** Public Shared Function GetUsersFromListBox(ByVal DPD As ListBox) As System.Collections.Generic.List(Of orgz.User) Dim users As New System.Collections.Generic.List(Of orgz.User) Dim item As New ListItem For Each item In DPD.Items users.Add(New User(item.Value, item.Text, "")) Next Return users users = Nothing End Function #End Region End Class End Namespace
Orgz class:Imports System.Security.Principal Namespace orgz Public Class orgzUser Implements System.Security.Principal.IPrincipal '******************************************************************************************************** 'Purpose: Special user class that extends the IPrincipal object to allow for our custom role interface. '******************************************************************************************************** Private _identity As IIdentity Private _roles() As String Public ReadOnly Property Identity() As System.Security.Principal.IIdentity Implements System.Security.Principal.IPrincipal.Identity Get Return _identity End Get End Property Public Sub New(ByVal identity As IIdentity, ByVal roles() As String) _identity = identity _roles = roles roles.CopyTo(_roles, 0) Array.Sort(_roles) End Sub Public Function IsInRole(ByVal role As String) As Boolean Implements System.Security.Principal.IPrincipal.IsInRole Return (IIf(Array.BinarySearch(_roles, role) >= 0, True, False)) End Function End Class End Namespace
Roles class. I think I need to use the GetRoles method from this class, but not sure how to implement it:Imports System.Data.OracleClient Namespace orgz Public Class Role #Region " Constructors " '******************************************************************************************************** 'Name: New 'Parameters: None 'Returns: Nothing 'Purpose: Default Constructor '******************************************************************************************************** Public Sub New() End Sub '******************************************************************************************************** 'Name: New 'Parameters: ' groupid - the groupid (primary key) of the role ' groupname - the name of the role ' groupdescription - a description of the role ' groupdefault - is the group the default group 'Returns: Nothing 'Purpose: Populates the object with the supplied values. '******************************************************************************************************** Public Sub New(ByVal groupid As Integer, ByVal groupname As String, ByVal groupdescription As String, ByVal groupdefault As Boolean) Me.groupid = groupid Me.groupname = groupname Me.groupdescription = groupdescription Me.groupdefault = groupdefault End Sub #End Region #Region " Declarations " '******************************************************************************************************** 'Purpose: Private variables exposed as public properties. '******************************************************************************************************** Private _groupid As Integer Private _groupname As String Private _groupdescription As String Private _groupdefault As Boolean #End Region #Region " Properties " '******************************************************************************************************** 'Name: groupid 'Purpose: the groupid (primary key) of the role '******************************************************************************************************** Public Property groupid() As Integer Get Return _groupid End Get Set(ByVal Value As Integer) _groupid = Value End Set End Property '******************************************************************************************************** 'Name: groupname 'Purpose: the name of the role '******************************************************************************************************** Public Property groupname() As String Get Return _groupname End Get Set(ByVal Value As String) _groupname = Value End Set End Property '******************************************************************************************************** 'Name: groupdescription 'Purpose: a description of the role '******************************************************************************************************** Public Property groupdescription() As String Get Return _groupdescription End Get Set(ByVal Value As String) _groupdescription = Value End Set End Property '******************************************************************************************************** 'Name: groupdefault 'Purpose: is the group the default group '******************************************************************************************************** Public Property groupdefault() As Boolean Get Return _groupdefault End Get Set(ByVal Value As Boolean) _groupdefault = Value End Set End Property #End Region #Region " Action Methods " '******************************************************************************************************** 'Name: getallroles 'Parameters: ' rolelist - the roles collection to filter by 'Returns: a collection of role objects 'Purpose: Returns the roles not matching the supplied role list. '******************************************************************************************************** Public Shared Function getallroles(ByVal roles As System.Collections.Generic.List(Of Role)) As System.Collections.Generic.List(Of Role) Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand Dim returnroles As New System.Collections.Generic.List(Of orgz.Role) Dim role As orgz.Role Dim reader As OracleDataReader Dim rolefound As Boolean cn.Open() With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.ROLES.GETALLROLES" .Parameters.Add("P_RESULT", OracleType.Cursor).Direction = ParameterDirection.Output reader = .ExecuteReader(CommandBehavior.CloseConnection) While reader.Read rolefound = False For Each role In roles If role.groupid = reader.Item("groupid") Then rolefound = True Exit For End If Next If Not rolefound Then returnroles.Add(New Role(reader.Item("groupid"), reader.Item("groupname"), reader.Item("groupdescription"), reader.Item("groupdefault"))) End If End While End With reader.Close() reader.Dispose() cmd.Dispose() cn.Close() cn.Dispose() role = Nothing Return returnroles End Function '******************************************************************************************************** 'Name: getDefaultRole 'Parameters: None 'Returns: a collection of role objects 'Purpose: Returns the default role '******************************************************************************************************** Public Shared Function getDefaultRole() As System.Collections.Generic.List(Of orgz.Role) Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim preader As OracleDataReader Dim cmd As New OracleCommand Dim roles As New System.Collections.Generic.List(Of orgz.Role) cn.Open() With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.ROLES.GETDEFAULTROLE" .Parameters.Add("P_RESULT", OracleType.Cursor).Direction = ParameterDirection.Output preader = .ExecuteReader(CommandBehavior.CloseConnection) End With If preader.Read() Then roles.Add(New Role(preader.Item("groupid"), preader.Item("groupname"), preader.Item("groupdescription"), preader.Item("groupdefault"))) End If preader.Close() preader.Dispose() preader = Nothing cmd.Dispose() cn.Dispose() cmd = Nothing cn = Nothing Return roles roles = Nothing End Function '******************************************************************************************************** 'Name: GetRole 'Parameters: ' roleid - the roleid (primary key) of the role you want 'Returns: a populated role object 'Purpose: Returns data for the selected role '******************************************************************************************************** Public Function GetRole(ByVal roleid As Integer) As orgz.Role Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand Dim dr As OracleDataReader Dim role As New orgz.Role With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.ROLES.GETROLE" .Parameters.Add("P_RESULT", OracleType.Cursor).Direction = ParameterDirection.Output .Parameters.Add("P_ROLEID", OracleType.Int32).Value = roleid cn.Open() dr = .ExecuteReader(CommandBehavior.CloseConnection) While dr.Read role = fillrole(dr) End While dr.Close() End With If cn.State = ConnectionState.Open Then cn.Close() End If dr.Dispose() dr = Nothing cmd.Dispose() cmd = Nothing cn.Dispose() cn = Nothing Return role role = Nothing End Function '******************************************************************************************************** 'Name: AddRole 'Parameters: None 'Returns: Nothing 'Purpose: Adds a role to the database. '******************************************************************************************************** Public Function AddRole() As Integer Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand Dim ret As Integer With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.ROLES.ADDROLE" .Parameters.Add("P_ROLEID", OracleType.Int32).Direction = ParameterDirection.Output .Parameters.Add("P_ROLENAME", OracleType.Varchar).Value = Me.groupname .Parameters.Add("P_ROLEDESCRIPTION", OracleType.Varchar).Value = Me.groupdescription .Parameters.Add("P_ROLEDEFAULT", OracleType.Int32).Value = IIf(Me.groupdefault, 1, 0) cn.Open() .ExecuteNonQuery() ret = .Parameters("P_ROLEID").Value cn.Close() End With cmd.Dispose() cmd = Nothing cn.Dispose() cn = Nothing Return ret End Function '******************************************************************************************************** 'Name: UpdateRole 'Parameters: None 'Returns: Nothing 'Purpose: Updates a role in the database '******************************************************************************************************** Public Sub UpdateRole() Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.ROLES.UPDATEROLE" .Parameters.Add("P_ROLEID", OracleType.Int32).Value = Me.groupid .Parameters.Add("P_ROLENAME", OracleType.Varchar).Value = Me.groupname .Parameters.Add("P_ROLEDESCRIPTION", OracleType.Varchar).Value = Me.groupdescription .Parameters.Add("P_ROLEDEFAULT", OracleType.Int32).Value = IIf(Me.groupdefault, 1, 0) cn.Open() .ExecuteNonQuery() cn.Close() End With cmd.Dispose() cmd = Nothing cn.Dispose() cn = Nothing End Sub '******************************************************************************************************** 'Name: DeleteRole 'Parameters: ' groupid - the groupid (primary key) of the role you want to delete 'Returns: Nothing 'Purpose: Deletes a role from the database. '******************************************************************************************************** Public Sub DeleteRole(ByVal groupid As Integer) Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.ROLES.DELETEROLE" .Parameters.Add("P_ROLEID", OracleType.Int32).Value = groupid cn.Open() .ExecuteNonQuery() cn.Close() End With cmd.Dispose() cmd = Nothing cn.Dispose() cn = Nothing End Sub '******************************************************************************************************** 'Name: UpdateDefaults 'Parameters: None 'Returns: Nothing 'Purpose: Updates the default role in the database. '******************************************************************************************************** Public Sub UpdateDefaults() Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.ROLES.UPDATEDEFAULTS" cn.Open() .ExecuteNonQuery() cn.Close() End With cmd.Dispose() cmd = Nothing cn.Close() cn.Dispose() cn = Nothing End Sub '******************************************************************************************************** 'Name: WipeAllRoles 'Parameters: ' roleid - the roleid of the role you wish to reset 'Returns: Nothing 'Purpose: Resets the role information for users, maps, menus, news and files '******************************************************************************************************** Public Sub WipeAllRoles(ByVal roleid As Integer) Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.ROLES.WIPEALLROLES" .Parameters.Add("P_ROLEID", OracleType.Int32).Value = roleid cn.Open() .ExecuteNonQuery() cn.Close() End With cmd.Dispose() cmd = Nothing cn.Dispose() cn = Nothing End Sub '******************************************************************************************************** 'Name: UpdateUserRoles 'Parameters: ' roleid - the role to be updated ' users - the user collection to update 'Returns: Nothing 'Purpose: Upates the given users with the supplied role. '******************************************************************************************************** Public Sub UpdateUserRoles(ByVal roleid As Integer, ByVal users As System.Collections.Generic.List(Of orgz.User)) Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand Dim user As New orgz.User With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.ROLES.UPDATEUSERROLES" cn.Open() For Each user In users .Parameters.Clear() .Parameters.Add("P_USERID", OracleType.Int32).Value = user.userid .Parameters.Add("P_ROLEID", OracleType.Int32).Value = roleid .ExecuteNonQuery() Next cn.Close() End With user = Nothing cmd.Dispose() cmd = Nothing cn.Dispose() cn = Nothing End Sub '******************************************************************************************************** 'Name: UpdateMapRoles 'Parameters: ' roleid - the role to be updated ' maps - the map collection to update 'Returns: Nothing ' maps - the maps collection to update 'Purpose: Upates the given maps with the supplied role. '******************************************************************************************************** Public Sub UpdateMapRoles(ByVal roleid As Integer, ByRef maps As System.Collections.Generic.List(Of orgz.Map)) Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand Dim map As New orgz.Map With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.ROLES.UPDATEMAPROLES" cn.Open() For Each map In maps .Parameters.Clear() .Parameters.Add("P_MAPID", OracleType.Int32).Value = map.mapid .Parameters.Add("P_ROLEID", OracleType.Int32).Value = roleid .ExecuteNonQuery() Next cn.Close() End With map = Nothing cmd.Dispose() cmd = Nothing cn.Dispose() cn = Nothing End Sub '******************************************************************************************************** 'Name: UpdateMenuRoles 'Parameters: ' roleid - the role to be updated ' menus - the menu collection to update 'Returns: Nothing 'Purpose: Upates the given menus with the supplied role. '******************************************************************************************************** Public Sub UpdateMenuRoles(ByVal roleid As Integer, ByRef menus As System.Collections.Generic.List(Of orgz.Menu)) Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand Dim menu As New orgz.Menu With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.ROLES.UPDATEMENUROLES" cn.Open() For Each menu In menus .Parameters.Clear() .Parameters.Add("P_MENUID", OracleType.Int32).Value = menu.menuid .Parameters.Add("P_ROLEID", OracleType.Int32).Value = roleid .ExecuteNonQuery() Next cn.Close() End With menu = Nothing cmd.Dispose() cmd = Nothing cn.Dispose() cn = Nothing End Sub '******************************************************************************************************** 'Name: UpdateNewsRoles 'Parameters: ' roleid - the role to be updated ' news - the news collection to update 'Returns: Nothing 'Purpose: Upates the given newsitems with the supplied role. '******************************************************************************************************** Public Sub UpdateNewsRoles(ByVal roleid As Integer, ByVal news As System.Collections.Generic.List(Of orgz.NewsItem)) Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand Dim newsitem As New orgz.NewsItem With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.ROLES.UPDATENEWSROLES" cn.Open() For Each newsitem In news .Parameters.Clear() .Parameters.Add("P_NEWSID", OracleType.Number).Value = newsitem.newsid .Parameters.Add("P_ROLEID", OracleType.Number).Value = roleid .ExecuteNonQuery() Next cn.Close() End With newsitem = Nothing cmd.Dispose() cmd = Nothing cn.Dispose() cn = Nothing End Sub '******************************************************************************************************** 'Name: UpdateFileRoles 'Parameters: ' roleid - the role to be updated ' files - the rile collection to update 'Returns: Nothing 'Purpose: Upates the given files with the supplied role. '******************************************************************************************************** Public Sub UpdateFileRoles(ByVal roleid As Integer, ByVal files As System.Collections.Generic.List(Of orgz.File)) Dim cn As New OracleConnection(ConfigurationManager.AppSettings("connectionstring")) Dim cmd As New OracleCommand Dim file As New orgz.File With cmd .Connection = cn .CommandType = CommandType.StoredProcedure .CommandText = "GPUSER.ROLES.UPDATEFILEROLES" cn.Open() For Each file In files .Parameters.Clear() .Parameters.Add("P_FILEID", OracleType.Int32).Value = file.fileid .Parameters.Add("P_ROLEID", OracleType.Int32).Value = roleid .ExecuteNonQuery() Next cn.Close() End With cmd.Dispose() cmd = Nothing cn.Dispose() cn = Nothing End Sub #End Region #Region " Auxillary Methods " '******************************************************************************************************** 'Name: GetRoleString 'Parameters: ' userid - the user whose roles you want 'Returns: a comma separated string of roles 'Purpose: Returns the users role list as a comma separated string '******************************************************************************************************** Public Shared Function GetRoleString(ByVal userid As Int32) As String Dim strRoles As New System.Text.StringBuilder Dim user As New orgz.User Dim role As New orgz.Role user = user.getuser(userid) If Not IsNothing(user) Then user.FillUserRoles() For Each role In user.roles strRoles.Append(role.groupname) strRoles.Append(",") Next If strRoles.Length > 0 Then Try strRoles.ToString.Substring(0, strRoles.Length - 1) Catch ex As Exception 'do nothing End Try End If Else strRoles.Append("Everyone") End If user = Nothing role = Nothing Return strRoles.ToString End Function '******************************************************************************************************** 'Name: GetRoleString 'Parameters: ' roles - the roles you want as a string 'Returns: a comma separated string of roles 'Purpose: Returns the role list as a comma separated string '******************************************************************************************************** Public Shared Function GetRoleString(ByRef roles As System.Collections.Generic.List(Of orgz.Role)) As String Dim strRoles As New System.Text.StringBuilder Dim role As New orgz.Role If roles.Count > 0 Then For Each role In roles strRoles.Append(role.groupname) strRoles.Append(",") Next If strRoles.Length > 0 Then Try strRoles.ToString.Substring(0, strRoles.Length - 1) Catch ex As Exception 'do nothing End Try End If Else strRoles.Append("Everyone") End If role = Nothing Return strRoles.ToString End Function '******************************************************************************************************** 'Name: filluserroles 'Parameters: ' roles - the roles to fill the listbox with ' listb - the listbox to fill 'Returns: Nothing 'Purpose: Fills the given listbox with the given roles '******************************************************************************************************** Public Shared Sub filluserroles(ByVal roles As System.Collections.Generic.List(Of orgz.Role), ByRef listb As ListBox) Dim role As orgz.Role listb.Items.Clear() For Each role In roles listb.Items.Add(New ListItem(role.groupname, role.groupid)) Next role = Nothing End Sub '******************************************************************************************************** 'Name: FILLDEFAULTROLE 'Parameters: ' listb - the listbox to fill with the default role 'Returns: Nothing 'Purpose: fills the supplied listbox with the default role '******************************************************************************************************** Public Shared Sub FILLDEFAULTROLE(ByRef listb As ListBox) Dim role As New orgz.Role For Each role In orgz.Role.getDefaultRole listb.Items.Add(New ListItem(role.groupname, role.groupid)) Next role = Nothing End Sub '******************************************************************************************************** 'Name: MoveRole 'Parameters: ' listfrom - the listbox to move the data from ' listto - the listbox to move the data to 'Returns: Nothing 'Purpose: Moves an item from one listbox to another. '******************************************************************************************************** Public Shared Sub MoveRole(ByRef listfrom As System.Web.UI.WebControls.ListBox, ByRef listto As System.Web.UI.WebControls.ListBox) Dim i As Integer If Not (IsNothing(listfrom.SelectedItem)) Then For i = listfrom.Items.Count - 1 To 0 Step -1 If listfrom.Items(i).Selected Then listto.Items.Add(listfrom.Items(i)) listfrom.Items.Remove(listfrom.Items(i)) End If Next End If End Sub '******************************************************************************************************** 'Name: fillrole 'Parameters: ' reader - the datarecord to fill the role data from 'Returns: a populated role object 'Purpose: Fills a role with data from a data record. '******************************************************************************************************** Public Function fillrole(ByVal reader As IDataRecord) As orgz.Role Return New Role(reader.Item("groupid"), reader.Item("groupname"), reader.Item("groupdescription"), reader.Item("groupdefault")) End Function '******************************************************************************************************** 'Name: GetRolesFromDropDown 'Parameters: ' DPD - The ListBox containing the role information 'Returns: A orgz.Roles object containing the role information in the supplied ListBox 'Purpose: Returns a orgz.Roles object containing the role information contained in the supplied ListBox '******************************************************************************************************** Public Shared Function GetRolesFromListBox(ByVal DPD As ListBox) As System.Collections.Generic.List(Of orgz.Role) Dim roles As New System.Collections.Generic.List(Of orgz.Role) Dim li As ListItem For Each li In DPD.Items roles.Add(New Role(li.Value, li.Text, "", False)) Next Return roles roles = Nothing End Function #End Region End Class End Namespace
Hopefully this is enough information. Any help is appreciated.Sunday, October 3, 2010 7:27 AM
Answers
-
User-660870441 posted
Hi,
The method is not shared, so it needs an instance to call. Please call method by this way to solve this error.
Dim roleObject As New orgz.Role() roles.Add(roleObject.GetRole(4))
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, October 6, 2010 3:49 AM
All replies
-
User-307692219 posted
I added the line below (see the comments starting with "add ***"):
'******************************************************************************************************** 'Name: lnkAdd_Click 'Parameters: ' sender - The object calling the function, i.e. lnkAdd ' e - event arguments 'Returns: Nothing 'Purpose: Adds a user to the database. '******************************************************************************************************** Private Sub lnkAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkAdd.Click lnkAdd.Enabled = False Dim user As New orgz.User Dim roles As New System.Collections.Generic.List(Of orgz.Role) Dim map As New orgz.Map 'add *** roles = orgz.Role.GetRole(4) 'end *** user.txtusername = user.getuseridbyusername() If (user.GetUserExistence() <= 0) Then If UCase(ConfigurationManager.AppSettings("authentication")) = "FORMS" Then user.txtusername = txtusername.Text user.txtpassword = txtpassword.Text Else Dim username As String = String.Empty username = user.getuseridbyusername() If username.Length < 1 Then Throw New Exception("Problem getting certificate for" & txtfname.Text & " " & txtlname.Text) End If user.txtusername = user.getuseridbyusername() user.txtpassword = "NOPASSWORDHERE" End If user.txtfirstname = orgz.Functions.scrubinput(txtfname.Text) user.txtlastname = orgz.Functions.scrubinput(txtlname.Text) user.txtrank = orgz.Functions.scrubinput(txtrank.Text) user.txtsquadron = orgz.Functions.scrubinput(txtsquadron.Text) user.txtoffice = orgz.Functions.scrubinput(txtoffice.Text) user.txtwing = orgz.Functions.scrubinput(txtwing.Text) user.txtinstallation = IIf(IsNothing(dpdinstallation.SelectedItem.Value), 0, dpdinstallation.SelectedItem.Value) user.txtemail = orgz.Functions.scrubinput(txtemail.Text) user.txtphone = orgz.Functions.scrubinput(txtphone.Text) user.defaultmap = map.GetDefaultMap() user.txtnotes = ""
thinking that would load the ROLEID 4 into roles. I get the following error:
error BC30469: Reference to a non-shared member requires an object reference.
How do I call this method correctly?
Monday, October 4, 2010 4:45 AM -
User-660870441 posted
Hi,
The method is not shared, so it needs an instance to call. Please call method by this way to solve this error.
Dim roleObject As New orgz.Role() roles.Add(roleObject.GetRole(4))
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, October 6, 2010 3:49 AM -
User-307692219 posted
Hi,
The method is not shared, so it needs an instance to call. Please call method by this way to solve this error.
- Dim roleObject As New orgz.Role()
- roles.Add(roleObject.GetRole(4))
Dim roleObject As New orgz.Role() roles.Add(roleObject.GetRole(4))
Doing it as you specified above did not produce any errors, but it also did not create the user with a roleid of 4. The user was created with no roles as before. I do not think, from reading through the roles class, that the Add method adds a role to the user. It adds a new role to the database, I think. I also tried the following:
Dim roleObject As New orgz.Role()
user.roles = roleObject.GetRole(4)
this resulted in the following error:
error BC30311: Value of type 'orgz.Role' cannot be converted to 'System.Collections.Generic.List(Of orgz.Role)'.
Friday, October 8, 2010 8:27 AM