Guest User

Untitled

a guest
Feb 13th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. <authentication mode="Forms">
  2. <forms loginUrl="~/Account/Login"/>
  3. </authentication>
  4.  
  5. [Authorize]
  6. public class DepartmentController : Controller
  7. { etc... }
  8.  
  9. @model AccountLoginViewModel
  10. @{
  11. ViewBag.Title = "Login";
  12. }
  13.  
  14. <div>
  15. @Html.DisplayFor(m => m.Messages)
  16. </div>
  17.  
  18. <h1 style="font-weight:bold">Log in!</h1>
  19.  
  20. <p>Here we can log in: </p>
  21.  
  22. <form method="post" action="@Url.Action("Login", "Account")">
  23. <div class="container">
  24. <br />
  25. <label for="uname"><b>Username: </b></label>
  26. @Html.TextBoxFor(m => m.Logins[0].Username, new { placeholder = " Enter Username" })<br /><br />
  27. <label for="psw"><b>Password: </b></label>
  28. @Html.PasswordFor(m => m.Logins[0].Password, new { placeholder = " Enter Password" })<br /><br />
  29.  
  30. <button type="submit">Login</button>
  31. </div>
  32. </form>
  33.  
  34. [HttpPost]
  35. public ActionResult Login(AccountLoginViewModel accountLoginViewModel)
  36. {
  37. AccountLoginViewModel model = new AccountLoginViewModel();
  38.  
  39. UserLoginBo _userLoginBo = new UserLoginBo();
  40. _userLoginBo.Username = accountLoginViewModel.Logins[0].Username;
  41. _userLoginBo.Password = accountLoginViewModel.Logins[0].Password;
  42.  
  43. var response = _userService.Login(_userLoginBo);
  44. if (response.IsSuccess)
  45. {
  46. model.Logins = response.Values;
  47. return RedirectToAction("Index", "Department");
  48. }
  49. else
  50. {
  51. model.Messages = response.Messages;
  52. }
  53.  
  54. return View(model);
  55. }
Add Comment
Please, Sign In to add comment