from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import os import hashlib class Account(Page): form_model = 'player' form_fields = [ 'EMAIL', 'PASSWORD', 'PASSWORD_2' ] def error_message(self, values): error_messages = dict() with open(f'_static/global/TN_{self.session.config["mailing_group"]}.txt', mode='r') as f: content = f.readlines() mail_addresses = [x.strip() for x in content] if not values['EMAIL'].strip() in mail_addresses: error_messages['EMAIL'] = 'Please enter a valid email address.' if values['PASSWORD'] != values['PASSWORD_2']: error_messages['PASSWORD_2'] = 'The two passwords must be identical.' return error_messages def before_next_page(self): salt = os.urandom(32) key = hashlib.pbkdf2_hmac('sha256', self.player.PASSWORD.encode('utf-8'), salt, 100000) self.player.SALT = str(salt) self.player.PASSWORD = str(key) self.player.PASSWORD_2 = str(key) class Demographics(Page): form_model = 'player' form_fields = [ 'ENTREPRENEUR', 'AGE', 'GENDER', 'IS_BACHELOR', 'DISCIPLINE' ] page_sequence = [ Account, Demographics ]