def reset(self, session, message='', email=None): if email is not None: try: account = session.get_account_by_email(email) except NoResultFound: message = 'No account exists for email address {!r}'.format( email) else: password = genpasswd() if account.password_reset: session.delete(account.password_reset) session.commit() session.add( PasswordReset(admin_account=account, hashed=bcrypt.hashpw(password, bcrypt.gensalt()))) body = render('emails/accounts/password_reset.txt', { 'name': account.attendee.full_name, 'password': password }, encoding=None) send_email.delay(c.ADMIN_EMAIL, account.attendee.email, c.EVENT_NAME + ' Admin Password Reset', body, model=account.attendee.to_dict('id')) raise HTTPRedirect( 'login?message={}', 'Your new password has been emailed to you') return {'email': email, 'message': message}
def update(self, session, password='', message='', **params): account = session.admin_account(params) if account.is_new: if c.AT_OR_POST_CON and not password: message = 'You must enter a password' else: password = password if c.AT_OR_POST_CON else genpasswd() account.hashed = bcrypt.hashpw(password, bcrypt.gensalt()) message = message or check(account) if not message: message = 'Account settings uploaded' attendee = session.attendee( account.attendee_id ) # dumb temporary hack, will fix later with tests account.attendee = attendee session.add(account) if account.is_new and not c.AT_OR_POST_CON: session.commit() body = render('emails/accounts/new_account.txt', { 'account': account, 'password': password, 'creator': AdminAccount.admin_name() }, encoding=None) send_email.delay(c.ADMIN_EMAIL, attendee.email, 'New ' + c.EVENT_NAME + ' Ubersystem Account', body, model=attendee.to_dict('id')) else: session.rollback() raise HTTPRedirect('index?message={}', message)
def update(self, session, password='', message='', **params): account = session.admin_account(params, checkgroups=['access']) if account.is_new: if c.AT_OR_POST_CON and not password: message = 'You must enter a password' else: password = password if c.AT_OR_POST_CON else genpasswd() account.hashed = bcrypt.hashpw(password, bcrypt.gensalt()) message = message or check(account) if not message: message = 'Account settings uploaded' attendee = session.attendee(account.attendee_id) # dumb temporary hack, will fix later with tests account.attendee = attendee session.add(account) if account.is_new and not c.AT_OR_POST_CON: body = render('emails/accounts/new_account.txt', { 'account': account, 'password': password, 'creator': AdminAccount.admin_name() }, encoding=None) send_email.delay( c.ADMIN_EMAIL, attendee.email, 'New ' + c.EVENT_NAME + ' Ubersystem Account', body, model=attendee.to_dict('id')) else: session.rollback() raise HTTPRedirect('index?message={}', message)
def reset(self, session, message='', email=None): if email is not None: try: account = session.get_account_by_email(email) except NoResultFound: message = 'No account exists for email address {!r}'.format(email) else: password = genpasswd() if account.password_reset: session.delete(account.password_reset) session.commit() session.add(PasswordReset(admin_account=account, hashed=bcrypt.hashpw(password, bcrypt.gensalt()))) body = render('emails/accounts/password_reset.txt', { 'name': account.attendee.full_name, 'password': password}, encoding=None) send_email.delay( c.ADMIN_EMAIL, account.attendee.email, c.EVENT_NAME + ' Admin Password Reset', body, model=account.attendee.to_dict('id')) raise HTTPRedirect('login?message={}', 'Your new password has been emailed to you') return { 'email': email, 'message': message }
def create_judge(self, session, message='', first_name='', last_name='', email='', **params): judge = session.indie_judge(params, checkgroups=['genres', 'platforms']) if cherrypy.request.method == 'POST': message = check(judge) if not message and not first_name or not last_name or not email: message = 'First name, last name, and email address are all required to add a judge' if not message: # only match on last name and email, to prevent nickname issues; this could cause # problems if we had two judges with the same last name AND the same email address attendee = session.query(Attendee).filter_by(last_name=last_name, email=email).first() if attendee and attendee.admin_account: if attendee.admin_account.judge: raise HTTPRedirect( 'index?message={}{}', attendee.full_name, ' is already registered as a judge') else: attendee.admin_account.judge = judge attendee.admin_account.access = ','.join(map(str, set( attendee.admin_account.access_ints + [c.INDIE_JUDGE]))) raise HTTPRedirect('index?message={}{}', attendee.full_name, ' has been granted judge access') if not attendee: attendee = Attendee(first_name=first_name, last_name=last_name, email=email, placeholder=True, badge_type=c.ATTENDEE_BADGE, paid=c.NEED_NOT_PAY) session.add(attendee) password = genpasswd() attendee.admin_account = AdminAccount( judge=judge, access=str(c.INDIE_JUDGE), hashed=bcrypt.hashpw(password, bcrypt.gensalt()) ) email_body = render('emails/accounts/new_account.txt', { 'password': password, 'account': attendee.admin_account }, encoding=None) send_email.delay( c.MIVS_EMAIL, attendee.email, 'New {} Ubersystem Account'.format(c.EVENT_NAME), email_body, model=attendee.to_dict('id')) raise HTTPRedirect( 'index?message={}{}', attendee.full_name, ' has been given an admin account as an Indie Judge') return { 'message': message, 'judge': judge, 'first_name': first_name, 'last_name': last_name, 'email': email }
def add_bulk_admin_accounts(self, session, message='', **params): ids = params.get('ids') if isinstance(ids, str): ids = str(ids).split(",") success_count = 0 for id in ids: try: uuid.UUID(id) except ValueError: pass else: match = session.query(Attendee).filter( Attendee.id == id).first() if match: account = session.admin_account(params) if account.is_new: password = genpasswd() account.hashed = bcrypt.hashpw(password, bcrypt.gensalt()) account.attendee = match session.add(account) body = render('emails/accounts/new_account.txt', { 'account': account, 'password': password }, encoding=None) send_email.delay(c.ADMIN_EMAIL, match.email, 'New ' + c.EVENT_NAME + ' Ubersystem Account', body, model=match.to_dict('id')) success_count += 1 if success_count == 0: message = 'No new accounts were created.' else: session.commit() message = '%d new accounts have been created, and emailed their passwords.' % success_count return message
def add_bulk_admin_accounts(self, session, message='', **params): ids = params.get('ids') if isinstance(ids, str): ids = str(ids).split(",") success_count = 0 for id in ids: try: uuid.UUID(id) except ValueError: pass else: match = session.query(Attendee).filter(Attendee.id == id).first() if match: account = session.admin_account(params, checkgroups=['access']) if account.is_new: password = genpasswd() account.hashed = bcrypt.hashpw(password, bcrypt.gensalt()) account.attendee = match session.add(account) body = render('emails/accounts/new_account.txt', { 'account': account, 'password': password }, encoding=None) send_email.delay( c.ADMIN_EMAIL, match.email, 'New ' + c.EVENT_NAME + ' Ubersystem Account', body, model=match.to_dict('id')) success_count += 1 if success_count == 0: message = 'No new accounts were created.' else: session.commit() message = '%d new accounts have been created, and emailed their passwords.' % success_count return message