def merge_to_umail(ldap_conn, mailer, umail, other): umail = umail.lower() other_user = User.fetch_by(username=other) if not other_user: print('Invalid user: {}'.format(other)) return name = helper.fetch_name(ldap_conn, umail) if not name: print('Invalid umail: {}'.format(umail)) return to = '{} <{}>'.format(name, other) umail_user = User.fetch_by(username=umail) if umail_user: print('Merging {} with {}'.format(other_user, umail_user)) helper.merge_users(umail_user, other_user) subject = 'submit.cs accounts merged' body = ('Your submit.cs account {old} has been merged with the account' ' {umail}. You will need to use {umail} and its associated ' 'password to login.\n\nIf you need to reset your password ' 'visit: https://submit.cs.ucsb.edu/password_reset'.format( old=other, umail=umail)) else: print('Changing {} to {}'.format(other_user, umail)) subject = 'submit.cs account username changed' body = ('Your submit.cs account name has been changed to {umail}. ' 'You will need to use this email to login on the submission ' 'system.'.format(umail=umail)) other_user.name = name other_user.username = umail if mailer: body += '\n\nThank you,\nBryce Boe' message = Message(subject=subject, body=body, recipients=[to]) mailer.send_immediately(message)
def merge_to_umail(ldap_conn, mailer, umail, other): umail = umail.lower() other_user = User.fetch_by(username=other) if not other_user: print('Invalid user: {}'.format(other)) return name = helper.fetch_name(ldap_conn, umail) if not name: print('Invalid umail: {}'.format(umail)) return to = '{} <{}>'.format(name, other) umail_user = User.fetch_by(username=umail) if umail_user: print('Merging {} with {}'.format(other_user, umail_user)) helper.merge_users(umail_user, other_user) subject = 'submit.cs accounts merged' body = ('Your submit.cs account {old} has been merged with the account' ' {umail}. You will need to use {umail} and its associated ' 'password to login.\n\nIf you need to reset your password ' 'visit: https://submit.cs.ucsb.edu/password_reset' .format(old=other, umail=umail)) else: print('Changing {} to {}'.format(other_user, umail)) subject = 'submit.cs account username changed' body = ('Your submit.cs account name has been changed to {umail}. ' 'You will need to use this email to login on the submission ' 'system.'.format(umail=umail)) other_user.name = name other_user.username = umail if mailer: body += '\n\nThank you,\nBryce Boe' message = Message(subject=subject, body=body, recipients=[to]) mailer.send_immediately(message)
def update_umail_users(): ldap_conn = helper.connect() for user in User.query_by().order_by(User.name).all(): email = user.username if email.endswith('umail.ucsb.edu'): name = helper.fetch_name(ldap_conn, email) if name and name != user.name: user.name = name elif not name: print email, user.name transaction.commit()