public static bool IsEmailRegistered(string userEmailString) { try { DirectoryService directoryService = GetGoogleDirectoryService(); //Email is considered the Primary on Google Accoutns var userkey = userEmailString; UsersResource.GetRequest getUser = directoryService.Users.Get(userkey); User _user = getUser.Execute(); if (_user == null || _user.Suspended == true) { return(false); } } catch (Exception ex) { Console.WriteLine(ex.Message); return(false); //Add you exception here } return(true); }
public bool SetUsersFlagAcceptTerms(String username) { State.log.WriteLine("Attempting to retrieve UserResource."); SetCredential(new[] { DirectoryService.Scope.AdminDirectoryUser }, "jason"); try { // Open the Directory Service DirectoryService service = new DirectoryService(new Google.Apis.Services.BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "Webhost Google Directory" }); State.log.WriteLine("Service Connected."); UsersResource.GetRequest gr = service.Users.Get(String.Format("{0}@dublinschool.org", username)); User user = gr.Execute(); State.log.WriteLine("Got User object."); if (user.AgreedToTerms.HasValue && user.AgreedToTerms.Value) { return(false); } user.AgreedToTerms = true; service.Users.Update(user, String.Format("{0}@dublinschool.org", username)).Execute(); State.log.WriteLine("User AgreedToTerms updated."); } catch (Exception e) { throw new GoogleAPIException(String.Format("Failed to Update {0} status.", username), e); } return(true); }
/// <summary> /// Set the user's GMail Password /// </summary> /// <param name="username">Pass only the UserName here--not the full email</param> /// <param name="Password">New Password to be set</param> public void SetPassword(String username, String Password) { State.log.WriteLine("Attempting to retrieve UserResource."); WebhostEventLog.GoogleLog.LogInformation("{0} is attempting to reset their password.", username); SetCredential(new[] { DirectoryService.Scope.AdminDirectoryUser }, "jason"); try { // Open the Directory Service DirectoryService service = new DirectoryService(new Google.Apis.Services.BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "Webhost Google Directory" }); State.log.WriteLine("Service Connected."); UsersResource.GetRequest gr = service.Users.Get(String.Format("{0}@dublinschool.org", username)); User user = gr.Execute(); State.log.WriteLine("Got User object."); user.Password = Password; service.Users.Update(user, String.Format("{0}@dublinschool.org", username)).Execute(); State.log.WriteLine("User password updated."); WebhostEventLog.GoogleLog.LogInformation("{0} successfully changed their password."); } catch (Exception e) { WebhostEventLog.GoogleLog.LogError("{0} failed to update their password: {1}", username, e.Message); throw new GoogleAPIException(String.Format("Failed to Update password for {0}.", username), e); } }
public async static Task <User> GetOrgUnits(UserCredential credential, string userid) { var service = new DirectoryService(new BaseClientService.Initializer { HttpClientInitializer = credential, ApplicationName = "UbiGrade" }); UsersResource.GetRequest request = service.Users.Get(userid); // List courses. "admin#directory#user" request.ViewType = UsersResource.GetRequest.ViewTypeEnum.DomainPublic; var x = await request.ExecuteAsync(); return(x); }
public static MyGoogleUserInfo GetGoogleUserInfo(string userEmailString) { try { DirectoryService directoryService = GetGoogleDirectoryService(); //Email is considered the Primary on Google Accoutns var userkey = userEmailString; UsersResource.GetRequest getUser = directoryService.Users.Get(userkey); User _user = getUser.Execute(); IList <VerificationCode> _verificationCodes = GetVerificationCodes(userkey); if (_user != null) { MyGoogleUserInfo myuser = new MyGoogleUserInfo() { CustomerId = _user.CustomerId, GivenName = _user.Name.GivenName, FamilyName = _user.Name.FamilyName, ThumbnailPhotoUrl = _user.ThumbnailPhotoUrl, IsEnrolledIn2Sv = _user.IsEnrolledIn2Sv, IsDelegatedAdmin = _user.IsDelegatedAdmin, HashFunction = _user.HashFunction, IsAdmin = _user.IsAdmin, IsEnforcedIn2Sv = _user.IsEnforcedIn2Sv, Password = _user.Password, Phones = _user.Phones, VerificationCodes = _verificationCodes, Suspended = _user.Suspended }; return(myuser); } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(null); }
public async static Task <User> GetOrgUnits3(UserCredential credential, string userid) { //directory api key AIzaSyBq6xSct8OhL2-5zUWMH73wRIN6iFGOg2k //"106276604230863721006" amel var service = new DirectoryService(new BaseClientService.Initializer { HttpClientInitializer = credential, ApiKey = "AIzaSyBq6xSct8OhL2-5zUWMH73wRIN6iFGOg2k", ApplicationName = "UbiGrade" }); UsersResource.GetRequest request = service.Users.Get("*****@*****.**"); request.ViewType = UsersResource.GetRequest.ViewTypeEnum.DomainPublic; //UsersResource.GetRequest request = service.Users.Get("1056718226129"); // htl orgunit id = 1056718226129 var x = await request.ExecuteAsync(); return(x); }