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

            var response = new LoginResponseModel(login);

            await ExpandAsync(login, response, expand, null);

            return(response);
        }
Exemplo n.º 2
0
        public async Task <LoginResponseModel> Put(string id, [FromBody] LoginRequestModel model, string[] expand = null)
        {
            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.ToCipher(login));

            var response = new LoginResponseModel(login);

            await ExpandAsync(login, response, expand, null);

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

            if (login == null || !login.OrganizationId.HasValue ||
                !_currentContext.OrganizationAdmin(login.OrganizationId.Value))
            {
                throw new NotFoundException();
            }

            var userId = _userService.GetProperUserId(User).Value;
            await _cipherService.SaveAsync(model.ToCipher(login), userId, true);

            var response = new LoginResponseModel(login);

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

            if (login == null || !login.OrganizationId.HasValue ||
                !_currentContext.OrganizationAdmin(login.OrganizationId.Value))
            {
                throw new NotFoundException();
            }

            // object cannot be a descendant of CipherDetails, so let's clone it.
            var cipher = Core.Utilities.CoreHelpers.CloneObject(model.ToCipher(login));
            await _cipherService.SaveAsync(cipher, userId, true);

            var response = new LoginResponseModel(cipher, _globalSettings, login.OrganizationUseTotp);

            return(response);
        }