// Execute only after User Validation success public Networking.Models.CredentialsInfo GetLoggedUser() { if (ValidateUser()) { foreach (Networking.Models.CredentialsInfo credentialInfo in usersCredentials) { bool usernameEqual = credentialInfo.person.name.RemoveWhitespaces() == name.RemoveWhitespaces(); List <Networking.Models.Position.PositionType> userPositions = Builders.PositionBuilder.BuildFrom(CredentialsManagerService.shared.ValidateUser(name, password)); bool positionEqual = false; foreach (Networking.Models.Position.PositionType position in userPositions) { if (credentialInfo.position.type == position) { positionEqual = true; break; } } if (usernameEqual && positionEqual) { return(credentialInfo); } } } Console.WriteLine("GetLoggedUser Error: GetLoggedUser was executed before ValidateUser method, should not happen"); Networking.Models.CredentialsInfo failedCredentialsInfo = new Networking.Models.CredentialsInfo(); return(failedCredentialsInfo); }
private void StartNavigation(Networking.Models.CredentialsInfo credentialsInfo) { if (model.CheckUserStatus() == Models.RegistrationModel.UserType.Admin) { Hide(); AdminFlow.AdminOperationsForm newForm = new AdminFlow.AdminOperationsForm(); newForm.SetCurrentCredentialsInfo(credentialsInfo); newForm.Show(); } else if (model.CheckUserStatus() == Models.RegistrationModel.UserType.User) { Hide(); UserFlow.DetailsForm newForm = new UserFlow.DetailsForm(); newForm.SetCurrentCredentialsInfo(credentialsInfo); newForm.Show(); } }
private void loginButton_Click(object sender, EventArgs e) { if (model.ValidateUser()) { Networking.Models.CredentialsInfo credentialsInfo = model.GetLoggedUser(); if (credentialsInfo.id == -1) { StartFailureFlow(); } else { StartNavigation(credentialsInfo); } } else { StartFailureFlow(); } }
public static Dictionary <string, string> BuildFrom(Networking.Models.CredentialsInfo userInfo) { Dictionary <string, string> dataDictionary = new Dictionary <string, string>(); dataDictionary.Add(UserDataKeys.kUsername, userInfo.person.name); switch (userInfo.position.type) { case Position.PositionType.Driver: case Position.PositionType.Conductor: dataDictionary.Add(UserDataKeys.kAccessLevel, Convert.ToString((int)CredentialsManagerService.AccessLevel.User)); dataDictionary.Add(UserDataKeys.kPassword, ""); break; case Position.PositionType.Manager: dataDictionary.Add(UserDataKeys.kAccessLevel, Convert.ToString((int)CredentialsManagerService.AccessLevel.Admin)); dataDictionary.Add(UserDataKeys.kPassword, "admin"); break; } return(dataDictionary); }
public void SetCurrentCredentialsInfo(Networking.Models.CredentialsInfo credentials) { model.SetCredentialsInfo(credentials); SetupControls(); }