Exemplo n.º 1
0
        public async Task <ActionResult> Reg([FromBody] LoginPassword loginPassword)
        {
            var user = await userManager.FindByNameAsync(loginPassword.Login);

            if (user != null)
            {
                return(BadRequest());
            }

            var res = await userManager.CreateAsync(new IdentityUser(loginPassword.Login), loginPassword.Password);

            if (!res.Succeeded)
            {
                return(BadRequest());
            }

            return(Ok());
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Auth([FromBody] LoginPassword loginPassword)
        {
            var user = await userManager.FindByNameAsync(loginPassword.Login);

            if (user is null)
            {
                return(Unauthorized());
            }

            if (!await userManager.CheckPasswordAsync(user, loginPassword.Password))
            {
                return(Unauthorized());
            }

            return(Ok(new
            {
                AccessToken = GenerateAccessToken(user.Id)
            }));
        }