Advertisement
Guest User

Untitled

a guest
Apr 15th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. public class UserLogin
  2. {
  3. public static string userName
  4. {
  5. get { return Convert.ToString(HttpContext.Current.Session["LoggedUser"]); }
  6. set { HttpContext.Current.Session["LoggedUser"] = value; }
  7. }
  8.  
  9. public static string userPass
  10. {
  11. get { return Convert.ToString(HttpContext.Current.Session["LoggedPass"]); }
  12. set { HttpContext.Current.Session["LoggedPass"] = value; }
  13. }
  14. }
  15.  
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Linq;
  19. using System.Web;
  20. using System.Web.Mvc;
  21. using LoginFormMVC.Models;
  22.  
  23. namespace LoginFormMVC.Controllers
  24. {
  25. public class HomeController : Controller
  26. {
  27. public ActionResult Index()
  28. {
  29. return View();
  30. }
  31.  
  32. public ActionResult About()
  33. {
  34. ViewBag.Message = "Your application description page.";
  35.  
  36. return View();
  37. }
  38.  
  39. public ActionResult Contact()
  40. {
  41. ViewBag.Message = "Your contact page.";
  42.  
  43. return View();
  44. }
  45.  
  46.  
  47. public ActionResult LogIn()
  48. {
  49. return View("About");
  50. }
  51.  
  52. [HttpPost]
  53. [ValidateAntiForgeryToken]
  54. public ActionResult LogIn(UserLogin u)
  55. {
  56.  
  57. using (OTR2WCF.OTR2ServiceClient service = new OTR2WCF.OTR2ServiceClient())
  58. {
  59.  
  60. var strResult = service.LoginUserJSON(LoginFormMVC.Models.UserLogin.userName, LoginFormMVC.Models.UserLogin.userName);
  61.  
  62. u = null;
  63.  
  64. if ((strResult != "[]") && (strResult.StartsWith("Error: ") == false))
  65. {
  66. UserLogin.userName = LoginFormMVC.Models.UserLogin.userName;
  67. UserLogin.userPass = LoginFormMVC.Models.UserLogin.userName;
  68. ModelState.AddModelError("", "Correct username and password");
  69.  
  70. }
  71.  
  72. else
  73. {
  74. ModelState.AddModelError("", "Wrong username or password");
  75. }
  76.  
  77.  
  78.  
  79. }
  80. return View();
  81. }
  82. }
  83. }
  84.  
  85. @model LoginFormMVC.Models.UserLogin
  86.  
  87. @{
  88. ViewBag.Title = "LogIn";
  89. }
  90.  
  91. <h2>LogIn</h2>
  92.  
  93.  
  94. @using (Html.BeginForm("LogIn", "Home", FormMethod.Post))
  95. {
  96. @Html.AntiForgeryToken()
  97.  
  98. <div class="form-horizontal">
  99. <h4>UserLogin</h4>
  100. <hr />
  101. @Html.ValidationSummary(true, "", new { @class = "text-danger" })
  102. <div class="form-group">
  103. @Html.LabelFor(model => LoginFormMVC.Models.UserLogin.userName, htmlAttributes: new { @class = "control-label col-md-2" })
  104. <div class="col-md-10">
  105. @Html.EditorFor(model => LoginFormMVC.Models.UserLogin.userName, new { htmlAttributes = new { @class = "form-control" } })
  106. @Html.ValidationMessageFor(model => LoginFormMVC.Models.UserLogin.userName, "", new { @class = "text-danger" })
  107. </div>
  108. </div>
  109.  
  110. <div class="form-group">
  111. @Html.LabelFor(model => LoginFormMVC.Models.UserLogin.userPass, htmlAttributes: new { @class = "control-label col-md-2" })
  112. <div class="col-md-10">
  113. @Html.EditorFor(model => LoginFormMVC.Models.UserLogin.userPass, new { htmlAttributes = new { @class = "form-control" } })
  114. @Html.ValidationMessageFor(model => LoginFormMVC.Models.UserLogin.userPass, "", new { @class = "text-danger" })
  115. </div>
  116. </div>
  117.  
  118. <div class="form-group">
  119. <div class="col-md-offset-2 col-md-10">
  120. <button type="submit">New Request</button>
  121. </div>
  122. </div>
  123. </div>
  124. }
  125.  
  126. <div>
  127. @Html.ActionLink("Back to List", "Index")
  128. </div>
  129.  
  130. @section Scripts {
  131. @Scripts.Render("~/bundles/jqueryval")
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement