Exemple #1
0
 protected void Session_OnEnd(object sender, EventArgs e)
 {
     if (User.Identity.IsAuthenticated)
     {
         var username = User.Identity.GetUserId();
         if (!string.IsNullOrWhiteSpace(username))
         {
             ITempDbService dbService = new TempDbService();
             dbService.RemoveUserLogin(username);
         }
     }
 }
Exemple #2
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            try
            {
                var user = DokmeeService.Login(model.UserName, model.Password, model.Type);
                if (user.IsCompleted)
                {
                    var ident = new ClaimsIdentity(
                        new[] {
                        // adding following 2 claim just for supporting default antiforgery provider
                        new Claim(ClaimTypes.NameIdentifier, model.UserName),
                        new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "ASP.NET Identity", "http://www.w3.org/2001/XMLSchema#string"),

                        new Claim(ClaimTypes.Name, model.UserName)
                    },
                        DefaultAuthenticationTypes.ApplicationCookie);

                    HttpContext.GetOwinContext()
                    .Authentication.SignIn(new AuthenticationProperties {
                        IsPersistent = false
                    }, ident);

                    TempDbService.SetUser(model.UserName, model.Password, model.Type);

                    return(RedirectToAction("AfterMyActionResult", "Home",
                                            new { username = model.UserName, password = model.Password, loginType = model.Type })); // auth succeed
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
            }

            return(View(model));
        }