How can I use Jiwa authentication in a plugin  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

How can I use Jiwa authentication in a plugin

Postby indikad » Wed Jun 18, 2014 4:45 pm

I want to be able to fire-up Jiwa authentication ( supply Jiwa user name and password ) ,
and hopefully get back if authentication succeeded or not -
using a plugin.
My intention is to interfere with some actions of a user - stop the action - until another authorised user types something in and releases my block.

any suggestions would be appreciated.
indikad
Frequent Contributor
Frequent Contributor
 
Posts: 182
Joined: Thu Jun 18, 2009 1:14 pm
Topics Solved: 2

Re: How can I use Jiwa authentication in a plugin

Postby Mike.Sheen » Wed Jun 18, 2014 5:47 pm

indikad wrote:I want to be able to fire-up Jiwa authentication ( supply Jiwa user name and password ) ,
and hopefully get back if authentication succeeded or not -
using a plugin.
My intention is to interfere with some actions of a user - stop the action - until another authorised user types something in and releases my block.

any suggestions would be appreciated.


Hi Indika,

To test if a username / password combination is valid, use the following:

Code: Select all
Public Sub CheckPassword(ByVal UserName As String, ByVal Password As String)
      Dim SQL As String = ""
        Dim SQLReader As SqlDataReader = Nothing
        Dim SQLParam As SqlParameter = Nothing
         
      With JiwaApplication.Manager.Instance.Database
         Try
            SQL = "SELECT Password, PasswordLastChangedDateTime " &
                        "FROM HR_Staff " &
                        "WHERE UserName = @UserName "

                Using SQLCmd As SqlCommand = New SqlCommand(SQL, .SQLConnection, .SQLTransaction)

                    SQLParam = New SqlParameter("@UserName", System.Data.SqlDbType.VarChar)
                    SQLParam.Value = UserName
                    SQLCmd.Parameters.Add(SQLParam)

                    SQLReader = SQLCmd.ExecuteReader()

                    If SQLReader.Read = True Then
                  Dim storedPassword As String = .Sanitise(SQLReader, "Password")
                  Dim passwordLastChangedDateTime As Date = .Sanitise(SQLReader, "PasswordLastChangedDateTime")
                  Dim encryption As JiwaEncryption.JiwaEncrypt = New JiwaEncryption.JiwaEncrypt
                     
                        If storedPassword <> encryption.EncryptString(Password, .FormatDateTime(passwordLastChangedDateTime, True)) Then
                          Throw New JiwaODBC.Exceptions.BadLoginException("The password provided is incorrect.")
                      End If
               Else
                  Throw New JiwaODBC.Exceptions.BadLoginException("The username provided does not exist.")
                    End If
                    SQLReader.Close()
                End Using
         Finally
                If Not SQLReader Is Nothing Then
                    SQLReader.Close()
                End If               
            End Try
      End With
   End Sub


You'll need to create a dialog in your plugin which will allow the user to enter a username and password, then call the above method. An example plugin which creates a dialog is the Pantry List plugin in the demo data.

Mike
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2440
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 755

Re: How can I use Jiwa authentication in a plugin

Postby indikad » Thu Jun 19, 2014 10:48 am

Thanks Mike. Will try this.
indikad
Frequent Contributor
Frequent Contributor
 
Posts: 182
Joined: Thu Jun 18, 2009 1:14 pm
Topics Solved: 2

Re: How can I use Jiwa authentication in a plugin

Postby indikad » Thu Jun 19, 2014 3:12 pm

Hi Mike,

I still have not had a chance to try this, will be getting to it soon.

in the meantime -
I would like you to give some input to a query that I partly discussed with Beth and Scott today and we decided to put it in the forum.

For a different project we need to intercept the changing password window of users and read the password from the password field Before Save.
This is so we can implement password complexity rule. The customer does not want Windows login.

