Exemplo n.º 1
0
        public async Task <bool> Login(JObject userJson)
        {
            var userInfo = JsonConvert.DeserializeObject <UserLoginModel>(userJson.ToString());

            if (!ModelState.IsValid)
            {
                return(false);
            }

            var user = await UserMgr.FindByEmailAsync(userInfo.Email);

            if (user != null &&
                await UserMgr.CheckPasswordAsync(user, userInfo.Password))
            {
                var identity = new ClaimsIdentity(IdentityConstants.ApplicationScheme);
                identity.AddClaim(new Claim(ClaimTypes.Name, user.UserName));

                await HttpContext.SignInAsync(IdentityConstants.ApplicationScheme,
                                              new ClaimsPrincipal(identity));

                return(true);
            }
            else
            {
                ModelState.AddModelError("", "Invalid UserName or Password");
                return(false);
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Login(string username, string password)
        {
            if (ModelState.IsValid)
            {
                var user = await UserMgr.FindByNameAsync(username);

                if (user != null && !user.EmailConfirmed &&
                    (await UserMgr.CheckPasswordAsync(user, password)))
                {
                    ModelState.AddModelError(string.Empty, "Email ainda não confirmado");
                    return(View());
                }

                var result = await SignInMgr.PasswordSignInAsync(username,
                                                                 password, false, false);

                if (result.Succeeded)
                {
                    return(RedirectToAction("index", "home"));
                }

                ModelState.AddModelError(string.Empty, "Invalid Login Attempt");
            }

            return(View());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> VerifyPassword(string password)
        {
            if (User?.Identity.IsAuthenticated == true)
            {
                var username = User?.Identity.Name;
                var user     = await UserMgr.FindByNameAsync(username);

                return(Ok(UserMgr.CheckPasswordAsync(user, password).Result));
            }
            return(Ok(false));
        }