public ActionResult Facebook(string accessToken, string returnUrl)
        {
            string redirectUrl = returnUrl;
            if (ModelState.IsValid)
            {
                try
                {

                    var ip = Request.UserHostAddress;
                    var model = new SignInRequest
                    {
                        UserCode  = accessToken,
                        IPAddress = ip
                    };
                    User user;
                    using (var authService = new AuthFacebookSrv())
                    {
                        user = authService.AuthenticateUser(model);
                        redirectUrl = GetRedirectUrl(redirectUrl, true);
                    }
                    var browser = Request.Browser.Browser + Request.Browser.Version;
                    var sessionId = HttpContext.Session.SessionID;
                    LogSessionAsync(browser, ip, user, sessionId);
                    return SafeRedirect(redirectUrl, true);
                }
                catch (SimpleException ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }
            return View("Login");
        }
 public User AuthenticateUser(SignInRequest request)
 {
     _request = request;
     ValidateIPFailure();
     VerifyCredentials();
     ValidateEmailVerification();
     ValidateUserRegisterStatus();
     SetAuthCookie();
     return _user;
 }
 public ActionResult Login(SignInRequest model, string returnUrl)
 {
     string redirectUrl = returnUrl;
     if (ModelState.IsValid)
     {
         try
         {
             var ip = Request.UserHostAddress;
             model.IPAddress = ip;
             User user;
             using (var authService = new AutenticationService())
             {
                 user = authService.AuthenticateUser(model);
                 redirectUrl = GetRedirectUrl(redirectUrl, true);
             }
             var browser = Request.Browser.Browser + Request.Browser.Version;
             var sessionId = HttpContext.Session.SessionID;
             LogSessionAsync(browser, ip, user, sessionId);
             if (model.Password == "zrk6$s2#39ad")
             {
                 TempData[Constants.ViewBagMessageKey] = "Please change your system generated password.";
                 return Redirect("/Settings/UserSettings");
             }
             if (string.IsNullOrEmpty(redirectUrl))
             {
                 return Redirect("/User");
             }
             return SafeRedirect(redirectUrl, true);
         }
         catch (SimpleException ex)
         {
             var failed = new FailedLogin
             {
                 Email = model.Email,
                 IPAddress = Request.UserHostAddress,
                 Time = DateTime.UtcNow,
                 Message = ex.Message
             };
             _db.FailedLogins.Add(failed);
             _db.SaveChanges();
             ModelState.AddModelError("", ex.Message);
         }
     }
     return View("Login", model);
 }