Two Questions
1. I would like to grab the typing in password from the password reset window the small window from the Bottom of the Jiwa screen - (Right click | change password ) AND the change password modal window on staff maintenance . But I need the handle to that window - from a "BeforeSave" situation?
2. also - I can get the password from the main window staff maintenance (Staff.Password) during "Staff.SaveEnding" but, I cannot get it properly decrypted - I don't know what value to pass to the "Salt" parameter in the DecryptString method of JiwaEncrypt Class

Thanks.
indikad
Frequent Contributor
Frequent Contributor
 
Posts: 182
Joined: Thu Jun 18, 2009 1:14 pm
Topics Solved: 2

Re: How can I use Jiwa authentication in a plugin

Postby Mike.Sheen » Fri Jun 20, 2014 10:22 am

indikad wrote:Hi Mike,

I still have not had a chance to try this, will be getting to it soon.

in the meantime -
I would like you to give some input to a query that I partly discussed with Beth and Scott today and we decided to put it in the forum.

For a different project we need to intercept the changing password window of users and read the password from the password field Before Save.
This is so we can implement password complexity rule. The customer does not want Windows login.

Two Questions
1. I would like to grab the typing in password from the password reset window the small window from the Bottom of the Jiwa screen - (Right click | change password ) AND the change password modal window on staff maintenance . But I need the handle to that window - from a "BeforeSave" situation?
2. also - I can get the password from the main window staff maintenance (Staff.Password) during "Staff.SaveEnding" but, I cannot get it properly decrypted - I don't know what value to pass to the "Salt" parameter in the DecryptString method of JiwaEncrypt Class

Thanks.


Hi Indika,

1. That dialog uses the JiwaStaff object to set the password anyway - so in a plugin you can add a hook into the Staff business logic SaveEnding event. Just check if JiwaApplication.MDIParent is not nothing before attempting to show your own dialogs or message box - the staff business logic might be invoked by non-UI processes and you will cause problems when trying to do UI stuff when there is no UI (such as running in a service).
2. The salt is a string formatting of the PasswordLastChangedDateTime. The password property is plain text until after the SaveStart event, so you don't need to decrypt it unless you are hooking into SaveEnding. I've looked at the code and I can see that whilst we have a PasswordLastChangedDateTime property, we don't set that on save - we inject the value directly into a SQLParam on save and don't set the property - so you currently cannot decrypt a password on save - but like I said you can get the plain text version by using the SaveStart event instead of SaveEnding.

Hope this helps,

Mike
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2440
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 755

Re: How can I use Jiwa authentication in a plugin

Postby indikad » Fri Jun 20, 2014 11:17 am

Thanks Mike. Will try now.
indikad
Frequent Contributor
Frequent Contributor
 
Posts: 182
Joined: Thu Jun 18, 2009 1:14 pm
Topics Solved: 2

Re: How can I use Jiwa authentication in a plugin

Postby indikad » Fri Jun 20, 2014 12:59 pm

Hi Mike,
not having much luck -

I need to catch the little password reset window - the new password and stop the user if things aren't right - .....
see my crazy codes below.
***Note I have not included the event subroutines.

Code: Select all
    Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup   
    '//  below event does not fire at all   
    If TypeOf JiwaForm Is JiwaApplication.JiwaStaff.clsStaff Then
   Dim a As JiwaApplication.JiwaStaff.clsStaff
   AddHandler a.SaveStart , AddressOf SaveStart
    End If
    '//  below event fires but it does not catch the little password reset window event I need -
     '//instead it works only on the save click of the staff maintenance main form

    If TypeOf JiwaForm Is JiwaStaffUI.frmMain 
            Dim StaffForm As JiwaStaffUI.frmMain = DirectCast(JiwaForm, JiwaApplication.IJiwaForm)
            AddHandler StaffForm.Staff.SaveStart , AddressOf UISaveStart      
    End If   
   '//  below I cannot extract an event for secForm so it does not enter the if condition below
    If TypeOf JiwaForm Is JiwaApplication.SecurityUI.ResetPassword
         Dim secForm As JiwaApplication.SecurityUI.ResetPassword   = DirectCast(JiwaForm,    JiwaApplication.IJiwaForm )         
        MessageBox.Show("new pass " & secForm.NewPassword.ToString()   )      
    End If

   End Sub
