Exemple #1
0
        public async Task <IActionResult> Login([FromBody] LoginDTO model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var user = await this.userManager.FindByEmailAsync(model.Email);

            if (user == null)
            {
                return(NotFound("User not found"));
            }

            var signInResult = await this.PasswordSignInAsync(model.Email, model.Password);

            if (!signInResult.Succeeded)
            {
                return(BadRequest("Authorization failed"));
            }

            var token = new AuthJwtTokenDTO();

            try
            {
                token.Token = await this.accountService.ActivateAccountByIdAsync(this.User, user, user.Id);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            return(Ok(token));
        }
Exemple #2
0
        public async Task <IActionResult> GetMyToken()
        {
            var token = new AuthJwtTokenDTO();

            try
            {
                token.Token = await this.accountService.GetCurrentTokenAsync();
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            return(Ok(token));
        }
        public async Task <IActionResult> ActivateAccount([FromBody] ActivateAccountDTO model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var token = new AuthJwtTokenDTO();

            try
            {
                token.Token = await this.accountService.ActivateAccountByIdAsync(model.AccountId);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
            return(Ok(token));
        }