Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. namespace Mynamespace
  2. {
  3. public class AuthenticationController : AuthorizedController
  4. {
  5. private readonly IFormsAuthentication formsAuthentication;
  6. private readonly IUserServices userServices;
  7.  
  8. [InjectionConstructor]
  9. public AuthenticationController(IFormsAuthentication formsAuthentication, IUserServices userServices, IServiceLocator servicelocator)
  10. : base(userServices, servicelocator)
  11. {
  12. this.formsAuthentication = formsAuthentication;
  13. this.userServices = userServices;
  14. }
  15. public ActionResult FormsAuthenticationSignIn(UserViewModel model)
  16. {
  17.  
  18. bool isSuccessful = false;
  19. UserModel user = null;
  20. if (ModelState.IsValid)
  21. {
  22.  
  23. string userLogin = model.UserLogin;
  24.  
  25. if (UserServices.IsPasswordReset(userLogin))
  26. {
  27. return View("ChangePassword");
  28. }
  29. else
  30. {
  31.  
  32. string password = model.Password;
  33. bool rememberMe = model.RememberMe;
  34. string remoteIP = Request.UserHostAddress;
  35. user = userServices.Authenticate(Utilities.Constants.SalesTeamRole, userLogin, password, remoteIP);
  36.  
  37.  
  38. if (user != null)
  39. {
  40. formsAuthentication.SetAuthCookie(this.HttpContext, UserAuthenticationTicketBuilder.CreateAuthenticationTicket(user, rememberMe));
  41. isSuccessful = true;
  42.  
  43. }
  44.  
  45. }
  46. }
  47. if (isSuccessful)
  48. {
  49. return RedirectToAction("Index", "Dashboard", new { area = "SalesTeam" });
  50. }
  51. else
  52. {
  53. TempData["LoginError"] = "InvalidCredentials";
  54. return this.RedirectToAction("Index", "Home");
  55. }
  56.  
  57. }
  58.  
  59.  
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement