Advertisement
Guest User

Untitled

a guest
Jan 16th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Compare Database
  2. Option Explicit
  3. Dim rsUser As Recordset
  4. Dim TmpCode As String
  5. Dim userCheck As Boolean
  6. '**************************************************************
  7. Private Sub CMDSendAgain_Click()
  8. 'sends another email with another verification code
  9. sendEmail
  10. MsgBox ("Another email has been sent to " & F_email)
  11. End Sub
  12. '**************************************************************
  13. Private Sub CMDExit_Click()
  14. DoCmd.Close
  15. DoCmd.OpenForm ("frmLogin")
  16. End Sub
  17. '**************************************************************
  18. Private Sub CMDCreateAccount_Click()
  19. 'Dim objOutlook As Outlook.Application
  20. 'Dim objEmail As Outlook.MailItem
  21. Dim i As Integer
  22.  
  23. i = 0
  24.  
  25. userCheck = False
  26.  
  27. 'Checks to make sure all fields have data in them
  28. 'i is used to count how many of the validations have been met
  29.  
  30. 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
  31.     Me.username.SetFocus
  32.     MsgBox ("please enter data into all the text boxes")
  33.  
  34.     Else
  35.         i = i + 1
  36.     End If
  37.  
  38. rsUser.FindFirst "U_username = '" & Me.username & "'"
  39. 'checks if the username entered doesnt exist
  40.  
  41. If rsUser.NoMatch = True Then
  42.     i = i + 1
  43.  
  44.     Else
  45.         Me.username = Null
  46.         Me.username.SetFocus
  47.         MsgBox ("Please choose another username, this one has already been taken :(")
  48.     End If
  49.  
  50. rsUser.FindFirst "U_emailaddress = '" & Me.emailaddress & "'"
  51. 'checks if the email address doesnt exist
  52.  
  53. If rsUser.NoMatch = True Then
  54.     i = i + 1
  55.  
  56.     Else
  57.         Me.emailaddress = Null
  58.         Me.emailaddress.SetFocus
  59.         MsgBox ("Please use a different email address, this one is already linked with an account :(")
  60.     End If
  61.  
  62. If i >= 3 Then
  63.     userCheck = True
  64. End If
  65.  
  66. 'If the passwords match and all vaildation has been met then
  67. If Me.ConfirmPassword = Me.password And userCheck = True Then
  68.    
  69.     GenerateCode
  70.    
  71.     'Sends an email to the new user
  72.    sendEmail
  73.    
  74.     'Adding a new recordset to the table "tblUser"
  75.    rsUser.AddNew
  76.     rsUser!U_Title = Me.cmbTitle
  77.     rsUser!U_Firstname = Me.firstname
  78.     rsUser!U_Surname = Me.surname
  79.     rsUser!U_Site = Me.Site
  80.     rsUser!U_EmailAddress = Me.emailaddress
  81.     rsUser!U_username = Me.username
  82.     rsUser!U_TempCode = TmpCode
  83.     rsUser.Update
  84.     rsUser.MoveLast
  85.     rsUser.Edit
  86.     rsUser!U_Password = Encrypt(Me.password, 3)
  87.     rsUser.Update
  88.                        
  89.     'Sets all the input boxs invisible and makes the verify code box visible
  90.    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")
  91.     Me.EnterCode.Visible = True
  92.     CMDVerify.Visible = True
  93.     CMDSendAgain.Visible = True
  94.     Me.EnterCode.SetFocus
  95.     Me.firstname.Visible = False
  96.     Me.surname.Visible = False
  97.     Me.cmbTitle.Visible = False
  98.     Me.Site.Visible = False
  99.     Me.ConfirmPassword.Visible = False
  100.     Me.emailaddress.Visible = False
  101.     Me.username.Visible = False
  102.     Me.password.Visible = False
  103.     CMDCreateAccount.Visible = False
  104.     Clear
  105.    
  106.     'If the passwords dont match then
  107.    ElseIf userCheck = True Then
  108.         MsgBox ("Passwords do not match.")
  109.         Me.password.SetFocus
  110.     End If
  111.        
  112. End Sub
  113. '**************************************************************
  114. Private Sub CMDVerify_Click()
  115. Static i As Integer
  116. rsUser.MoveLast
  117. 'If the temp code sent is the same as the code in the table then open the login page
  118. If rsUser!U_TempCode = Me.EnterCode Then
  119.  
  120.     MsgBox ("Thank you for verifiying your account, you now have access to the booking system")
  121.     'set the account verified as true and delete the tempcode data
  122.    rsUser.MoveLast
  123.     rsUser.Edit
  124.     rsUser!U_AccountVerified = True
  125.     rsUser!U_TempCode = Null
  126.     rsUser.Update
  127.  
  128.     DoCmd.Close
  129.     DoCmd.OpenForm ("frmLogin")
  130.  
  131.     Else
  132.         'if the code entered is wrong then ask for it again,
  133.        'they have only 3 attempts.
  134.        '1 attempt is taken away for every wrong code entered
  135.        i = i + 1
  136.         MsgBox ("Incorrect code, please try again you have " & 3 - i & " attempt(s) remaining")
  137.         Me.EnterCode.SetFocus
  138.            
  139. End If
  140.  
  141. If i = 3 Then
  142.     'if all attempts have been used, lock the account and
  143.    'set tempcode as null so it cannot be used
  144.    MsgBox ("Your account has been locked, if you wish to still create the account contact the admin at the contact page.")
  145.  
  146.     rsUser.MoveLast
  147.     rsUser.Edit
  148.     rsUser!U_AccountLocked = True
  149.     rsUser!U_TempCode = Null
  150.     rsUser.Update
  151.  
  152.     DoCmd.Close
  153.     DoCmd.OpenForm ("frmLogin")
  154.                
  155. End If
  156. End Sub
  157. '**************************************************************
  158. Private Sub sendEmail()
  159.  
  160. 'creates an instance of Outlook
  161. Set objOutlook = CreateObject("Outlook.application")
  162. Set objEmail = objOutlook.CreateItem(olMailItem)
  163.                
  164. GenerateCode() = tempCode
  165.    
  166. 'creates and sends email
  167. With objEmail
  168.     .To = Me.emailaddress
  169.     .Subject = Me.username & " Welcome to the awesomely OP new booking system "
  170.     .Body = "Welcome " & Me.username & " here at QinetiQ we hope you enjoy booking rooms with our new and advanced booking system,  Verification code " & tempCode & ""
  171.     .Send
  172. End With
  173.                
  174. 'closes outlook
  175. Set objEmail = Nothing
  176. objOutlook.Quit
  177.  
  178. End Sub
  179. '**************************************************************
  180. Private Sub Form_load() 'When the form loads then do this
  181.  
  182. Set rsUser = CurrentDb.OpenRecordset("tblUser", dbOpenDynaset) 'Linking the form to the table
  183.  
  184. Me.EnterCode.Visible = False
  185. CMDVerify.Visible = False
  186. CMDSendAgain.Visible = False
  187.  
  188. End Sub
  189. '**************************************************************
  190. Private Function GenerateCode()
  191. Dim AlphaChk As Integer
  192. Dim BaseNum  As Integer
  193. Dim i As Integer
  194. 'generates a random code to be sent to
  195. 'the users email to verify the users
  196. 'account
  197. Randomize Timer
  198.  
  199. For i = 1 To 5
  200.     AlphaChk = (Rnd() * 2) + 0.5
  201.    
  202.     If AlphaChk = 1 Then
  203.     BaseNum = (Rnd() * 26) + 95
  204.     TmpCode = TmpCode + Chr(BaseNum)
  205.    
  206.     ElseIf AlphaChk = 2 Then
  207.     BaseNum = (Rnd() * 9) + 0.5
  208.     TmpCode = TmpCode + Str(BaseNum)
  209.     End If
  210.    
  211. Next i
  212. GenerateCode = TmpCode
  213. End Function
  214. '**************************************************************
  215. Private Sub CMDClear_Click()
  216. 'clears the form
  217. Clear
  218. End Sub
  219. '**************************************************************
  220. Private Function Clear()
  221. Dim clearObj As Object
  222. 'Search though every object on the form
  223. For Each clearObj In Me.Form
  224. 'If the currently selected object is a text box
  225. If TypeOf clearObj Is TextBox Then
  226. 'Empty the contents of the currently selected text box
  227. clearObj = Null
  228. End If
  229. Next clearObj
  230. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement