public void RemoveUserAccountProfile(UserAccountProfile accountProfile) { var profile = UserProfiles.FirstOrDefault((p) => p.InstitutionName == accountProfile.InstitutionName); if (profile == null) { return; } profile.Accounts.Remove(accountProfile); SaveUserProfile(); }
public UserProfileManager() { _userProfileFilePath = Path.Combine(Directory.GetCurrentDirectory(), @"UserProfile.json"); _companyProfileFilePath = Path.Combine(Directory.GetCurrentDirectory(), @"CompanyProfile.json"); CompanyProfiles = LoadCompanyProfiles(_companyProfileFilePath); UserProfiles = LoadUserProfiles(_userProfileFilePath); DataProviders = LoadUserProviders(UserProfiles); NewAccountViewModel.WhenNewProfileAdded.Subscribe((newProfile) => { if (UserProfiles.Contains(newProfile)) { var profile = UserProfiles.FirstOrDefault((p) => p.Equals(newProfile)); profile.Accounts = profile.Accounts.Union(newProfile.Accounts).ToList(); } else { UserProfiles.Add(newProfile); } SaveUserProfile(); }); }
public async Task Execute() { if (this.isValidated == false) { await Validate(); } if (this.credential.LoginID == "TST-USER" && this.credential.LoginPassword == "TST-PSSWRD") { this.accessToken = new AccessToken { LoginID = "TST-USER", IsLongTerm = true, UserID = new Guid(), UserName = "******" }; Guid g = Guid.Empty; Guid.TryParse("b79d510f-eaf3-439f-b884-931b179fe3d3", out g); this.accessToken.AccessTokenID = g; this.accessTokenID = g; this.httpStatusCode = HttpStatusCode.OK; Debug.Print("Login with test user"); return; } try { //If accessToken is null we are logging in for the first time if (this.accessToken == null) { if (this.httpStatusCode == System.Net.HttpStatusCode.OK) { // handle login/token-creation or simply create an anonymous token if (this.httpStatusCode == HttpStatusCode.OK) { if ((string.IsNullOrEmpty(this.credential.LoginID) == false) && (string.IsNullOrEmpty(this.credential.LoginPassword) == false)) { // Authenticate User Based on Login ID and Login Password // Only Daytona users are able to create a token and login at the same time User user = AuthenticateUserLogic.AuthenticateUser( this.databaseSettings, this.credential.LoginID, this.credential.LoginPassword); if (user != null) { this.accessTokenID = await AccessTokenLogic.CreateAccessTokenAsync(this.databaseSettings, user.UserID); } Debug.Print("[AccessTokensController.Post] Access Token Created = " + this.accessTokenID.ToString()); this.accessToken = await AccessTokenLogic.GetAccessTokenAsync(this.databaseSettings, this.accessTokenID); } } } } else { AuthenticationProfile authenticationProfile = new AuthenticationProfile { AutoLoginUserID = this.accessToken.UserID, AutoLoginIsActive = true }; // // The Access Token already exists so wee are just updating it // if ((string.IsNullOrEmpty(this.credential.LoginID) == false) && (string.IsNullOrEmpty(this.credential.LoginPassword) == false)) { // Attach a new user to an existing token if valid User user = AuthenticateUserLogic.AuthenticateUser( this.databaseSettings, this.credential.LoginID, this.credential.LoginPassword); if (user != null) { if (string.IsNullOrEmpty(this.credential.NewLoginPassword) == false) { UserProfiles userProfiles = await UserProfileLogic.UserProfileGet(this.databaseSettings, Guid.Empty, user.UserID); UserProfile userProfile = userProfiles.FirstOrDefault(); // we've made it this far, so no need to check the old password userProfile.Password = this.credential.NewLoginPassword; userProfile.IsPasswordChangeRequired = false; UserProfileChangePasswordCommand command = new UserProfileChangePasswordCommand( datastoreProfile: this.databaseSettings, effectiveUserID: user.UserID, userProfile: userProfile ); if (await command.Execute()) { // good to go } else { this.errorOut = command.ErrorOut; this.httpStatusCode = command.HttpStatusCode; return; } } } if (user == null) { this.accessToken = null; Debug.Print("[AccessTokensController.Post] User - Invalid Login or Password."); if (this.errorOut == null) { this.errorOut = new ErrorOut(20025, "Invalid Login or Password. (20025)"); } this.httpStatusCode = System.Net.HttpStatusCode.Unauthorized; } else { AccessTokenLogic.ChangeUser(this.databaseSettings, this.accessTokenID, user.UserID, this.credential.IsLongTerm); Debug.Print("[AccessTokensController.Post] User changed."); // Access Token has been changed, so reload it this.accessToken = AccessTokenLogic.GetAccessToken(this.databaseSettings, this.accessTokenID); } } else { // Clear the user off the token AccessTokenLogic.ChangeUser(this.databaseSettings, this.accessTokenID, authenticationProfile.AutoLoginUserID, false); Debug.Print("[AccessTokensController.Post] User cleared."); // Access Token has been changed, so reload it this.accessToken = AccessTokenLogic.GetAccessToken(this.databaseSettings, this.accessTokenID); } } } catch (Exception ex) { Debug.Print("[AccessTokensController.Post] Unhandled Exception: " + ex.ToString()); this.httpStatusCode = HttpStatusCode.InternalServerError; this.errorOut = new ErrorOut(0, "Unhandled Exception"); } if (this.httpStatusCode == System.Net.HttpStatusCode.OK) { if (this.accessToken == null) { Debug.Print("[AccessTokensController.Post] Returning Unauthorized."); if (this.errorOut == null && string.IsNullOrEmpty(this.credential.LoginID) == false) { this.errorOut = new ErrorOut(20025, "Invalid Login or Password. (20025)"); } this.httpStatusCode = HttpStatusCode.Unauthorized; } } }
public UserProfile FindUser(Func <UserProfile, bool> pred) { return(UserProfiles.FirstOrDefault(p => pred(p))); }