Esempio n. 1
0
        public async Task <IActionResult> Login([FromBody] LoginCredential credentials)
        {
            Domain.UserQuiz user = await userManager.FindByEmailAsync(credentials.Username);

            if (user != null && await userManager.CheckPasswordAsync(user, credentials.Password))
            {
                await this.signManager.SignInAsync(user, isPersistent : false);

                return(Ok(new ResultOperationWithObject(true, new { Token = CreateToken(user.Id) })));
            }

            return(Ok(new ResultOperation("Username or password invalid!")));
        }
Esempio n. 2
0
        public IActionResult Post([FromBody] UserViewModel entity)
        {
            Domain.UserQuiz user = new Domain.UserQuiz()
            {
                Email    = entity.Email,
                UserName = entity.Username
            };

            var result = this.userManager.CreateAsync(user, entity.Password).Result;

            if (!result.Succeeded)
            {
                return(Ok(new ResultOperationWithObject(result.Errors.Select(r => r.Description).ToList(), entity)));
            }

            this.signManager.SignInAsync(user, isPersistent: false);

            return(Ok(new ResultOperationWithObject(true, new { Token = CreateToken(user.Id) })));
        }