Beispiel #1
0
        public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = Db.Users.FirstOrDefault(x => x.UserName.Equals(model.UserName, StringComparison.InvariantCultureIgnoreCase));
                if (user == null)
                {
                    ViewData["Message"] = "Kullanıcı adı yanlış! ";
                    return(View(model));
                }

                if (signInManager.GetClaimsPrincipal(model.UserName, model.Password, user, out ClaimsPrincipal principal))
                {
                    await HttpContext.SignInAsync(principal);

                    return(RedirectToLocal(returnUrl));
                }
                else
                {
                    ViewData["Message"] = "Yanlış şifre! ";
                }
            }

            return(View(model));
        }
        public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = userDb.Get(new User {
                    UserName = model.UserName
                });
                if (user == null)
                {
                    ViewData["Message"] = "Kullanıcı adı yanlış! ";
                    return(View(model));
                }

                if (signInManager.GetClaimsPrincipal(model.UserName, model.Password,
                                                     user, out ClaimsPrincipal principal))
                {
                    await HttpContext.SignInAsync(principal);

                    return(RedirectToLocal(returnUrl));
                }
                else
                {
                    ViewData["Message"] = "Yanlış şifre! ";
                }
            }

            return(View(model));
        }