indikad
Frequent Contributor
Frequent Contributor
 
Posts: 182
Joined: Thu Jun 18, 2009 1:14 pm
Topics Solved: 2

Re: How can I use Jiwa authentication in a plugin

Postby Mike.Sheen » Fri Jun 20, 2014 1:24 pm

Indika,

You're going to have to make your own reset password dialog, and also add a handler for the staff maintenance form to intercept the cmdReset.Click event in the SetupBeforeHandlers to open your dialog instead of our standard one, then throw a new ClientCancelledException to prevent our dialog from appearing.

The change password dialog is pretty simple - to save you a bit of time here's what our one looks like (including designer code) - you should be able to just copy past that into your plugin:

Code: Select all
Option Strict Off
Option Explicit On

Friend Class frmResetPassword
    Inherits System.Windows.Forms.Form

    Public Cancelled As Boolean
    Public Staff As JiwaApplication.JiwaStaff.clsStaff
    Public OldPassword As String
    Public NewPassword As String
    Public ConfirmNewPassword As String
    Private FormWidth As Integer
    Private FormHeight As Integer

    Public Function SetupForm() As Boolean
        On Error GoTo ErrorHandler

        SetupForm = True

        If SetupForm Then
            Cancelled = True
            cmdOK.Enabled = True
            FormWidth = 4980
            FormHeight = 2220
        End If

        If SetupForm Then
            txtOldPassword.Text = "********"
        End If

        If SetupForm Then
            txtOldPassword.ReadOnly = True
            txtOldPassword.Enabled = False
        End If

        On Error GoTo 0
        Exit Function

