コード例 #1
0
        public async Task <IActionResult> AuthenticateUserAsync([FromBody] MyUserLogin loginCreds)
        {
            var result = await _signInManager.PasswordSignInAsync(loginCreds.Username, loginCreds.Password, true, false);

            if (result.Succeeded)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
コード例 #2
0
        public async Task <IActionResult> PostAsync([FromBody] MyUserLogin loginCreds)
        {
            var result = await _userManager.CreateAsync(new User()
            {
                UserName = loginCreds.Username
            }, loginCreds.Password);

            if (result.Succeeded)
            {
                return(Ok());
            }
            else
            {
                Dictionary <string, IdentityError> dict = result.Errors.ToDictionary(e => e.Code);

                bool length    = dict.ContainsKey("PasswordTooShort");
                bool upper     = dict.ContainsKey("PasswordRequiresUpper");
                bool lower     = dict.ContainsKey("PassowrdRequiresLower");
                bool number    = dict.ContainsKey("PasswordRequiresDigit");
                bool duplicate = dict.ContainsKey("DuplicateUserName");

                return(BadRequest(new { length, upper, lower, number, duplicate }));
            }
        }