def make_user(self, first_name, last_name, username, personal_email, orgunit_path="OU=ECA,OU=ECA Users", **kwargs): password = get_password() full_name = "%s %s" % (first_name, last_name) target_ou = "%s,DC=ECA,DC=local" % orgunit_path principal_name = "*****@*****.**" % username extra_args = "" for arg, value in kwargs.iteritems(): extra_args += "-%s '%s' " % (arg, value) ps = self.make_user_script % ( password, full_name, first_name, last_name, username, target_ou, principal_name, extra_args, ) r = self.session.run_ps(ps) if not r.status_code == 0: raise Exception("There was an error creating user %s: \n %s" % (username, r.std_err)) t = _get_template("templates/server_account_creation.txt") message = t.render(first_name=first_name, username=username, password=password) message_id = self.gapps.send_message( "Chuck Wilson <*****@*****.**>", personal_email, "ECA Server Account Creation", message ) if message_id: print ("User %s created in OU %s" % (username, orgunit_path)) return True
def turnover_user(self, first_name, last_name, username): password = self._reset_password_ps(username) d = { "first_name": first_name, "last_name": last_name, "username": username, "password": password, "email": "*****@*****.**" % username, } r = self.session.run_ps(self.change_name_script % d) if r.status_code != 0: raise Exception("Unable to change name for %(username)s" % username) t = _get_template("templates/server_account_turnover.txt") message = t.render(**d) message_id = self.gapps.send_message( "Chuck Wilson <*****@*****.**>", d["email"], "ECA Server Account", message ) if message_id: print ( """Sent welcome email for %(username)s (%(first_name)s %(last_name)s) to %(email)s""" % d ) return True
def turnover_user(self, first_name, last_name, email, personal_email): # get password from random.org password = get_password() password_hash = sha1(password) self.set_service('admin', 'directory_v1') name = { 'familyName': last_name, 'givenName': first_name } user = { 'name': name, 'password': password_hash.hexdigest(), 'hashFunction': 'SHA-1', 'changePasswordAtNextLogin': True, } results = self.service.users().update(userKey=email, body=user).execute() # Send email to user with their username/password t = _get_template('templates/email_turnover.txt') message = t.render( first_name=first_name, email=email, password=password ) message_id = self.send_message( 'Chuck Wilson <*****@*****.**>', personal_email, 'ECA Email Account Details', message ) if message_id: print('Sent welcome email with reset password to %s (%s %s) for account %s' % (personal_email, first_name, last_name, email)) return True
def reset_password(self, first_name, email, personal_email): # get password from random.org password = get_password() password_hash = sha1(password) self.set_service('admin', 'directory_v1') user = { 'password': password_hash.hexdigest(), 'hashFunction': 'SHA-1', 'changePasswordAtNextLogin': True, } results = self.service.users().update(userKey=email, body=user).execute() print(results) # Send email to user with their username/password t = _get_template('templates/email_password_reset.txt') message = t.render( first_name=first_name, email=email, password=password ) message_id = self.send_message( 'Chuck Wilson <*****@*****.**>', personal_email, 'ECA Email Password Reset', message ) if message_id: print('Sent password reset email for %s to %s' % (email,personal_email)) return True
def reset_password(self, first_name, username, personal_email): password = self._reset_password_ps(username) t = _get_template("templates/server_account_creation.txt") message = t.render(first_name=first_name, username=username, password=password) message_id = self.gapps.send_message( "Chuck Wilson <*****@*****.**>", personal_email, "ECA Server Account Password Reset", message ) if message_id: d = {"username": username, "password": password} print ("Password reset for %(username)s to %(password)s" % d) return True
def make_user(self, first_name, last_name, username, personal_email, orgunit_path='/'): # get password from random.org password = get_password() password_hash = sha1(password) # Add the user to the google domain self.set_service('admin', 'directory_v1') name = { 'familyName': last_name, 'givenName': first_name } email = '*****@*****.**' % username user = { 'name': name, 'primaryEmail': email, 'password': password_hash.hexdigest(), 'hashFunction': 'SHA-1', 'changePasswordAtNextLogin': True, 'orgUnitPath': orgunit_path } try: results = self.service.users().insert(body=user).execute() except errors.HttpError as e: print("Unable to create user %s" % username) raise e # Send email to user with their username/password t = _get_template('templates/email_account_creation.txt') message = t.render( first_name=first_name, username=username, password=password ) message_id = self.send_message( 'Chuck Wilson <*****@*****.**>', personal_email, 'ECA Email Creation', message ) if message_id: print('Successfully created user %s' % username) return True