Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Mynamespace
- {
- public class AuthenticationController : AuthorizedController
- {
- private readonly IFormsAuthentication formsAuthentication;
- private readonly IUserServices userServices;
- [InjectionConstructor]
- public AuthenticationController(IFormsAuthentication formsAuthentication, IUserServices userServices, IServiceLocator servicelocator)
- : base(userServices, servicelocator)
- {
- this.formsAuthentication = formsAuthentication;
- this.userServices = userServices;
- }
- public ActionResult FormsAuthenticationSignIn(UserViewModel model)
- {
- bool isSuccessful = false;
- UserModel user = null;
- if (ModelState.IsValid)
- {
- string userLogin = model.UserLogin;
- if (UserServices.IsPasswordReset(userLogin))
- {
- return View("ChangePassword");
- }
- else
- {
- string password = model.Password;
- bool rememberMe = model.RememberMe;
- string remoteIP = Request.UserHostAddress;
- user = userServices.Authenticate(Utilities.Constants.SalesTeamRole, userLogin, password, remoteIP);
- if (user != null)
- {
- formsAuthentication.SetAuthCookie(this.HttpContext, UserAuthenticationTicketBuilder.CreateAuthenticationTicket(user, rememberMe));
- isSuccessful = true;
- }
- }
- }
- if (isSuccessful)
- {
- return RedirectToAction("Index", "Dashboard", new { area = "SalesTeam" });
- }
- else
- {
- TempData["LoginError"] = "InvalidCredentials";
- return this.RedirectToAction("Index", "Home");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement