Advertisement
Guest User

Untitled

a guest
Mar 6th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. Public Class Users
  2. Public Property Id As Integer
  3. Public Property UserName As String
  4. Public Property UserNin As Int16
  5. Public Property UserType As String
  6. Public Property Password As String
  7.  
  8. Property UserTypes As IEnumerable(Of SelectListItem) = {
  9. New SelectListItem With {.Value = "admin", .Text = "Admin"},
  10. New SelectListItem With {.Value = "doctor", .Text = "Doctor"},
  11. New SelectListItem With {.Value = "reception", .Text = "Receptionist"}
  12. }
  13. End Class
  14.  
  15. <% Using (Html.BeginForm("Create", "User", FormMethod.Post))%>
  16. <table>
  17. <tr>
  18. <td>
  19. User Name
  20. </td>
  21. </tr>
  22. <tr>
  23. <td>
  24. <%= Html.TextBoxFor(Function(x) x.UserName)%>
  25. </td>
  26. </tr>
  27. <tr>
  28. <td>
  29. User NIN
  30. </td>
  31. </tr>
  32. <tr>
  33. <td>
  34. <%= Html.TextBoxFor(Function(x) x.UserNin)%>
  35. </td>
  36. </tr>
  37. <tr>
  38. <td>
  39. Password
  40. </td>
  41. </tr>
  42. <tr>
  43. <td>
  44. <%= Html.PasswordFor(Function(x) x.Password)%>
  45. </td>
  46. </tr>
  47. <tr>
  48. <td>
  49. <%= Html.DropDownListFor(Function(x) x.UserType, Model.UserTypes)%>
  50. </td>
  51. </tr>
  52. <tr>
  53. <td>
  54. <input type="submit" value="Add New User" />
  55. </td>
  56. </tr>
  57. </table>
  58. <% End Using%>
  59.  
  60. Public Class LoginUser
  61. <Required()>
  62. Public Property UserName As String
  63.  
  64. <Required()>
  65. <StringLength(8)>
  66. Public Property Password As String
  67.  
  68. End Class
  69.  
  70. <% Using (Html.BeginForm("Login", "User", FormMethod.Post))%>
  71. <% Html.EnableClientValidation()%>
  72. <table ID="loginTable" runat="server">
  73. <tr>
  74. <td>
  75. <label for="username">UserName</label>
  76. </td>
  77. </tr>
  78. <tr>
  79. <td>
  80. <%= Html.TextBoxFor(Function(x) x.UserName)%>
  81. <%= Html.ValidationMessageFor(Function(x) x.UserName) %>
  82. </td>
  83. </tr>
  84. <tr>
  85. <td>
  86. <label for="password">Password</label>
  87. </td>
  88. </tr>
  89. <tr>
  90. <td>
  91. <%= Html.TextBoxFor(Function(x) x.Password)%>
  92. <%= Html.ValidationMessageFor(Function(x) x.Password)%>
  93. </td>
  94. </tr>
  95. <tr>
  96. <td>
  97. <input type="submit" value="Login" />
  98. </td>
  99. </tr>
  100. </table>
  101. <% End Using%>
  102.  
  103. <HttpPost()>
  104. Function Login() As ActionResult
  105. If ModelState.IsValid Then
  106. Dim sql As String
  107. Dim username As String = Request.Form("username").ToString
  108. Dim password As String = Request.Form("password").ToString
  109. Dim dbHelper As New DBHelper(False)
  110.  
  111. sql = "SELECT * FROM " & _tblName & " WHERE username = '" & username & "' and password = '" & password & "'"
  112. Try
  113. Dim dr As DataRow = dbHelper.ExecuteAndGetRow(sql)
  114.  
  115. If Convert.ToInt16(dr.Item(0).ToString) > 0 Then
  116. Dim nin As String = dr.Item(4)
  117. Session("loggedin") = 1
  118. Session("logged") = dr.Item(0)
  119. Session("logged_nin") = dr.Item(4)
  120. ViewData("message") = "Login Successful"
  121. ViewData("show_loginForm") = False
  122. Else
  123. ViewData("message") = "Login failed"
  124. ViewData("show_loginForm") = True
  125. End If
  126. Catch ex As Exception
  127. ViewData("message") = "Login failed"
  128. ViewData("show_loginForm") = True
  129. End Try
  130.  
  131.  
  132. Return View()
  133. Else
  134. Return View()
  135. End If
  136. End Function
  137.  
  138. <Required>
  139. Public Property UserName As String
  140.  
  141. <%= Html.TextBoxFor(Function(x) x.UserName) %>
  142. <%= Html.ValidationMessageFor(Function(x) x.UserName) %>
  143.  
  144. <%= Html.ValidationSummary() %>
  145.  
  146. <HttpPost()>
  147. Function Create(model As Users) As ActionResult
  148. If ModelState.IsValid Then
  149. ' validation succeeded => do some processing and redirect
  150. Return RedirectToAction("Create")
  151. End If
  152.  
  153. ' validation failed => redisplay the same view so that the user
  154. ' can fix the errors
  155. Return View(model)
  156. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement