protected void StartAuthentication(object sender, EventArgs e) { RestClient authenticationClient = UiDrivenLogin.Authenticate(TenantUrl, UserName_TextBox.Text + DefaultDomain); if (authenticationClient != null) { ProcessChallenges(authenticationClient.ChallengeCollection); Session["AuthenticaitonClient"] = authenticationClient; UserName_TextBox.Enabled = false; SocialLogin_Div.Visible = false; Register_HyperLink_Div.Visible = false; if (authenticationClient.AllowPasswordReset) { ForgotPass_Button.Visible = true; } RememberMe_Div.Visible = true; StartOver_Button.Visible = true; } else { //There was an error Login_Div.Visible = false; FailureText.Text = "There was an unexpected error. Please contact your system administrator. Click here to <a href=\"Login.aspx\">start over.</a>"; ErrorMessage.Visible = true; } }
protected void Submit_UserModify(object sender, EventArgs e) { //Create a new client to store authentication RestClient authenticationClient = UiDrivenLogin.Authenticate(TenantUrl, AdminServiceAccount); //Parse result challenge list. This is a service account so we can assume the results will be password and that there will only be one result. Dictionary <string, dynamic> mech = authenticationClient.ChallengeCollection[0]["Mechanisms"][0]; //Login for service account is assumed to only require password and no MFA. if (mech["AnswerType"] == "Text") { //Call advance authentication with our service account credentials UiDrivenLogin.AdvanceForMech(authenticationClient, authenticationClient.TenantId, authenticationClient.SessionId, true, mech, null, AdminServicePass); } //Something other then text was returned which indicates that the service account is not set up correctly. else { FailureText.Text = "The service account is not set up correctly. It should only require a password an no MFA."; ErrorMessage.Visible = true; UserInfo_div.Visible = false; MyAccount_Start_div.Visible = false; } //Create a new userManagementClient and pass our authenticated rest client from our login call. UserManagement userManagementClient = new UserManagement(authenticationClient); CDUser cUser = new CDUser(); cUser.Name = LoginName.Text + "@" + Alias_DropDownList.SelectedItem.ToString(); cUser.ID = UserUUID.Text; cUser.DisplayName = DisplayName.Text; cUser.Mail = Email.Text; cUser.OfficeNumber = OfficeNumber.Text; cUser.MobileNumber = MobileNumber.Text; cUser.HomeNumber = HomeNumber.Text; Dictionary <string, dynamic> modifyUserResult = userManagementClient.ChangeUser(cUser, InEverybodyRole.Checked); if (modifyUserResult["success"]) { SuccessText.Text = "User " + LoginName.Text + " was successfully modified."; SuccessMessage.Visible = true; //hide unneeded elements. UserInfo_div.Visible = false; MyAccount_Start_div.Visible = false; } else { FailureText.Text = "There was an error modifying the user: "******"Message"]; ErrorMessage.Visible = true; //hide unneeded elements. UserInfo_div.Visible = false; MyAccount_Start_div.Visible = false; } }
protected void GetUserInfo(object sender, EventArgs e) { Alias_DropDownList.Items.Clear(); //Create a new client to store authentication RestClient serviceAuthenticationClient = UiDrivenLogin.Authenticate(TenantUrl, AdminServiceAccount); //Parse result challenge list. This is a service account so we can assume the results will be password and that there will only be one result. Dictionary <string, dynamic> mech = serviceAuthenticationClient.ChallengeCollection[0]["Mechanisms"][0]; //Login for service account is assumed to only require password and no MFA. if (mech["AnswerType"] == "Text") { //Call advance authentication with our service account credentials UiDrivenLogin.AdvanceForMech(serviceAuthenticationClient, serviceAuthenticationClient.TenantId, serviceAuthenticationClient.SessionId, true, mech, null, AdminServicePass); } //Something other then text was returned which indicates that the service account is not set up correctly. else { FailureText.Text = "The service account is not set up correctly. It should only require a password an no MFA."; ErrorMessage.Visible = true; UserInfo_div.Visible = false; MyAccount_Start_div.Visible = false; } //Pull authentication client from session RestClient authenticationClient = (RestClient)Session["AuthenticaitonClient"]; //Create a new userManagementClient and pass our authenticated rest client from our login call. UserManagement userManagementClient = new UserManagement(authenticationClient); UserManagement serviceUserManagementClient = new UserManagement(serviceAuthenticationClient); Dictionary <string, dynamic> getAliases = userManagementClient.GetAliasesForTenant(); //Get a list of all tenant Aliases int iCount = 0; foreach (var alias in getAliases["Result"]["Results"]) { Alias_DropDownList.Items.Insert(0, new ListItem(alias["Row"]["ID"], iCount.ToString())); iCount++; } //Get User Info Dictionary <string, dynamic> getUser = userManagementClient.GetUser(); Dictionary <string, dynamic> getUserResult = getUser["Result"]; //Get User UUID Dictionary <string, dynamic> queryResult = serviceUserManagementClient.Query(@"select ID from cduser where Name ='" + getUserResult["Name"] + "'"); int queryCount = queryResult["Count"]; if (queryCount == 1) { //split the username and domain name. add user name into LoginName text box and select the correct domain in the alias dropdown. string s = getUserResult["Name"]; string[] userName = s.Split('@'); Alias_DropDownList.Items.FindByText(userName[1]).Selected = true; //populate user info LoginName.Text = userName[0]; UserUUID.Text = queryResult["Results"][0]["Row"]["ID"]; Email.Text = getUserResult["Mail"]; //check that optional attributes are populated if (getUserResult.ContainsKey("DisplayName")) { DisplayName.Text = getUserResult["DisplayName"]; } if (getUserResult.ContainsKey("OfficeNumber")) { OfficeNumber.Text = getUserResult["OfficeNumber"]; } if (getUserResult.ContainsKey("MobileNumber")) { MobileNumber.Text = getUserResult["MobileNumber"]; } if (getUserResult.ContainsKey("HomeNumber")) { HomeNumber.Text = getUserResult["HomeNumber"]; } if (getUserResult.ContainsKey("InEverybodyRole")) { InEverybodyRole.Checked = getUserResult["InEverybodyRole"]; } //show/hide elements UserInfo_div.Visible = true; } else { FailureText.Text = "There was an error getting the logged in users ID."; //hide unneeded elements. ErrorMessage.Visible = true; UserInfo_div.Visible = false; MyAccount_Start_div.Visible = false; } }
protected void Submit_Registration(object sender, EventArgs e) { //Create a new client to store authentication RestClient authenticationClient = UiDrivenLogin.Authenticate(TenantUrl, AdminServiceAccount); //Parse result challenge list. This is a service account so we can assume the results will be password and that there will only be one result. Dictionary <string, dynamic> mech = authenticationClient.ChallengeCollection[0]["Mechanisms"][0]; //Login for service account is assumed to only require password and no MFA. if (mech["AnswerType"] == "Text") { //Call advance authentication with our service account credentials UiDrivenLogin.AdvanceForMech(authenticationClient, authenticationClient.TenantId, authenticationClient.SessionId, true, mech, null, AdminServicePass); } //Something other then text was returned which indicates that the service account is not set up correctly. else { FailureText.Text = "The service account is not set up correctly. It should only require a password an no MFA."; ErrorMessage.Visible = true; Registration.Visible = false; //Hide our registration form. } //Set up dictionary to hold our create user results. Dictionary <string, dynamic> createUserResult = null; //Check if the passwords match if (Password.Text == Confirm_Password.Text) { //Create a new userManagementClient and pass our authenticated rest client from our login call. UserManagement userManagementClient = new UserManagement(authenticationClient); //Call the create user api and pass the contents of our registration form. CDUser cUser = new CDUser(); cUser.Name = LoginName.Text + DefaultDomain; cUser.Mail = Email.Text; cUser.DisplayName = DisplayName.Text; cUser.Password = Password.Text; cUser.OfficeNumber = OfficeNumber.Text; cUser.MobileNumber = MobileNumber.Text; cUser.HomeNumber = HomeNumber.Text; createUserResult = userManagementClient.CreateUser(cUser, false, false, false, false, true); } //The passwords did not match else { FailureText.Text = "Password and Confirm Password do not match. Please refresh the page and try again."; ErrorMessage.Visible = true; Registration.Visible = false; //Hide our registration form. } //Check if the create user call was successful and present the results if it was. if (createUserResult["success"]) { SuccessText.Text = "User " + LoginName.Text + " was successfully created. Please here to <a href=\"Login.aspx\">login."; SuccessMessage.Visible = true; Registration.Visible = false; //Hide our registration form. } //The create user api call was not successful. Present the returned error message from the api. else { FailureText.Text = createUserResult["Message"]; ErrorMessage.Visible = true; Registration.Visible = false; //Hide our registration form. } }