Exemplo n.º 1
0
        public async Task <IActionResult> AddPassword(AddPasswordDto passwordInfo)
        {
            var user = await this.UserManager.FindByIdAsync(passwordInfo.ID.ToString());

            #region [Authorization]
            var result = await this.AuthorizationService.AuthorizeAsync
                         (
                this.User, user, nameof(KindlyPolicies.AllowIfOwner)
                         );

            if (result.Succeeded == false)
            {
                return(this.Unauthorized());
            }
            #endregion

            var identityResult = await this.UserManager.AddPasswordAsync(user, passwordInfo.Password);

            if (identityResult.Succeeded)
            {
                return(this.Ok(new LoginResponseDto(await this.GenerateUserDto(user), await this.GenerateLoginToken(user))));
            }
            else
            {
                return(this.Unauthorized());
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> AddPassword([FromBody] AddPasswordDto addPasswordDto)
        {
            var result = await _profileService.AddPassword(addPasswordDto, UserId);

            if (!result.Succedeed)
            {
                return(BadRequest());
            }

            return(NoContent());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> AddPassword([FromBody] AddPasswordDto addPasswordDto)
        {
            var userId = User.GetUserId();

            var addPasswordResult = await _changePasswordService.AddPassword(addPasswordDto, userId);

            if (addPasswordResult != null && addPasswordResult.Succeeded)
            {
                _logger.LogInformation($"User with id: {userId} added password");
                return(NoContent());
            }
            _logger.LogInformation($"Ivalid password adding as a user with id: {userId}");
            return(BadRequest());
        }
        public async Task <IdentityResult> AddPassword(AddPasswordDto addPasswordDto, string userId)
        {
            var user = await _userManager.Users.FirstOrDefaultAsync(x => x.Id == userId);

            var hasUserPassword = await _userManager.HasPasswordAsync(user);

            if (user == null || hasUserPassword)
            {
                return(null);
            }

            var addResult = await _userManager.AddPasswordAsync(user, addPasswordDto.NewPassword);

            return(addResult);
        }
        private async Task <Result> AddPassword(AddPasswordDto addPasswordDto, User user)
        {
            var identityResult = await _userManager.AddPasswordAsync(user, addPasswordDto.Password);

            return(identityResult.ToResult());
        }
 public async Task <Result> AddPassword(AddPasswordDto addPasswordDto, string userId)
 {
     return(await ProfileModificationAction(AddPassword, addPasswordDto, userId));
 }