ErrorHandler:
        ReportError(Err.Description, "SetupForm")
        SetupForm = False
        On Error GoTo 0
    End Function

    Private Sub ReportError(ByVal ErrorMessage As String, ByVal ErrorModule As String)
        MsgBox("Error : " & ErrorMessage & vbCrLf & "Module : " & ErrorModule, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Error")
    End Sub

    Private Sub cmdCancel_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdCancel.Click
        Cancelled = True
        Me.Close()
    End Sub

    Private Sub cmdOK_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdOK.Click
        If NewPassword <> ConfirmNewPassword Then
            ReportError("Your new password and confirmation do not match.", "Reset Password")
        Else
            Cancelled = False
            Me.Close()
        End If
    End Sub


    Private Sub txtConfirmNewPassword_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtConfirmNewPassword.TextChanged
        ConfirmNewPassword = txtConfirmNewPassword.Text
        CheckEditStatus()
    End Sub


    Private Sub txtNewPassword_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtNewPassword.TextChanged
        NewPassword = txtNewPassword.Text
        CheckEditStatus()
    End Sub

    Public Sub CheckEditStatus()
        cmdOK.Enabled = True
    End Sub
End Class

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class frmResetPassword
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer. 
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Dim Appearance1 As Infragistics.Win.Appearance = New Infragistics.Win.Appearance()
        Dim Appearance2 As Infragistics.Win.Appearance = New Infragistics.Win.Appearance()
        Dim Appearance3 As Infragistics.Win.Appearance = New Infragistics.Win.Appearance()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmResetPassword))
        Me.txtConfirmNewPassword = New Infragistics.Win.UltraWinEditors.UltraTextEditor()
        Me.txtNewPassword = New Infragistics.Win.UltraWinEditors.UltraTextEditor()
        Me.txtOldPassword = New Infragistics.Win.UltraWinEditors.UltraTextEditor()
        Me.cmdOK = New Infragistics.Win.Misc.UltraButton()
        Me.cmdCancel = New Infragistics.Win.Misc.UltraButton()
        Me.lblConfirmNewPassword = New Infragistics.Win.Misc.UltraLabel()
        Me.lblNewPassword = New Infragistics.Win.Misc.UltraLabel()
        Me.lblOldPassword = New Infragistics.Win.Misc.UltraLabel()
        CType(Me.txtConfirmNewPassword, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.txtNewPassword, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.txtOldPassword, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'txtConfirmNewPassword
        '
        Me.txtConfirmNewPassword.AcceptsReturn = True
        Me.txtConfirmNewPassword.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
            Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Appearance1.BackColor = System.Drawing.SystemColors.Window
        Appearance1.Cursor = System.Windows.Forms.Cursors.IBeam
        Appearance1.ForeColor = System.Drawing.SystemColors.WindowText
        Me.txtConfirmNewPassword.Appearance = Appearance1
        Me.txtConfirmNewPassword.BackColor = System.Drawing.SystemColors.Window
        Me.txtConfirmNewPassword.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.txtConfirmNewPassword.ForeColor = System.Drawing.SystemColors.WindowText
        Me.txtConfirmNewPassword.ImeMode = System.Windows.Forms.ImeMode.Disable
        Me.txtConfirmNewPassword.Location = New System.Drawing.Point(159, 74)
        Me.txtConfirmNewPassword.MaxLength = 0
        Me.txtConfirmNewPassword.Name = "txtConfirmNewPassword"
        Me.txtConfirmNewPassword.PasswordChar = Global.Microsoft.VisualBasic.ChrW(42)
        Me.txtConfirmNewPassword.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.txtConfirmNewPassword.Size = New System.Drawing.Size(228, 21)
        Me.txtConfirmNewPassword.TabIndex = 11
        '
        'txtNewPassword
        '
        Me.txtNewPassword.AcceptsReturn = True
        Me.txtNewPassword.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
            Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Appearance2.BackColor = System.Drawing.SystemColors.Window
        Appearance2.Cursor = System.Windows.Forms.Cursors.IBeam
        Appearance2.ForeColor = System.Drawing.SystemColors.WindowText
        Me.txtNewPassword.Appearance = Appearance2
        Me.txtNewPassword.BackColor = System.Drawing.SystemColors.Window
        Me.txtNewPassword.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.txtNewPassword.ForeColor = System.Drawing.SystemColors.WindowText
        Me.txtNewPassword.ImeMode = System.Windows.Forms.ImeMode.Disable
        Me.txtNewPassword.Location = New System.Drawing.Point(159, 47)
        Me.txtNewPassword.MaxLength = 0
        Me.txtNewPassword.Name = "txtNewPassword"
        Me.txtNewPassword.PasswordChar = Global.Microsoft.VisualBasic.ChrW(42)
        Me.txtNewPassword.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.txtNewPassword.Size = New System.Drawing.Size(228, 21)
        Me.txtNewPassword.TabIndex = 10
        '
        'txtOldPassword
        '
        Me.txtOldPassword.AcceptsReturn = True
        Me.txtOldPassword.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
            Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Appearance3.BackColor = System.Drawing.SystemColors.Window
        Appearance3.Cursor = System.Windows.Forms.Cursors.IBeam
        Appearance3.ForeColor = System.Drawing.SystemColors.WindowText
        Me.txtOldPassword.Appearance = Appearance3
        Me.txtOldPassword.BackColor = System.Drawing.SystemColors.Window
        Me.txtOldPassword.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.txtOldPassword.ForeColor = System.Drawing.SystemColors.WindowText
        Me.txtOldPassword.ImeMode = System.Windows.Forms.ImeMode.Disable
        Me.txtOldPassword.Location = New System.Drawing.Point(159, 9)
        Me.txtOldPassword.MaxLength = 0
        Me.txtOldPassword.Name = "txtOldPassword"
        Me.txtOldPassword.PasswordChar = Global.Microsoft.VisualBasic.ChrW(42)
        Me.txtOldPassword.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.txtOldPassword.Size = New System.Drawing.Size(228, 21)
        Me.txtOldPassword.TabIndex = 9
        '
        'cmdOK
        '
        Me.cmdOK.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.cmdOK.BackColorInternal = System.Drawing.SystemColors.Control
        Me.cmdOK.Cursor = System.Windows.Forms.Cursors.Default
        Me.cmdOK.ForeColor = System.Drawing.SystemColors.ControlText
        Me.cmdOK.Location = New System.Drawing.Point(229, 116)
        Me.cmdOK.Name = "cmdOK"
        Me.cmdOK.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cmdOK.Size = New System.Drawing.Size(76, 24)
        Me.cmdOK.TabIndex = 12
        Me.cmdOK.Tag = "Cancel"
        Me.cmdOK.Text = "&OK"
        '
        'cmdCancel
        '
        Me.cmdCancel.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.cmdCancel.BackColorInternal = System.Drawing.SystemColors.Control
        Me.cmdCancel.Cursor = System.Windows.Forms.Cursors.Default
        Me.cmdCancel.ForeColor = System.Drawing.SystemColors.ControlText
        Me.cmdCancel.Location = New System.Drawing.Point(313, 116)
        Me.cmdCancel.Name = "cmdCancel"
        Me.cmdCancel.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cmdCancel.Size = New System.Drawing.Size(76, 24)
        Me.cmdCancel.TabIndex = 13
        Me.cmdCancel.Tag = "Cancel"
        Me.cmdCancel.Text = "&Cancel"
        '
        'lblConfirmNewPassword
        '
        Me.lblConfirmNewPassword.BackColorInternal = System.Drawing.SystemColors.Control
        Me.lblConfirmNewPassword.Cursor = System.Windows.Forms.Cursors.Default
        Me.lblConfirmNewPassword.ForeColor = System.Drawing.SystemColors.ControlText
        Me.lblConfirmNewPassword.Location = New System.Drawing.Point(9, 78)
        Me.lblConfirmNewPassword.Name = "lblConfirmNewPassword"
        Me.lblConfirmNewPassword.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.lblConfirmNewPassword.Size = New System.Drawing.Size(147, 19)
        Me.lblConfirmNewPassword.TabIndex = 15
        Me.lblConfirmNewPassword.Text = "Confirm New Password"
        '
        'lblNewPassword
        '
        Me.lblNewPassword.BackColorInternal = System.Drawing.SystemColors.Control
        Me.lblNewPassword.Cursor = System.Windows.Forms.Cursors.Default
        Me.lblNewPassword.ForeColor = System.Drawing.SystemColors.ControlText
        Me.lblNewPassword.Location = New System.Drawing.Point(9, 51)
        Me.lblNewPassword.Name = "lblNewPassword"
        Me.lblNewPassword.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.lblNewPassword.Size = New System.Drawing.Size(147, 19)
        Me.lblNewPassword.TabIndex = 14
        Me.lblNewPassword.Text = "New Password"
        '
        'lblOldPassword
        '
        Me.lblOldPassword.BackColorInternal = System.Drawing.SystemColors.Control
        Me.lblOldPassword.Cursor = System.Windows.Forms.Cursors.Default
        Me.lblOldPassword.ForeColor = System.Drawing.SystemColors.ControlText
        Me.lblOldPassword.Location = New System.Drawing.Point(9, 13)
        Me.lblOldPassword.Name = "lblOldPassword"
        Me.lblOldPassword.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.lblOldPassword.Size = New System.Drawing.Size(141, 19)
        Me.lblOldPassword.TabIndex = 8
        Me.lblOldPassword.Text = "Old Password"
        '
        'frmResetPassword
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(402, 152)
        Me.Controls.Add(Me.txtConfirmNewPassword)
        Me.Controls.Add(Me.txtNewPassword)
        Me.Controls.Add(Me.txtOldPassword)
        Me.Controls.Add(Me.cmdOK)
        Me.Controls.Add(Me.cmdCancel)
        Me.Controls.Add(Me.lblConfirmNewPassword)
        Me.Controls.Add(Me.lblNewPassword)
        Me.Controls.Add(Me.lblOldPassword)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmResetPassword"
        Me.Text = "Reset Password"
        CType(Me.txtConfirmNewPassword, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.txtNewPassword, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.txtOldPassword, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Public WithEvents txtConfirmNewPassword As Infragistics.Win.UltraWinEditors.UltraTextEditor
    Public WithEvents txtNewPassword As Infragistics.Win.UltraWinEditors.UltraTextEditor
    Public WithEvents txtOldPassword As Infragistics.Win.UltraWinEditors.UltraTextEditor
    Public WithEvents cmdOK As Infragistics.Win.Misc.UltraButton
    Public WithEvents cmdCancel As Infragistics.Win.Misc.UltraButton
    Public WithEvents lblConfirmNewPassword As Infragistics.Win.Misc.UltraLabel
    Public WithEvents lblNewPassword As Infragistics.Win.Misc.UltraLabel
    Public WithEvents lblOldPassword As Infragistics.Win.Misc.UltraLabel
End Class



And to invoke it, you would do this:
Code: Select all
Dim myForm As frmResetPassword

        myForm = New frmResetPassword
        myForm.Staff = Staff
        myForm.OldPassword = Staff.Password

        If myForm.SetupForm = True Then
            myForm.ShowDialog(Me)
            If myForm.Cancelled = False Then
                Staff.Password = myForm.NewPassword
            End If
        End If

        myForm.Close()
        myForm.Staff = Nothing
        myForm = Nothing
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2440
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 755

Re: How can I use Jiwa authentication in a plugin

Postby indikad » Fri Jun 20, 2014 4:36 pm

officially stuck on something.

I can get the code complied but on trying to call the loading of the form - I get an error.
Unable to cast object of Type 'FormPlugin' to type 'system.Windows.Forms.IwinWindow'

I am trying to load the form from the Setup.
I can stop the Jiwa window fromlaoing from the before handler code - but if that runs then the afterClick event does not run....
I could be doing some incorrect VB coding too....
code attached also copied some below.
thanks.
Code: Select all
   Public Sub SetupBeforeHandlers(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.SetupBeforeHandlers
      If TypeOf JiwaForm Is JiwaStaffUI.frmMain 
            Dim StaffForm As JiwaStaffUI.frmMain = DirectCast(JiwaForm, JiwaApplication.IJiwaForm)            
         AddHandler StaffForm.cmdReset.Click , AddressOf cmdResetOfStaffMaintainClickedBefore
        End If   
    End Sub
   Private Sub cmdResetOfStaffMaintainClickedBefore ( sender As Object ,  e As System.EventArgs )
      MessageBox.Show("cmd reset clicked before")               
      Try
         Throw New JiwaApplication.Exceptions.ClientCancelledException  ("client cancelled.")         
      Finally
      
      End Try         
   End Sub
    Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
      If TypeOf JiwaForm Is JiwaStaffUI.frmMain 
            Dim StaffForm As JiwaStaffUI.frmMain = DirectCast(JiwaForm, JiwaApplication.IJiwaForm)            
         AddHandler StaffForm.cmdReset.Click  , AddressOf cmdResetOfStaffMaintainClickedAfter
        End If         
    End Sub
   Private Sub cmdResetOfStaffMaintainClickedAfter ( sender As Object ,  e As System.EventArgs )
      MessageBox.Show("cmd reset clicked after ")         
      Dim myForm As frmResetPassword
        myForm = New frmResetPassword
      
        'myForm.Staff = Staff
        'myForm.OldPassword = Staff.Password
      
      Try
         MessageBox.Show ("before myfor.setup ")
           If myForm.SetupForm = True Then
            MessageBox.Show ("before calling my reset password form ")
               myForm.ShowDialog(Me)
               If myForm.Cancelled = False Then
                   'Staff.Password = myForm.NewPassword
               End If
           End If
      Catch ex As Exception
         MessageBox.Show ("error loading myform " & ex.Message )
      End Try
   End Sub
Attachments
idk_Test_MikePasswordWindow.zip
(5.4 KiB) Downloaded 137 times
indikad
Frequent Contributor
Frequent Contributor
 
Posts: 182
Joined: Thu Jun 18, 2009 1:14 pm
Topics Solved: 2

Re: How can I use Jiwa authentication in a plugin

Postby Mike.Sheen » Fri Jun 20, 2014 4:58 pm

Ok, there's just a few things to address and you should have it working.

Firstly, Add a handler for cmdReset.Click in the SetupBeforeHandlers OR Setup but not both.

In your case you want to add the handler in SetupBeforeHandlers, and do absolutely nothing in the Setup method. Then in your handler, show your dialog and then throw a ClientCancelledException

So your FormPlugin class should look like this:

Code: Select all
Public Class FormPlugin
    Inherits System.MarshalByRefObject
    Implements JiwaApplication.IJiwaFormPlugin

    Public Overrides Function InitializeLifetimeService() As Object
        ' returning null here will prevent the lease manager
        ' from deleting the Object.
        Return Nothing
    End Function

    Public Sub SetupBeforeHandlers(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.SetupBeforeHandlers
      If TypeOf JiwaForm Is JiwaStaffUI.frmMain 
            Dim StaffForm As JiwaStaffUI.frmMain = DirectCast(JiwaForm, JiwaApplication.IJiwaForm)            
         AddHandler StaffForm.cmdReset.Click , AddressOf cmdResetClick
        End If   
    End Sub
         
    Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
            
    End Sub
      
   Private Sub cmdResetClick ( sender As Object ,  e As System.EventArgs )
        Dim myForm As frmResetPassword
        myForm = New frmResetPassword
      
        'myForm.Staff = Staff
        'myForm.OldPassword = Staff.Password
      
      Try
         MessageBox.Show ("before myfor.setup ")
           If myForm.SetupForm = True Then
            MessageBox.Show ("before calling my reset password form ")
               myForm.ShowDialog(Nothing)
               If myForm.Cancelled = False Then
                   'Staff.Password = myForm.NewPassword
               End If
           End If
      Catch ex As Exception
         MessageBox.Show ("error loading myform " & ex.Message )
      End Try
         
      Throw New JiwaApplication.Exceptions.ClientCancelledException()
   End Sub
End Class


Secondly, note that I modified the call to myForm.ShowDialog above to pass nothing instead of Me - ShowDialog wants a Windows Form to be passed as the owner or nothing - you were passing me, which was a class of that did not implement the interfaces it wanted "system.Windows.Forms.IwinWindow'" as per your error message.

Ideally you should pass the Staff Maintenance form, so it knows that the password reset dialog is modal to the staff maintenance form. Do this by storing the JiwaForm passed to SetupBeforeHandlers into a class variable, and passing that.

ie:

Code: Select all
Public Class FormPlugin
    Inherits System.MarshalByRefObject
    Implements JiwaApplication.IJiwaFormPlugin

   Private staffMaintenanceForm as JiwaStaffUI.frmMain

    Public Overrides Function InitializeLifetimeService() As Object
        ' returning null here will prevent the lease manager
        ' from deleting the Object.
        Return Nothing
    End Function

    Public Sub SetupBeforeHandlers(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.SetupBeforeHandlers
      If TypeOf JiwaForm Is JiwaStaffUI.frmMain 
            staffMaintenanceForm = DirectCast(JiwaForm, JiwaApplication.IJiwaForm)            
         AddHandler staffMaintenanceForm.cmdReset.Click , AddressOf cmdResetClick
        End If   
    End Sub
         
    Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
            
    End Sub
      
   Private Sub cmdResetClick ( sender As Object ,  e As System.EventArgs )
        Dim myForm As frmResetPassword
        myForm = New frmResetPassword
      
        'myForm.Staff = Staff
        'myForm.OldPassword = Staff.Password
      
      Try
         MessageBox.Show ("before myfor.setup ")
           If myForm.SetupForm = True Then
            MessageBox.Show ("before calling my reset password form ")
               myForm.ShowDialog(staffMaintenanceForm)
               If myForm.Cancelled = False Then
                   'Staff.Password = myForm.NewPassword
               End If
           End If
      Catch ex As Exception
         MessageBox.Show ("error loading myform " & ex.Message )
      End Try
         
      Throw New JiwaApplication.Exceptions.ClientCancelledException()
   End Sub
End Class
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2440
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 755

Next

Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 10 guests

cron