Esempio n. 1
0
        public async Task <bool> ChangeUserData(UserChangeDTO user)
        {
            byte[] PasswordSalt = null;
            byte[] Password     = null;
            if (user.Name != null)
            {
                user.Name = user.Name.ToLower();
            }
            if (user.Role != null)
            {
                user.Role = user.Role.ToLower();
            }
            if (user.Email != null)
            {
                user.Email = user.Email.ToLower();
                if (await _authRepository.UserExists(user.Email))
                {
                    return(false);
                }
            }
            if (user.Password != null)
            {
                using (var hmac = new System.Security.Cryptography.HMACSHA512())
                {
                    PasswordSalt = hmac.Key;
                    Password     = hmac.ComputeHash(System.Text.Encoding.UTF8.GetBytes(user.Password));
                }
            }
            await _authRepository.Update(user.Id, user.Name, user.Role, user.Email, Password, PasswordSalt, user.isActive);

            return(true);
        }
Esempio n. 2
0
        public async Task <IActionResult> ChangeUserData(UserChangeDTO change)
        {
            if (change.Password != null && change.ReinputPassword != null)
            {
                if (!_authService.CheckPassword(change.Password, change.ReinputPassword))
                {
                    return(BadRequest("As senhas não são iguais."));
                }
                ;
            }
            bool response = await _authService.ChangeUserData(change);

            if (response)
            {
                return(Ok(response));
            }
            return(BadRequest("Não foi possivel atualizar o usuário"));
        }