public static void setPw(string username, string password) { try { AppsService service = new AppsService(DOMAIN, USERNAME, PASSWORD); UserEntry entry = service.RetrieveUser(username); entry.Login.Password = password; service.UpdateUser(entry); } catch (AppsException ex) { // Probably don't have a Google Apps account yet, do nothing if (ex.Reason == "EntityDoesNotExist") { } else { throw ex; } } }
private static void UserOperations(AppsService service) { // Create a new user. UserEntry insertedEntry = service.CreateUser(testUserName, "Jane", "Doe", "testuser-password"); Console.WriteLine("Created new user '{0}'", insertedEntry.Login.UserName); // Suspend the user. UserEntry suspendedEntry = service.SuspendUser(testUserName); Console.WriteLine("Suspended account for {0}", suspendedEntry.Login.UserName); // Restore the user. UserEntry restoredEntry = service.RestoreUser(testUserName); Console.WriteLine("Restored user {0}", restoredEntry.Login.UserName); // Query for a single user. UserEntry entry = service.RetrieveUser(testUserName); Console.WriteLine("Retrieved user {0}", entry.Login.UserName); // Query for a page of users. UserFeed feed = service.RetrievePageOfUsers(testUserName); entry = feed.Entries[0] as UserEntry; Console.WriteLine("Retrieved page of {0} users, beginning with '{1}'", feed.Entries.Count, entry.Login.UserName); // Query for all users. feed = service.RetrieveAllUsers(); entry = feed.Entries[0] as UserEntry; Console.WriteLine("Retrieved all {0} users in the domain, beginning with '{1}'", feed.Entries.Count, entry.Login.UserName); // Update the user's given name. restoredEntry.Name.GivenName = "John"; UserEntry updatedEntry = service.UpdateUser(entry); Console.WriteLine("Updated user with new given name '{0}'", updatedEntry.Name.GivenName); }
private void button1_Click(object sender, EventArgs e) { //decodr.Text = System.Web.HttpUtility.UrlEncode(encodr.Text.ToString()).Replace("+", " ").Replace("*", "%2A").Replace("!", "%21").Replace("(", "%28").Replace(")", "%29").Replace("'", "%27").Replace("_", "%5f").Replace(" ", "%20").Replace("%", "_"); AppsService service = new AppsService("students.fhchs.edu", "*****@*****.**", "abc123"); UserEntry gmailUser = service.RetrieveUser(encodr.Text.ToString()); gmailUser.Dirty = true; decodr.Text += gmailUser.Dirty.ToString(); decodr.Text += gmailUser.IsDirty(); gmailUser.Update(); decodr.Text += gmailUser.Dirty.ToString(); decodr.Text += gmailUser.IsDirty(); service.UpdateUser(gmailUser); decodr.Text += gmailUser.Dirty.ToString(); decodr.Text += gmailUser.IsDirty(); gmailUser.Dirty = true; }
private void button3_Click(object sender, EventArgs e) { // decodr.Text = Regex.Replace(Regex.Replace(encodr.Text.ToString(), @"[^a-z|^A-Z|^0-9|^\.|_|-]|[\^|\|]|", ""), @"\.+", "."); AppsService service = new AppsService("students.fhchs.edu", "*****@*****.**", "abc123"); UserEntry gmailUser = service.RetrieveUser(encodr.Text.ToString()); //decodr.Text = gmailUser.Dirty.ToString(); //decodr.Text += gmailUser.IsDirty(); //gmailUser.Content.Dirty = true; SortedList list = gmailUser.Name.Attributes; string attribs = "Name attibutes \n" ; foreach (DictionaryEntry de in list) { attribs += de.Key + " " + de.Value + "\n"; } MessageBox.Show(attribs); list = gmailUser.Login.Attributes; attribs = "login attributes \n"; foreach (DictionaryEntry de in list) { attribs += de.Key + " " + de.Value + "\n"; } MessageBox.Show(attribs); list = gmailUser.Quota.Attributes; attribs = "quota attributes \n"; foreach (DictionaryEntry de in list) { attribs += de.Key + " " + de.Value + "\n"; } MessageBox.Show(attribs); // AtomCategory dirty = new AtomCategory(); // gmailUser.ToggleCategory(dirty, true); gmailUser.Name.GivenName = "Mike"; MessageBox.Show("base check dirt after content set dirty " + gmailUser.Login.AgreedToTerms.ToString() + " " + gmailUser.Login.UserName + " " + gmailUser.Name.GivenName); gmailUser.Login.AgreedToTerms = (bool)false; MessageBox.Show("base check dirt after content set dirty " + gmailUser.Login.AgreedToTerms.ToString() + " " + gmailUser.Login.UserName + " " + gmailUser.Name.GivenName); service.UpdateUser(gmailUser); gmailUser.Name.GivenName = "Michael"; MessageBox.Show("base check dirt after content set dirty and update performed " + gmailUser.Login.AgreedToTerms.ToString() + " " + gmailUser.Login.UserName + " " + gmailUser.Name.GivenName); service.UpdateUser(gmailUser); MessageBox.Show("base check dirt after content set dirty and update performed " + gmailUser.Login.AgreedToTerms.ToString() + " " + gmailUser.Login.UserName + " " + gmailUser.Name.GivenName); //GoogleMailSettingsService gmailSettings = new GoogleMailSettingsService("students.fhchs.edu", "FHCHS"); //gmailSettings.setUserCredentials("*****@*****.**", "password"); //try //{ // gmailSettings.CreateSendAs(encodr.Text.ToString(), "Nigeria rocks", "*****@*****.**", "*****@*****.**", "true"); //} //catch (GDataRequestException ex) //{ // MessageBox.Show(" \\-Data-/ " + ex.Data + " \\-Message-/ " + ex.Message + " \\-Response-/ " + ex.Response + " \\-Response String-/ " + ex.ResponseString); //} }
private void button2_Click(object sender, EventArgs e) { // encodr.Text = System.Web.HttpUtility.UrlDecode(decodr.Text.ToString().Replace("_", "%"));\ AppsService service = new AppsService("students.fhchs.edu", "*****@*****.**", "password"); UserEntry gmailUser = service.RetrieveUser(encodr.Text.ToString()); gmailUser.Dirty = true; decodr.Text = gmailUser.Dirty.ToString(); decodr.Text += gmailUser.IsDirty(); gmailUser.Update(); service.UpdateUser(gmailUser); decodr.Text = gmailUser.Dirty.ToString(); decodr.Text += gmailUser.IsDirty(); }
public void UpdateGmailUser(AppsService service, GmailUsers gusersyn, SqlDataReader usersToUpdate, LogFile log) { string userNickName = ""; string middlename = ""; try { while (usersToUpdate.Read()) { try { UserEntry gmailUser = service.RetrieveUser((string)usersToUpdate[gusersyn.User_StuID]); //special gmail username replace string only allows -_. special character thru gmailUser.Login.UserName = System.Web.HttpUtility.UrlEncode(usersToUpdate[gusersyn.User_StuID].ToString()).Replace("+", " ").Replace("*", "%2A").Replace("!", "%21").Replace("(", "%28").Replace(")", "%29").Replace("'", "%27").Replace("_", "%5f").Replace(" ", "%20").Replace("%", "_"); gmailUser.Name.FamilyName = usersToUpdate[gusersyn.User_Lname].ToString().Replace("<", "%3c").Replace(">", "%3e").Replace("=", "%3d").Replace("%", "%25"); gmailUser.Name.GivenName = usersToUpdate[gusersyn.User_Fname].ToString().Replace("<", "%3c").Replace(">", "%3e").Replace("=", "%3d").Replace("%", "%25"); middlename = usersToUpdate[gusersyn.User_Mname].ToString().Replace("<", "%3c").Replace(">", "%3e").Replace("=", "%3d").Replace("%", "%25"); service.UpdateUser(gmailUser); log.addTrn("Updated " + System.Web.HttpUtility.UrlEncode(usersToUpdate[gusersyn.User_StuID].ToString()).Replace("+", " ").Replace("*", "%2A") + " because of name change. New Name is " + gmailUser.Name.FamilyName.ToString() + ", " + gmailUser.Name.GivenName.ToString(), "Transaction"); // if (gusersyn.Levenshtein == true) // { userNickName = GetNewUserNickname(service, gmailUser.Login.UserName, gmailUser.Name.GivenName, middlename, gmailUser.Name.FamilyName, 0, false); log.addTrn("Added New Alias for " + gmailUser.Login.UserName + "@" + gusersyn.Admin_domain + " Aliased as " + userNickName + "@" + gusersyn.Admin_domain, "Transaction"); // } } catch (Exception ex) { log.addTrn("Failed update gmail account " + System.Web.HttpUtility.UrlEncode(usersToUpdate[gusersyn.User_StuID].ToString()).Replace("+", " ").Replace("*", "%2A").Replace("!", "%21").Replace("(", "%28").Replace(")", "%29").Replace("'", "%27").Replace("_", "%5f").Replace(" ", "%20").Replace("%", "_") + " exception " + ex.Message.ToString() + "\n" + ex.StackTrace.ToString(), "Error"); } } } catch (Exception ex) { log.addTrn("Issue updating gmail users datareader is null " + ex.Message.ToString() + "\n" + ex.StackTrace.ToString(), "Error"); } }