Ejemplo n.º 1
0
        public async Task <UserDto> GetUserAsync(string email, string password)
        {
            var hashedPassword = PasswordManager.HashPassword(password);
            var user           = await _context.Users.FirstOrDefaultAsync(user => user.Email == email && user.Password == hashedPassword);

            return(user is null ? null : UserDto.FromUser(user));
        }
Ejemplo n.º 2
0
        //GET: api/Users?teamId=xxx
        public IEnumerable <UserDto> GetUsers(long teamId)
        {
            var users    = userService.GetUsers(teamId);
            var userDtos = users.Select(u => UserDto.FromUser(u));

            return(userDtos);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> PutUser(string id, [FromBody] UpdateUserDto request)
        {
            var user = await userManager.UpdateAsync(id, request.ToValues());

            var response = UserDto.FromUser(user, this);

            return(Ok(response));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> PutUser(string id, [FromBody] UpdateUserDto request)
        {
            var user = await userService.UpdateAsync(id, request.ToValues(), ct : HttpContext.RequestAborted);

            var response = UserDto.FromUser(user, Resources);

            return(Ok(response));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> PostUser([FromBody] CreateUserDto request)
        {
            var user = await userService.CreateAsync(request.Email, request.ToValues());

            var response = UserDto.FromUser(user, Resources);

            return(Ok(response));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> PostUser([FromBody] CreateUserDto request)
        {
            var user = await userManager.CreateAsync(userFactory, request.ToValues());

            var response = UserDto.FromUser(user, this);

            return(Ok(response));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> PostUser([FromBody] CreateUserDto request)
        {
            var user = await userManager.CreateAsync(userFactory, request.ToValues());

            userEvents.OnUserRegistered(user);

            var response = UserDto.FromUser(user, Resources);

            return(Ok(response));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> LockUser(string id)
        {
            if (this.IsUser(id))
            {
                throw new ValidationException("Locking user failed.", new ValidationError("You cannot lock yourself."));
            }

            var user = await userManager.LockAsync(id);

            var response = UserDto.FromUser(user, this);

            return(Ok(response));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> UnlockUser(string id)
        {
            if (this.IsUser(id))
            {
                throw new DomainForbiddenException(T.Get("users.unlockYourselfError"));
            }

            var user = await userManager.UnlockAsync(id);

            var response = UserDto.FromUser(user, Resources);

            return(Ok(response));
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> GetUser(string id)
        {
            var user = await userManager.FindByIdWithClaimsAsync(id);

            if (user == null)
            {
                return(NotFound());
            }

            var response = UserDto.FromUser(user, Resources);

            return(Ok(response));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> GetUser(string id)
        {
            var entity = await userManager.FindByIdAsync(id);

            if (entity == null)
            {
                return(NotFound());
            }

            var response = UserDto.FromUser(entity);

            return(Ok(response));
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> LockUser(string id)
        {
            if (this.IsUser(id))
            {
                throw new DomainForbiddenException(T.Get("users.lockYourselfError"));
            }

            var user = await userService.LockAsync(id, HttpContext.RequestAborted);

            var response = UserDto.FromUser(user, Resources);

            return(Ok(response));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> GetUser(string id)
        {
            var user = await userService.FindByIdAsync(id, HttpContext.RequestAborted);

            if (user == null)
            {
                return(NotFound());
            }

            var response = UserDto.FromUser(user, Resources);

            return(Ok(response));
        }
Ejemplo n.º 14
0
        public IHttpActionResult GetUser(string id)
        {
            if (id == "current")
            {
                id = User.Identity.GetUserId();
            }
            User u = userService.FindUser(id);

            if (u == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(UserDto.FromUser(u)));
            }
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> GetUsers(string query)
        {
            try
            {
                var users = await userResolver.QueryByEmailAsync(query);

                var response = users.Where(x => !x.IsHidden()).Select(x => UserDto.FromUser(x, this)).ToArray();

                return(Ok(response));
            }
            catch (Exception ex)
            {
                log.LogError(ex, w => w
                             .WriteProperty("action", nameof(GetUsers))
                             .WriteProperty("status", "Failed"));
            }

            return(Ok(new UserDto[0]));
        }
Ejemplo n.º 16
0
        public IActionResult CreateUser([FromBody] UserCreateDto userDto)
        {
            if (userDto == null || !ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                var user = _userService.CreateUser(userDto);

                return(Ok(UserDto.FromUser(user)));
            }
            catch (Exception ex)
            {
                _logger.LogCritical($"Exception while creating user", ex);
                return(StatusCode(500, "A problem happened while handling your request."));
            }
        }
Ejemplo n.º 17
0
        public IActionResult GetById(int id)
        {
            try
            {
                var user = UserDto.FromUser(_userService.GetUserById(id));

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

                _logger.LogInformation($"User with id {id} was not found.");

                return(NotFound());
            }
            catch (Exception ex)
            {
                _logger.LogCritical($"Exception while getting user with id {id}", ex);
                return(StatusCode(500, "A problem happened while handling your request."));
            }
        }
        public async Task <IActionResult> Save(Guid id, [FromBody] UserDto user)
        {
            var ety = new EventStoreEntityDto {
                ID      = user.Id.ToString(),
                Version = user.Version.Value,
                Data    = user.ToUser()
            };

            var json = JsonConvert.SerializeObject(ety, new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });

            var client  = _httpClientFactory.CreateClient();
            var content = new StringContent(json, Encoding.UTF8, "application/json");
            var resp    = await client.PutAsync($"{_evtStoreBaseUrl}/{user.Id}", content);

            if (resp.StatusCode != HttpStatusCode.OK)
            {
                var err = await resp.Content.ReadAsStringAsync();

                return(StatusCode((int)resp.StatusCode, err));
            }

            var tmp = await resp.Content.ReadAsStringAsync();

            var respUser = JsonConvert.DeserializeObject <EventStoreEntityDto>(tmp);

            var result = new UserDto();

            result.FromUser(respUser.Data);
            result.Version = respUser.Version;

            await _daprClient.PublishEventAsync(_eventStoreOptions.TopicName, new UserUpdated
            {
                Id      = respUser.ID,
                Version = respUser.Version
            });

            return(Ok(result));
        }
Ejemplo n.º 19
0
        public async Task <IActionResult> GetUser(string id)
        {
            try
            {
                var entity = await userResolver.FindByIdOrEmailAsync(id);

                if (entity != null)
                {
                    var response = UserDto.FromUser(entity, this);

                    return(Ok(response));
                }
            }
            catch (Exception ex)
            {
                log.LogError(ex, w => w
                             .WriteProperty("action", nameof(GetUser))
                             .WriteProperty("status", "Failed"));
            }

            return(NotFound());
        }
Ejemplo n.º 20
0
        public void ApiRegisterCreatesAccountWhenValidInfoPosted()
        {
            var          user         = UserDto.FromUser(_facebookUser);
            var          credentials  = _facebookCredentials;
            var          verifyResult = _facebookResult;
            UserLoginDto login        = new UserLoginDto
            {
                Credentials = credentials,
                User        = user
            };
            var userManagerMock = new Mock <IUserManager>();

            userManagerMock.Setup(man => man.Find(It.Is <UserLoginInfo>(info => info.LoginProvider == credentials.Provider && info.ProviderKey == verifyResult.Id))).Returns <User>(null);
            var loginMock = new Mock <ILoginService>();

            loginMock.Setup(svc => svc.VerifyCredentials(credentials)).Returns(verifyResult);
            loginMock.Setup(svc => svc.CreateAccount(It.IsAny <User>(), It.IsAny <UserLoginInfo>())).Returns(true);
            var con      = new AccountsController(userManagerMock.Object, loginMock.Object);
            var response = con.Register(login);

            Assert.IsInstanceOfType(response, typeof(OkResult));
        }
Ejemplo n.º 21
0
        // GET: api/Users
        public IEnumerable <UserDto> GetUsers()
        {
            var users = userService.GetUsers();

            return(users.Select(u => UserDto.FromUser(u)));
        }
Ejemplo n.º 22
0
        public IEnumerable <UserDto> SearchUsers(string name)
        {
            IEnumerable <User> users = userService.SearchUsers(name);

            return(users.Select(u => UserDto.FromUser(u)));
        }
Ejemplo n.º 23
0
        public async Task <UserDto> GetUserByIdAsync(int id)
        {
            var user = await _context.Users.FirstOrDefaultAsync(b => b.UserId == id);

            return(user is null ? null : UserDto.FromUser(user));
        }