def sig2b64(sig): img = s2i(sig) output = StringIO.StringIO() img.save(output,'PNG') b64 = b64encode(output.getvalue()) output.close() return b64
def register(): """ Registration Form """ form = RegisterForm(request.form) if form.validate_on_submit(): # If netid and email are unique, create an user instance not yet # stored in the database user = User.query.filter_by(netid=form.netid.data, email=form.email.data).first() if user: flash(u'NetID/Email already registered', 'error') return render_template("users/register.html", form=form) raw_signature = request.form['output'] # Convert drawn signature to base64 encoded image. if raw_signature.find("data:image") == -1: from signpad2image import s2i PIL_image = s2i( raw_signature, input_image=os.path.abspath('acm_phoenix/static/packages/signpad2image' '/signpad2image/blanksig.png'), nosig_image=os.path.abspath('acm_phoenix/static/packages/signpad2image' '/signpad2image/nosig.png')) output = StringIO.StringIO() PIL_image.save(output, format='PNG') sig_img = 'data:image/png;base64,' + base64.b64encode(output.getvalue()) output.close() else: sig_img = raw_signature user = User(form.name.data, form.netid.data, form.email.data, form.standing.data, form.major.data, form.shirt_size.data, gfm(form.description.data), sig_img) user.member = True # Insert the record in our database and commit it db.session.add(user) db.session.commit() login_user(user) # flash will display a message to the user flash('Thanks for registering') # If user wants to pay membership now, redirect them to wepay. if form.reg_and_pay.data: response = wepay_membership_response(user) # Keep track of user's checkout_id for later lookup on wepay. user.wepay_checkout_id = response['checkout_id'] db.session.add(user) db.session.commit() return redirect(response['checkout_uri']) else: # redirect user to the 'home' method of the user module. return redirect(url_for('users.home')) return render_template('users/register.html', form=form)