Esempio n. 1
0
        //
        // POST: /Account/LogOff
        //[HttpPost]
        //[ValidateAntiForgeryToken]
        public ActionResult LogOff()
        {
            if (User.Identity.IsAuthenticated)
            {
                // remove temp database account
                var username = User.Identity.GetUserId();
                TempDbServiceOj.RemoveUserLogin(username);

                AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
            }

            return(RedirectToAction("Login", "Account"));
        }
Esempio n. 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);

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

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

            return(View(model));
        }