Exemplo n.º 1
0
        public async Task <LoginResponseModel> Post([FromBody] LoginRequestModel model)
        {
            var userId = _userService.GetProperUserId(User).Value;
            var login  = model.ToCipherDetails(userId);
            await _cipherService.SaveAsync(login);

            var response = new LoginResponseModel(login);

            return(response);
        }
Exemplo n.º 2
0
        public async Task <LoginResponseModel> Put(string id, [FromBody] LoginRequestModel model)
        {
            var userId = _userService.GetProperUserId(User).Value;
            var login  = await _cipherRepository.GetByIdAsync(new Guid(id), _userService.GetProperUserId(User).Value);

            if (login == null || login.Type != Core.Enums.CipherType.Login)
            {
                throw new NotFoundException();
            }

            await _cipherService.SaveAsync(model.ToCipherDetails(login));

            var response = new LoginResponseModel(login);

            return(response);
        }
Exemplo n.º 3
0
        public async Task <LoginResponseModel> Put(string id, [FromBody] LoginRequestModel model)
        {
            var userId = _userService.GetProperUserId(User).Value;
            var login  = await _cipherRepository.GetByIdAsync(new Guid(id), userId);

            if (login == null || login.Type != Core.Enums.CipherType.Login)
            {
                throw new NotFoundException();
            }

            var modelOrgId = string.IsNullOrWhiteSpace(model.OrganizationId) ? (Guid?)null : new Guid(model.OrganizationId);

            if (login.OrganizationId != modelOrgId)
            {
                throw new BadRequestException("Organization mismatch. Re-sync if you recently shared this login, " +
                                              "then try again.");
            }

            await _cipherService.SaveDetailsAsync(model.ToCipherDetails(login), userId);

            var response = new LoginResponseModel(login);

            return(response);
        }