public ExecResult AddNewAccount(string defaultUserName = null) { WsAccountLoginInfo userCredential = _uiProvider.PromptUserCredential(defaultUserName); if (userCredential != null) { if (_accountAccessors.Exists(a => a.FileName.Equals(userCredential.UserName, StringComparison.InvariantCultureIgnoreCase))) { _uiProvider.ShowMessage(string.Format(Resources.TextResource.AccountExists, userCredential.UserName), false); } else if (WsAccountAccessor.TryRegisterAccount(_accountRepository, _uiProvider, userCredential, out WsAccountAccessor newAccountAccessor)) { _accountAccessors.Add(newAccountAccessor); return(ExecResult.SymLink(@"/")); } else { _uiProvider.ShowMessage(Resources.TextResource.WrongLogin, false); } } return(ExecResult.Ok); }
public async Task <SuccessAccountRegistrationInfo> TryRegisterAccount(WsAccountLoginInfo userCredential) { if (userCredential == null) { throw new ArgumentNullException(nameof(userCredential)); } if (_accounts.Exists(a => a.UserName.Equals(userCredential.UserName, StringComparison.InvariantCultureIgnoreCase))) { throw new ArgumentException($"Account {userCredential.UserName} is already registered.", nameof(userCredential)); } WsApiClient apiClient = new WsApiClient(GetDeviceUuid()); RegisterAccountSecretStore registerSecretStore = new RegisterAccountSecretStore(userCredential.UserPassword); bool successLogin = await apiClient.Login(userCredential.UserName, registerSecretStore, userCredential.RememberUserPassword?registerSecretStore : null); if (successLogin) { WsAccount newAccount = new WsAccount(Save, _protector, userCredential.UserName, registerSecretStore.UserPasswordHash); _accounts.Add(newAccount); Save(); return(new SuccessAccountRegistrationInfo(newAccount, apiClient)); } return(null); }
public static bool TryRegisterAccount(WsAccountRepository accountRepository, TcUIProvider uiProvider, WsAccountLoginInfo userCredential, out WsAccountAccessor accountAccessor) { WsAccountRepository.SuccessAccountRegistrationInfo successRegistration; using (ThreadKeeper exec = new ThreadKeeper()) { successRegistration = exec.ExecAsync((cancellationToken) => accountRepository.TryRegisterAccount(userCredential)); } if (successRegistration != null) { accountAccessor = new WsAccountAccessor(successRegistration.Account, uiProvider, successRegistration.ConnectedApiClient); return(true); } accountAccessor = null; return(false); }