Esempio n. 1
0
        public async Task <IActionResult> Index(Accountmodels model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var result = _accountService.AuthenticationUser(model.Password, model.User);

            if (result.Item2 == true)
            {
                var claims = new List <Claim> {
                    new Claim(ClaimTypes.Name, Convert.ToString(result.Item1)),
                    new Claim(ClaimTypes.Role, result.Item3),
                    new Claim(ClaimTypes.GivenName, result.Item3)
                };
                var authProperties = new AuthenticationProperties {
                };
                var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
                await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity), authProperties);

                if (!string.IsNullOrEmpty(model.ReturnUrl))
                {
                    return(Redirect(model.ReturnUrl));
                }

                return(Redirect("home/index"));
            }
            else
            {
                ModelState.AddModelError("", "Fel lösenord eller användanamn");
                return(View(model));
            }
        }
        public ActionResult Index(Accountmodels model)
        {
            if (!ModelState.IsValid)
            {
                // om inte rätt format
                return(View(model));
            }
            Accountservice acc    = new Accountservice();
            var            result = acc.AuthenticationUser(model.Password, model.user);

            if (result.Item2 == true)
            {
                var identity = new ClaimsIdentity(new[] {
                    new Claim(ClaimTypes.Name, Convert.ToString(result.Item1)),
                    new Claim(ClaimTypes.Role, result.Item3),
                    new Claim(ClaimTypes.GivenName, result.Item3)
                }, "ApplicationCookie");

                var ctx         = Request.GetOwinContext();
                var authManager = ctx.Authentication;
                authManager.SignIn(identity);
                if (!string.IsNullOrEmpty(Request.QueryString["ReturnUrl"]))
                {
                    return(Redirect(Request.QueryString["ReturnUrl"]));
                }

                return(Redirect("home/index"));
            }
            else
            {
                ModelState.AddModelError("", "Fel lösenord eller användanamn");
                return(View(model));
            }
        }
Esempio n. 3
0
        public ActionResult Forgetpassword(Accountmodels model)
        {
            bool result = _accountService.Forgetpassword(model.User);

            if (result)
            {
                return(RedirectToAction("Index", "Home"));
            }
            ModelState.AddModelError("", "Användaren finns inte eller så är kontot inte aktiverat");
            return(View(model));
        }