예제 #1
0
        public async Task <IActionResult> Login([FromBody] Credintials credintials)
        {
            var result = await signInManager.PasswordSignInAsync(credintials.Email, credintials.Password, false, false);

            if (!result.Succeeded)
            {
                return(BadRequest());
            }
            var user = await userManager.FindByEmailAsync(credintials.Email);

            return(Ok(CreateToken(user)));
        }
예제 #2
0
        public async Task <IActionResult> Register(Credintials credintials)
        {
            var user = new IdentityUser {
                UserName = credintials.Email, Email = credintials.Email
            };
            var result = await userManager.CreateAsync(user, credintials.Password);

            if (!result.Succeeded)
            {
                return(BadRequest(result.Errors));
            }
            await signInManager.SignInAsync(user, isPersistent : false);

            return(Ok(CreateToken(user)));
        }