def register(): if not can_register(): return redirect(url_for('auth.login')) if request.method == 'POST': errors = [] name = request.form['name'] email = request.form['email'] schoolCode = request.form['schoolCode'] password = request.form['password'] name_len = len(name) == 0 names = Teams.query.add_columns('name', 'id').filter_by(name=name).first() emails = Teams.query.add_columns('email', 'id').filter_by(email=email).first() pass_short = len(password) == 0 pass_long = len(password) > 128 valid_email = re.match("[^@]+@[^@]+\.[^@]+", request.form['email']) if not valid_email: errors.append("That email doesn't look right") if names: errors.append('That team name is already taken') if emails: errors.append('That email has already been used') if pass_short: errors.append('Pick a longer password') if pass_long: errors.append('Pick a shorter password') if name_len: errors.append('Pick a longer team name') if len(errors) > 0: return render_template('register.html', errors=errors, name=request.form['name'], email=request.form['email'], schoolCode=request.form['schoolCode'], password=request.form['password']) else: with app.app_context(): team = Teams(name, email.lower(), schoolCode, password) db.session.add(team) db.session.commit() db.session.flush() session['username'] = team.name session['id'] = team.id session['admin'] = team.admin session['nonce'] = sha512(os.urandom(10)) if mailserver() and get_config('verify_emails'): verify_email(team.email) else: if mailserver(): sendmail(request.form['email'], "You've successfully registered for {}".format(get_config('ctf_name'))) db.session.close() logger = logging.getLogger('regs') logger.warn("[{0}] {1} registered with {2}".format(time.strftime("%m/%d/%Y %X"), request.form['name'].encode('utf-8'), request.form['email'].encode('utf-8'))) return redirect(url_for('challenges.challenges_view')) else: return render_template('register.html')
def register(): if not can_register(): return redirect(url_for('auth.login')) if request.method == 'POST': errors = [] name = request.form['name'] email = request.form['email'] password = request.form['password'] name_len = len(name) == 0 names = Teams.query.add_columns('name', 'id').filter_by(name=name).first() emails = Teams.query.add_columns('email', 'id').filter_by(email=email).first() pass_short = len(password) == 0 pass_long = len(password) > 128 valid_email = re.match("[^@]+@[^@]+\.[^@]+", request.form['email']) if not valid_email: errors.append("That email doesn't look right") if names: errors.append('That team name is already taken') if emails: errors.append('That email has already been used') if pass_short: errors.append('Pick a longer password') if pass_long: errors.append('Pick a shorter password') if name_len: errors.append('Pick a longer team name') if len(errors) > 0: return render_template('register.html', errors=errors, name=request.form['name'], email=request.form['email'], password=request.form['password']) else: with app.app_context(): team = Teams(name, email.lower(), password) db.session.add(team) db.session.commit() db.session.flush() session['username'] = team.name session['id'] = team.id session['admin'] = team.admin session['nonce'] = sha512(os.urandom(10)) if can_send_mail() and get_config('verify_emails'): verify_email(team.email) else: if can_send_mail(): sendmail(request.form['email'], "You've successfully registered for {}".format(get_config('ctf_name'))) db.session.close() logger = logging.getLogger('regs') logger.warn("[{0}] {1} registered with {2}".format(time.strftime("%m/%d/%Y %X"), request.form['name'].encode('utf-8'), request.form['email'].encode('utf-8'))) return redirect(url_for('challenges.challenges_view')) else: return render_template('register.html')
def register(): if not can_register(): return redirect('/login') if request.method == 'POST': errors = [] name = request.form['name'] email = request.form['email'] password = request.form['password'] name_len = len(name) == 0 names = Teams.query.add_columns('name', 'id').filter_by(name=name).first() emails = Teams.query.add_columns('email', 'id').filter_by(email=email).first() pass_short = len(password) == 0 pass_long = len(password) > 128 valid_email = re.match("[^@]+@[^@]+\.[^@]+", request.form['email']) if not valid_email: errors.append("That email doesn't look right") if names: errors.append('That team name is already taken') if emails: errors.append('That email has already been used') if pass_short: errors.append('Pick a longer password') if pass_long: errors.append('Pick a shorter password') if name_len: errors.append('Pick a longer team name') if len(errors) > 0: return render_template('register.html', errors=errors, name=request.form['name'], email=request.form['email'], password=request.form['password']) else: with app.app_context(): team = Teams(name, email, password) db.session.add(team) db.session.commit() if mailserver(): sendmail(request.form['email'], "You've successfully registered for the CTF") db.session.close() logger = logging.getLogger('regs') logger.warn("[{0}] {1} registered with {2}".format( time.strftime("%m/%d/%Y %X"), request.form['name'].encode('utf-8'), request.form['email'].encode('utf-8'))) return redirect('/login') else: return render_template('register.html')
def register(): logger = logging.getLogger('regs') if not utils.can_register(): return redirect(url_for('auth.login')) if request.method == 'POST': errors = [] name = request.form['name'] password = request.form['password'] name_len = len(name) == 0 names = Teams.query.add_columns('name', 'id').filter_by(name=name).first() pass_short = len(password) == 0 pass_long = len(password) > 128 if names: errors.append('That team name is already taken') if pass_short: errors.append('Pick a longer password') if pass_long: errors.append('Pick a shorter password') if name_len: errors.append('Pick a longer team name') if len(errors) > 0: return render_template('register.html', errors=errors, name=request.form['name'], password=request.form['password']) else: with app.app_context(): team = Teams(name, password) db.session.add(team) db.session.commit() db.session.flush() session['username'] = team.name session['id'] = team.id session['admin'] = team.admin session['nonce'] = utils.sha512(os.urandom(10)) logger.warn("[{date}] {ip} - {username} registered".format( date=time.strftime("%m/%d/%Y %X"), ip=utils.get_ip(), username=request.form['name'].encode('utf-8'))) db.session.close() return redirect(url_for('challenges.challenges_view')) else: return render_template('register.html')
def register(): if not can_register(): return redirect('/login') if request.method == 'POST': errors = [] name = request.form['name'] email = request.form['email'] password = request.form['password'] name_len = len(name) == 0 names = Teams.query.add_columns('name', 'id').filter_by(name=name).first() emails = Teams.query.add_columns('email', 'id').filter_by(email=email).first() pass_short = len(password) == 0 pass_long = len(password) > 128 valid_email = re.match("[^@]+@[^@]+\.[^@]+", request.form['email']) if not valid_email: errors.append("That email doesn't look right") if names: errors.append('That team name is already taken') if emails: errors.append('That email has already been used') if pass_short: errors.append('Pick a longer password') if pass_long: errors.append('Pick a shorter password') if name_len: errors.append('Pick a longer team name') if len(errors) > 0: return render_template('register.html', errors=errors, name=request.form['name'], email=request.form['email'], password=request.form['password']) else: with app.app_context(): team = Teams(name, email, password) db.session.add(team) db.session.commit() if mailserver(): sendmail(request.form['email'], "You've successfully registered for the CTF") db.session.close() logger = logging.getLogger('regs') logger.warn("[{0}] {1} registered with {2}".format(time.strftime("%m/%d/%Y %X"), request.form['name'].encode('utf-8'), request.form['email'].encode('utf-8'))) return redirect('/login') else: return render_template('register.html')
def register(): logger = logging.getLogger('regs') if not utils.can_register(): return redirect(url_for('auth.login')) if request.method == 'POST': errors = [] name = request.form['name'] email = request.form['email'] password = request.form['password'] name_len = len(name) == 0 names = Teams.query.add_columns('name', 'id').filter_by(name=name).first() emails = Teams.query.add_columns('email', 'id').filter_by(email=email).first() pass_short = len(password) == 0 pass_long = len(password) > 128 valid_email = re.match(r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)", request.form['email']) if not valid_email: errors.append("That email doesn't look right") if names: errors.append('That team name is already taken') if emails: errors.append('That email has already been used') if pass_short: errors.append('Pick a longer password') if pass_long: errors.append('Pick a shorter password') if name_len: errors.append('Pick a longer team name') if len(errors) > 0: return render_template('register.html', errors=errors, name=request.form['name'], email=request.form['email'], password=request.form['password']) else: with app.app_context(): team = Teams(name, email.lower(), password) db.session.add(team) db.session.commit() db.session.flush() session['username'] = team.name session['id'] = team.id session['admin'] = team.admin session['nonce'] = utils.sha512(os.urandom(10)) if utils.can_send_mail() and utils.get_config('verify_emails'): # Confirming users is enabled and we can send email. logger = logging.getLogger('regs') logger.warn("[{date}] {ip} - {username} registered (UNCONFIRMED) with {email}".format( date=time.strftime("%m/%d/%Y %X"), ip=utils.get_ip(), username=request.form['name'].encode('utf-8'), email=request.form['email'].encode('utf-8') )) utils.verify_email(team.email) db.session.close() return redirect(url_for('auth.confirm_user')) else: # Don't care about confirming users if utils.can_send_mail(): # We want to notify the user that they have registered. utils.sendmail(request.form['email'], "You've successfully registered for {}".format(utils.get_config('ctf_name'))) logger.warn("[{date}] {ip} - {username} registered with {email}".format( date=time.strftime("%m/%d/%Y %X"), ip=utils.get_ip(), username=request.form['name'].encode('utf-8'), email=request.form['email'].encode('utf-8') )) db.session.close() return redirect(url_for('contests.contests_view')) else: return render_template('register.html')
def register(): if not can_register(): return redirect(url_for('auth.login')) if request.method == 'POST': errors = [] name = request.form.get('name', '') email = request.form.get('email', '') password = request.form.get('password', '') password_confirm = request.form.get('password-confirm', '') website = request.form.get('website', '') affiliation = request.form.get('affiliation', '') country = request.form.get('country', '') if not name: errors.append('Pick a longer team name') else: names = Teams.query.filter_by(name=name).first() if names: errors.append('That team name is already taken') if not email: errors.append('Pick a longer email') elif not re.match( r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)", email): errors.append("That email doesn't look right") else: emails = Teams.query.filter_by(email=email).first() if emails: errors.append('That email has already been used') if not password: errors.append('Pick a longer password') password = password_confirm = '' elif len(password) > 128: errors.append('Pick a shorter password') password = password_confirm = '' elif password != password_confirm: errors.append("These passwords don't match") password = password_confirm = '' if website.strip() and not validate_url(website): errors.append("That doesn't look like a valid URL") if country not in countries.keys: errors.append('Invalid country') if len(errors) > 0: return render_template('register.html', errors=errors, name=name, email=email, password=password, password_confirm=password_confirm, website=website, affiliation=affiliation, country=country, countries=countries) else: with app.app_context(): team = Teams(name, email.lower(), password, website, affiliation, country) db.session.add(team) db.session.commit() db.session.flush() session['username'] = team.name session['id'] = team.id session['admin'] = team.admin session['nonce'] = sha512(os.urandom(10)) if can_send_mail() and get_config( 'verify_emails' ): # Confirming users is enabled and we can send email. db.session.close() logger = logging.getLogger('regs') logger.warn( "[{0}] {1} registered (UNCONFIRMED) with {2}".format( time.strftime("%m/%d/%Y %X"), request.form['name'].encode('utf-8'), request.form['email'].encode('utf-8'))) return redirect(url_for('auth.confirm_user')) else: # Don't care about confirming users if can_send_mail( ): # We want to notify the user that they have registered. sendmail( request.form['email'], "You've successfully registered for {}".format( get_config('ctf_name'))) db.session.close() logger = logging.getLogger('regs') logger.warn("[{0}] {1} registered with {2}".format( time.strftime("%m/%d/%Y %X"), request.form['name'].encode('utf-8'), request.form['email'].encode('utf-8'))) return redirect(url_for('challenges.challenges_view')) else: return render_template( 'register.html', country='wo', # default: Multiple Countries countries=countries)
def register(): if not utils.can_register(): return redirect(url_for('auth.login')) if request.method == 'POST': errors = [] name = request.form['name'] email = request.form['email'] password = request.form['password'] name_len = len(name) == 0 names = Teams.query.add_columns('name', 'id').filter_by(name=name).first() emails = Teams.query.add_columns('email', 'id').filter_by(email=email).first() pass_short = len(password) == 0 pass_long = len(password) > 128 valid_email = re.match(r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)", request.form['email']) if not valid_email: errors.append("That email doesn't look right") if names: errors.append('That team name is already taken') if emails: errors.append('That email has already been used') if pass_short: errors.append('Pick a longer password') if pass_long: errors.append('Pick a shorter password') if name_len: errors.append('Pick a longer team name') if len(errors) > 0: return render_template('register.html', errors=errors, name=request.form['name'], email=request.form['email'], password=request.form['password']) else: with app.app_context(): team = Teams(name, email.lower(), password) db.session.add(team) db.session.commit() db.session.flush() session['username'] = team.name session['id'] = team.id session['admin'] = team.admin session['nonce'] = utils.sha512(os.urandom(10)) if utils.can_send_mail() and utils.get_config('verify_emails'): # Confirming users is enabled and we can send email. db.session.close() logger = logging.getLogger('regs') logger.warn("[{0}] {1} registered (UNCONFIRMED) with {2}".format(time.strftime("%m/%d/%Y %X"), request.form['name'].encode('utf-8'), request.form['email'].encode('utf-8'))) utils.verify_email(team.email) return redirect(url_for('auth.confirm_user')) else: # Don't care about confirming users if utils.can_send_mail(): # We want to notify the user that they have registered. utils.sendmail(request.form['email'], "You've successfully registered for {}".format(utils.get_config('ctf_name'))) db.session.close() logger = logging.getLogger('regs') logger.warn("[{0}] {1} registered with {2}".format(time.strftime("%m/%d/%Y %X"), request.form['name'].encode('utf-8'), request.form['email'].encode('utf-8'))) return redirect(url_for('challenges.challenges_view')) else: return render_template('register.html')
def register(): logger = logging.getLogger('regs') if not utils.can_register(): return redirect(url_for('auth.login')) if request.method == 'POST': errors = [] name = request.form['name'] sno = request.form['sno'] email = request.form['email'] password = request.form['password'] name_len = len(name) == 0 names = Teams.query.add_columns('name', 'id').filter_by(name=name).first() valid_sno = utils.check_sno_format(request.form['sno']) snos = Teams.query.add_columns('sno', 'id').filter_by(sno=sno).first() emails = Teams.query.add_columns('email', 'id').filter_by(email=email).first() pass_short = len(password) == 0 pass_long = len(password) > 128 valid_email = utils.check_email_format(request.form['email']) team_name_email_check = utils.check_email_format(name) if not valid_sno: errors.append("Please enter a valid student ID") if not valid_email: errors.append("Please enter a valid email address") if names or snos: errors.append('That nick/user is already taken') if team_name_email_check is True: errors.append('Your team name cannot be an email address') if emails: errors.append('That email has already been used') if pass_short: errors.append('Pick a longer password') if pass_long: errors.append('Pick a shorter password') if name_len: errors.append('Pick a longer team name') if len(errors) > 0: return render_template('register.html', errors=errors, name=request.form['name'], email=request.form['email'], password=request.form['password']) else: with app.app_context(): team = Teams(name, sno, email.lower(), password) db.session.add(team) db.session.commit() db.session.flush() session['username'] = team.name session['sno'] = team.sno session['id'] = team.id session['admin'] = team.admin session['nonce'] = utils.sha512(os.urandom(10)) if utils.can_send_mail() and utils.get_config( 'verify_emails' ): # Confirming users is enabled and we can send email. logger = logging.getLogger('regs') logger.warn( "[{date}] {ip} - {username}/{sno} registered (UNCONFIRMED) with {email}" .format(date=time.strftime("%m/%d/%Y %X"), ip=utils.get_ip(), username=request.form['name'].encode('utf-8'), sno=request.form['sno'].encode('utf-8'), email=request.form['email'].encode('utf-8'))) utils.verify_email(team.email) db.session.close() return redirect(url_for('auth.confirm_user')) else: # Don't care about confirming users if utils.can_send_mail( ): # We want to notify the user that they have registered. utils.sendmail( request.form['email'], "You've successfully registered for {}".format( utils.get_config('ctf_name'))) logger.warn( "[{date}] {ip} - {username}/{sno} registered with {email}".format( date=time.strftime("%m/%d/%Y %X"), ip=utils.get_ip(), username=request.form['name'].encode('utf-8'), sno=request.form['sno'].encode('utf-8'), email=request.form['email'].encode('utf-8'))) db.session.close() return redirect(url_for('challenges.challenges_view')) else: return render_template('register.html')
def register(): logger = logging.getLogger('regs') if not utils.can_register(): return redirect(url_for('auth.login')) if request.method == 'POST': errors = [] name = request.form['name'] email = request.form['email'] password = request.form['password'] name_len = len(name) == 0 names = Teams.query.add_columns('name', 'id').filter_by(name=name).first() emails = Teams.query.add_columns('email', 'id').filter_by(email=email).first() pass_short = len(password) == 0 pass_long = len(password) > 128 valid_email = utils.check_email_format(request.form['email']) team_name_email_check = utils.check_email_format(name) if not valid_email: errors.append("邮箱格式不正确") if names: errors.append('用户名已被其他用户使用') if team_name_email_check is True: errors.append('用户名不能和邮箱一样') if emails: errors.append('邮箱已被其他用户使用') if pass_short: errors.append('密码长度不够') if pass_long: errors.append('密码长度超过上限') if name_len: errors.append('用户名长度不够') if len(errors) > 0: return render_template('register.html', errors=errors, name=request.form['name'], email=request.form['email'], password=request.form['password']) else: with app.app_context(): team = Teams(name, email.lower(), password) db.session.add(team) db.session.commit() db.session.flush() session['username'] = team.name session['id'] = team.id session['admin'] = team.admin session['nonce'] = utils.sha512(os.urandom(10)) if utils.can_send_mail() and utils.get_config( 'verify_emails' ): # Confirming users is enabled and we can send email. logger = logging.getLogger('regs') logger.warn( "[{date}] {ip} - {username} registered (UNCONFIRMED) with {email}" .format(date=time.strftime("%m/%d/%Y %X"), ip=utils.get_ip(), username=request.form['name'].encode('utf-8'), email=request.form['email'].encode('utf-8'))) utils.verify_email(team.email) db.session.close() return redirect(url_for('auth.confirm_user')) else: # Don't care about confirming users if utils.can_send_mail( ): # We want to notify the user that they have registered. utils.sendmail( request.form['email'], "您已经成功过注册了 {}".format( utils.get_config('ctf_name'))) logger.warn( "[{date}] {ip} - {username} registered with {email}".format( date=time.strftime("%m/%d/%Y %X"), ip=utils.get_ip(), username=request.form['name'].encode('utf-8'), email=request.form['email'].encode('utf-8'))) db.session.close() return redirect(url_for('challenges.challenges_view')) else: return render_template('register.html')
def register(): if not can_register(): return redirect(url_for("auth.login")) if request.method == "POST": errors = [] name = request.form["name"] email = request.form["email"] password = request.form["password"] bracket = request.form["bracket"] country = request.form["country"] affiliation = request.form["affiliation"] name_len = len(name) == 0 names = Teams.query.add_columns("name", "id").filter_by(name=name).first() emails = Teams.query.add_columns("email", "id").filter_by(email=email).first() pass_short = len(password) == 0 pass_long = len(password) > 128 valid_email = re.match("[^@]+@[^@]+\.[^@]+", request.form["email"]) bracket_exists = bracket in brackets country_exists = country in countries print country_exists print country if not valid_email: errors.append("That email doesn't look right") if names: errors.append("That team name is already taken") if emails: errors.append("That email has already been used") if pass_short: errors.append("Pick a longer password") if pass_long: errors.append("Pick a shorter password") if name_len: errors.append("Pick a longer team name") if not bracket_exists: errors.append("Please select a valid bracket") if not country_exists: errors.append("Please select a valid country") if len(errors) > 0: return render_template( "register.html", errors=errors, name=request.form["name"], email=request.form["email"], password=request.form["password"], brackets=brackets, countries=countries, ) else: with app.app_context(): team = Teams(name, email.lower(), password, bracket, country, affiliation) db.session.add(team) db.session.commit() db.session.flush() session["username"] = team.name session["id"] = team.id session["admin"] = team.admin session["nonce"] = sha512(os.urandom(10)) if mailserver() and get_config("verify_emails"): verify_email(team.email) else: if mailserver(): sendmail( request.form["email"], "You've successfully registered for {}".format(get_config("ctf_name")), ) db.session.close() logger = logging.getLogger("regs") logger.warn( "[{0}] {1} registered with {2}".format( time.strftime("%m/%d/%Y %X"), request.form["name"].encode("utf-8"), request.form["email"].encode("utf-8"), ) ) return redirect(url_for("challenges.challenges_view")) else: return render_template("register.html", brackets=brackets, countries=countries)
def private_register(): if not utils.can_register(): return redirect(url_for('auth.login')) if request.method == 'POST': selected_option = utils.get_config('private_registration_option') errors = [] if selected_option == 'token': token = request.form['token'] invited_team = InvitedTeams.query.add_columns( 'name', 'email').filter_by(token=token).first() if not invited_team: errors.append('Invalid token') elif selected_option == 'email': email = request.form['email'] invited_team = InvitedTeams.query.add_columns( 'name', 'email').filter_by(email=email).first() if not invited_team: errors.append('Your email is not invited') else: errors.append('Something strange happened') if len(errors) == 0: team = Teams.query.add_columns('id').filter_by( name=invited_team.name).first() if team: errors.append('Already registered') password = request.form['password'] pass_short = len(password) == 0 pass_long = len(password) > 128 if pass_short: errors.append('Pick a longer password') if pass_long: errors.append('Pick a shorter password') if len(errors) > 0: if selected_option == 'token': return render_template('register.html', errors=errors, token=request.form['token'], password=request.form['password']) elif selected_option == 'email': return render_template('register.html', errors=errors, email=request.form['email'], password=request.form['password']) else: return render_template('register.html') else: with app.app_context(): name = invited_team.name email = invited_team.email team = Teams(name, email.lower(), password) db.session.add(team) db.session.commit() db.session.flush() session['username'] = team.name session['id'] = team.id session['admin'] = team.admin session['nonce'] = utils.sha512(urandom(10)) if (utils.can_send_mail() and utils.get_config('verify_emails')): db.session.close() logger = logging.getLogger('regs') logger.warn('[{0}] {1} registered (UNCONFIRMED) ' \ 'with {2}'.format( time.strftime('%m/%d/%Y %X'), name.encode('utf-8'), email.encode('utf-8'))) utils.verify_email(team.email) return redirect(url_for('auth.confirm_user')) else: if utils.can_send_mail(): utils.sendmail(email, "You've successfully " \ "registered for {}".format( utils.get_config('ctf_name'))) db.session.close() logger = logging.getLogger('regs') logger.warn('[{0}] {1} registered with {2}'.format( time.strftime('%m/%d/%Y %X'), name.encode('utf-8'), email.encode('utf-8'))) return redirect(url_for('challenges.challenges_view')) else: return render_template('register.html')
def register_smart(): logger = logging.getLogger('regs') if not utils.can_register(): return redirect(url_for('auth.login')) if request.method == 'POST': errors = [] name = request.form['name'] email = request.form['email'] password = request.form['password'] color = request.form['color'] school = request.form['school'] image = request.form['image'] #school = request.form['school'] if not color in teamColors: color = "RED" if not image in teamImages: image = "HULK" name_len = len(name) == 0 names = Teams.query.add_columns('name', 'id').filter_by(name=name).first() emails = Teams.query.add_columns('email', 'id').filter_by(email=email).first() smart_color = SmartCityTeam.query.filter_by(color=color).first() smart_image = SmartCityTeam.query.filter_by(image=image).first() #challenge = SmartCityChallenge.query.filter_by(id=challenge.id).first() pass_short = len(password) == 0 pass_long = len(password) > 128 valid_email = utils.check_email_format(request.form['email']) team_name_email_check = utils.check_email_format(name) if not valid_email: errors.append("Please enter a valid email address") if names: errors.append('That team name is already taken') if team_name_email_check is True: errors.append('Your team name cannot be an email address') if emails: errors.append('That email has already been used') if pass_short: errors.append('Pick a longer password') if pass_long: errors.append('Pick a shorter password') if name_len: errors.append('Pick a longer team name') if smart_color: if not Teams.query.filter_by(id=smart_color.teamId).first().admin: errors.append( 'Color unavailable. The following colors are available: \n' + getAvailableColors()) if smart_image: if not Teams.query.filter_by(id=smart_image.teamId).first().admin: errors.append('That image is already taken') if len(errors) > 0: return render_template('register.html', errors=errors, name=request.form['name'], email=request.form['email'], password=request.form['password']) else: with app.app_context(): team = Teams(name, email.lower(), password) db.session.add(team) db.session.commit() db.session.flush() smart_team = SmartCityTeam(team.id, team.name, color, image, school) db.session.add(smart_team) db.session.commit() db.session.flush() session['username'] = team.name session['id'] = team.id session['admin'] = team.admin session['nonce'] = utils.sha512(os.urandom(10)) if utils.can_send_mail() and utils.get_config( 'verify_emails' ): # Confirming users is enabled and we can send email. logger = logging.getLogger('regs') logger.warn( "[{date}] {ip} - {username} registered (UNCONFIRMED) with {email}" .format(date=time.strftime("%m/%d/%Y %X"), ip=utils.get_ip(), username=request.form['name'].encode('utf-8'), email=request.form['email'].encode('utf-8'))) utils.verify_email(team.email) db.session.close() return redirect(url_for('auth.confirm_user')) else: # Don't care about confirming users if utils.can_send_mail( ): # We want to notify the user that they have registered. utils.sendmail( request.form['email'], "You've successfully registered for {}".format( utils.get_config('ctf_name'))) logger.warn( "[{date}] {ip} - {username} registered with {email}".format( date=time.strftime("%m/%d/%Y %X"), ip=utils.get_ip(), username=request.form['name'].encode('utf-8'), email=request.form['email'].encode('utf-8'))) db.session.close() return redirect(url_for('challenges.challenges_view')) else: return render_template('register.html')
def register(): logger = logging.getLogger('regs') if not utils.can_register(): return redirect(url_for('auth.login')) if request.method == 'POST': errors = [] name = request.form['name'] email = request.form['email'] password = request.form['password'] name_len = len(name) == 0 names = Teams.query.add_columns('name', 'id').filter_by(name=name).first() emails = Teams.query.add_columns('email', 'id').filter_by(email=email).first() pass_short = len(password) == 0 pass_long = len(password) > 128 valid_email = utils.check_email_format(request.form['email']) team_name_email_check = utils.check_email_format(name) if not valid_email: errors.append(get_tip('INVIDE_EMAIL')) if names: errors.append(get_tip('TEAM_EXIST')) if team_name_email_check is True: errors.append(get_tip('EMAIL_NOT_TEAM')) if emails: errors.append(get_tip('EMAIL_HAVE_USE')) if pass_short: errors.append(get_tip('TOO_SHORT_PASS')) if pass_long: errors.append(get_tip('TOO_LONG_PASS')) if name_len: errors.append(get_tip('TOO_SHORT_TEAM')) if len(errors) > 0: return render_template('register.html', errors=errors, name=request.form['name'], email=request.form['email'], password=request.form['password']) else: with app.app_context(): token = os.urandom(16).encode('hex') team = Teams(name, email.lower(), password, token.lower()) db.session.add(team) db.session.commit() db.session.flush() session['username'] = team.name session['id'] = team.id session['admin'] = team.admin session['nonce'] = utils.sha512(os.urandom(10)) if utils.can_send_mail() and utils.get_config( 'verify_emails' ): # Confirming users is enabled and we can send email. logger = logging.getLogger('regs') logger.warn( get_tip('USER_REG_WARN').format( date=time.strftime("%m/%d/%Y %X"), ip=utils.get_ip(), username=request.form['name'].encode('utf-8'), email=request.form['email'].encode('utf-8'))) utils.verify_email(team.email) db.session.close() return redirect(url_for('auth.confirm_user')) else: # Don't care about confirming users if utils.can_send_mail( ): # We want to notify the user that they have registered. utils.sendmail( request.form['email'], get_tip('USER_REG_SUCCESS').format( utils.get_config('ctf_name'))) logger.warn( get_tip('USER_REGISTRED').format( date=time.strftime("%m/%d/%Y %X"), ip=utils.get_ip(), username=request.form['name'].encode('utf-8'), email=request.form['email'].encode('utf-8'))) db.session.close() return redirect(url_for('challenges.challenges_view')) else: return render_template('register.html')