def create_beta_account(): error = False errors = [] flash = errors.append if len(request.form.get('application')) < 4 or \ not service.valid_subdomain(request.form.get('application')): flash( 'Account name must be at least 4 characters with alpha ' 'numeric and hyphen characters. It cannot start or end ' 'with a hyphen or have two or more consecutive hyphens.' ) error = True if len(request.form.get('username')) < 6 or \ len(request.form.get('password')) < 6: flash('Username and password both must be at least 6 characters') error = True if not service.valid_email(request.form.get('email')): flash('E-mail address is not valid') error = True if not error: plan = db.session.query(Plan).\ filter(Plan.code_name=='beta open').one() user = AccountUser( username=request.form.get('username'), password=service.make_hash(request.form.get('password')), email=request.form.get('email') ) account = Account( name=request.form.get('application'), users=[user] ) account.inherit_plan(plan) db.session.add(account) db.session.commit() manager_uri = 'http://%s.%s/login/?first_registration=true' % ( request.form.get('application'), config.DOMAIN_SUFFIX_MANAGER ) mailer.beta_registration( request.form.get('application'), request.form.get('username'), request.form.get('email') ) reply = {'redirect': manager_uri} else: raise APIError(errors) return reply