Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Compare Database
- Option Explicit
- Dim rsUser As Recordset
- Dim TmpCode As String
- Dim userCheck As Boolean
- '**************************************************************
- Private Sub CMDSendAgain_Click()
- 'sends another email with another verification code
- sendEmail
- MsgBox ("Another email has been sent to " & F_email)
- End Sub
- '**************************************************************
- Private Sub CMDExit_Click()
- DoCmd.Close
- DoCmd.OpenForm ("frmLogin")
- End Sub
- '**************************************************************
- Private Sub CMDCreateAccount_Click()
- 'Dim objOutlook As Outlook.Application
- 'Dim objEmail As Outlook.MailItem
- Dim i As Integer
- i = 0
- userCheck = False
- 'Checks to make sure all fields have data in them
- 'i is used to count how many of the validations have been met
- If Len(Me.emailaddress.Value & "") = 0 Or Len(Me.username.Value & "") = 0 Or Len(Me.password.Value & "") = 0 Or Len(Me.Site.Value & "") = 0 Or Len(Me.cmbTitle.Value & "") = 0 Or Len(Me.surname.Value & "") = 0 Or Len(Me.firstname.Value & "") = 0 Or Len(Me.ConfirmPassword.Value & "") = 0 Then
- Me.username.SetFocus
- MsgBox ("please enter data into all the text boxes")
- Else
- i = i + 1
- End If
- rsUser.FindFirst "U_username = '" & Me.username & "'"
- 'checks if the username entered doesnt exist
- If rsUser.NoMatch = True Then
- i = i + 1
- Else
- Me.username = Null
- Me.username.SetFocus
- MsgBox ("Please choose another username, this one has already been taken :(")
- End If
- rsUser.FindFirst "U_emailaddress = '" & Me.emailaddress & "'"
- 'checks if the email address doesnt exist
- If rsUser.NoMatch = True Then
- i = i + 1
- Else
- Me.emailaddress = Null
- Me.emailaddress.SetFocus
- MsgBox ("Please use a different email address, this one is already linked with an account :(")
- End If
- If i >= 3 Then
- userCheck = True
- End If
- 'If the passwords match and all vaildation has been met then
- If Me.ConfirmPassword = Me.password And userCheck = True Then
- GenerateCode
- 'Sends an email to the new user
- sendEmail
- 'Adding a new recordset to the table "tblUser"
- rsUser.AddNew
- rsUser!U_Title = Me.cmbTitle
- rsUser!U_Firstname = Me.firstname
- rsUser!U_Surname = Me.surname
- rsUser!U_Site = Me.Site
- rsUser!U_EmailAddress = Me.emailaddress
- rsUser!U_username = Me.username
- rsUser!U_TempCode = TmpCode
- rsUser.Update
- rsUser.MoveLast
- rsUser.Edit
- rsUser!U_Password = Encrypt(Me.password, 3)
- rsUser.Update
- 'Sets all the input boxs invisible and makes the verify code box visible
- MsgBox ("An Email has been sent to your email address with a confimation code to validation your account enter the code here to verify your account. COPY AND PASTE THE CODE WITH THE SPACES IF ANY")
- Me.EnterCode.Visible = True
- CMDVerify.Visible = True
- CMDSendAgain.Visible = True
- Me.EnterCode.SetFocus
- Me.firstname.Visible = False
- Me.surname.Visible = False
- Me.cmbTitle.Visible = False
- Me.Site.Visible = False
- Me.ConfirmPassword.Visible = False
- Me.emailaddress.Visible = False
- Me.username.Visible = False
- Me.password.Visible = False
- CMDCreateAccount.Visible = False
- Clear
- 'If the passwords dont match then
- ElseIf userCheck = True Then
- MsgBox ("Passwords do not match.")
- Me.password.SetFocus
- End If
- End Sub
- '**************************************************************
- Private Sub CMDVerify_Click()
- Static i As Integer
- rsUser.MoveLast
- 'If the temp code sent is the same as the code in the table then open the login page
- If rsUser!U_TempCode = Me.EnterCode Then
- MsgBox ("Thank you for verifiying your account, you now have access to the booking system")
- 'set the account verified as true and delete the tempcode data
- rsUser.MoveLast
- rsUser.Edit
- rsUser!U_AccountVerified = True
- rsUser!U_TempCode = Null
- rsUser.Update
- DoCmd.Close
- DoCmd.OpenForm ("frmLogin")
- Else
- 'if the code entered is wrong then ask for it again,
- 'they have only 3 attempts.
- '1 attempt is taken away for every wrong code entered
- i = i + 1
- MsgBox ("Incorrect code, please try again you have " & 3 - i & " attempt(s) remaining")
- Me.EnterCode.SetFocus
- End If
- If i = 3 Then
- 'if all attempts have been used, lock the account and
- 'set tempcode as null so it cannot be used
- MsgBox ("Your account has been locked, if you wish to still create the account contact the admin at the contact page.")
- rsUser.MoveLast
- rsUser.Edit
- rsUser!U_AccountLocked = True
- rsUser!U_TempCode = Null
- rsUser.Update
- DoCmd.Close
- DoCmd.OpenForm ("frmLogin")
- End If
- End Sub
- '**************************************************************
- Private Sub sendEmail()
- 'creates an instance of Outlook
- Set objOutlook = CreateObject("Outlook.application")
- Set objEmail = objOutlook.CreateItem(olMailItem)
- GenerateCode() = tempCode
- 'creates and sends email
- With objEmail
- .To = Me.emailaddress
- .Subject = Me.username & " Welcome to the awesomely OP new booking system "
- .Body = "Welcome " & Me.username & " here at QinetiQ we hope you enjoy booking rooms with our new and advanced booking system, Verification code " & tempCode & ""
- .Send
- End With
- 'closes outlook
- Set objEmail = Nothing
- objOutlook.Quit
- End Sub
- '**************************************************************
- Private Sub Form_load() 'When the form loads then do this
- Set rsUser = CurrentDb.OpenRecordset("tblUser", dbOpenDynaset) 'Linking the form to the table
- Me.EnterCode.Visible = False
- CMDVerify.Visible = False
- CMDSendAgain.Visible = False
- End Sub
- '**************************************************************
- Private Function GenerateCode()
- Dim AlphaChk As Integer
- Dim BaseNum As Integer
- Dim i As Integer
- 'generates a random code to be sent to
- 'the users email to verify the users
- 'account
- Randomize Timer
- For i = 1 To 5
- AlphaChk = (Rnd() * 2) + 0.5
- If AlphaChk = 1 Then
- BaseNum = (Rnd() * 26) + 95
- TmpCode = TmpCode + Chr(BaseNum)
- ElseIf AlphaChk = 2 Then
- BaseNum = (Rnd() * 9) + 0.5
- TmpCode = TmpCode + Str(BaseNum)
- End If
- Next i
- GenerateCode = TmpCode
- End Function
- '**************************************************************
- Private Sub CMDClear_Click()
- 'clears the form
- Clear
- End Sub
- '**************************************************************
- Private Function Clear()
- Dim clearObj As Object
- 'Search though every object on the form
- For Each clearObj In Me.Form
- 'If the currently selected object is a text box
- If TypeOf clearObj Is TextBox Then
- 'Empty the contents of the currently selected text box
- clearObj = Null
- End If
- Next clearObj
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement