コード例 #1
0
        public async Task <ActionResult <SharedAccount> > CreateSharedAccount(CreateSharedAccountDto sharedAccountDto)
        {
            SharedAccount createdAccount;

            try
            {
                var sharedAccount = new SharedAccountAddModel()
                {
                    Name      = sharedAccountDto.Name,
                    Urls      = sharedAccountDto.Urls,
                    Apps      = sharedAccountDto.Apps,
                    LoginType = sharedAccountDto.LoginType,
                    Login     = sharedAccountDto.Login,
                    Domain    = sharedAccountDto.Domain,
                    Password  = sharedAccountDto.Password,
                    OtpSecret = sharedAccountDto.OtpSecret
                };

                createdAccount = await _sharedAccountService.CreateSharedAccountAsync(sharedAccount);
            }
            catch (AlreadyExistException ex)
            {
                return(BadRequest(new { error = ex.Message }));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(StatusCode(500, new { error = ex.Message }));
            }

            return(CreatedAtAction("GetSharedAccountById", new { id = createdAccount.Id }, createdAccount));
        }
コード例 #2
0
ファイル: SharedAccountService.cs プロジェクト: minkione/HES
        public async Task <SharedAccount> CreateSharedAccountAsync(SharedAccountAddModel sharedAccountModel)
        {
            if (sharedAccountModel == null)
            {
                throw new ArgumentNullException(nameof(sharedAccountModel));
            }

            _dataProtectionService.Validate();

            var sharedAccount = new SharedAccount()
            {
                Name              = sharedAccountModel.Name,
                Urls              = Validation.VerifyUrls(sharedAccountModel.Urls),
                Apps              = sharedAccountModel.Apps,
                Login             = await ValidateAccountNameAndLoginAsync(sharedAccountModel.Name, sharedAccountModel.GetLogin()),
                LoginType         = sharedAccountModel.LoginType,
                Password          = _dataProtectionService.Encrypt(sharedAccountModel.Password),
                PasswordChangedAt = DateTime.UtcNow
            };

            if (!string.IsNullOrWhiteSpace(sharedAccountModel.OtpSecret))
            {
                Validation.VerifyOtpSecret(sharedAccountModel.OtpSecret);
                sharedAccount.OtpSecret          = _dataProtectionService.Encrypt(sharedAccountModel.OtpSecret);
                sharedAccount.OtpSecretChangedAt = DateTime.UtcNow;
            }

            return(await _sharedAccountRepository.AddAsync(sharedAccount));
        }
コード例 #3
0
        protected override async Task OnInitializedAsync()
        {
            try
            {
                SharedAccountService           = ScopedServices.GetRequiredService <ISharedAccountService>();
                TemplateService                = ScopedServices.GetRequiredService <ITemplateService>();
                RemoteDeviceConnectionsService = ScopedServices.GetRequiredService <IRemoteDeviceConnectionsService>();

                Templates = await TemplateService.GetTemplatesAsync();

                SharedAccount = new SharedAccountAddModel();
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.Message);
                await ToastService.ShowToastAsync(ex.Message, ToastType.Error);
                await ModalDialogCancel();
            }
        }