Пример #1
0
        public async Task <IActionResult> Login([FromBody] credentials credentials)
        {
            var result = await signInManager.PasswordSignInAsync(credentials.Email, credentials.Password, false, false);

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

            return(Ok(CreateToken(user)));
        }
Пример #2
0
        public async Task <IActionResult> Register([FromBody] credentials credentials)
        {
            var user = new IdentityUser {
                UserName = credentials.Email, Email = credentials.Email
            };
            var result = await userManager.CreateAsync(user, credentials.Password);

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

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