def register(): form = RegistrationForm(request.form) if not app.config['RECAPTCHA_ENABLED']: del form.recaptcha if request.method == 'POST' and form.validate(): #Exract data from the form full_name = form.full_name.data email = form.email.data password = form.password.data #create user user = User(email, hashlib.sha1(password).hexdigest()) user.full_name = full_name user.active = False #add to database token = Token(str(uuid.uuid4()), datetime.datetime.now()) user.token = token db.session.add(user) db.session.commit() #create email from_email = '*****@*****.**' link = url_for('confirm', email=email, token=token.token, _external = True) body_html = """ <html> <head></head> <body> <p>Welcome!<p> <p>This is the wcloud system, which creates new WebLab-Deusto instances. Your account is ready, and you can activate it:</p> <ul> <li><a href="%(link)s">%(link)s</a>.</li> </ul> <p>If you didn't register, feel free to ignore this e-mail.</p> <p>Best regards,</p> <p>WebLab-Deusto team</p> </body> </html>""" % dict(link=link) print(body_html) body = """Welcome to wcloud. Click %s to confirm your registration.""" % link subject = 'wCloud registration' # Send email try: utils.send_email(app, body, subject, from_email, user.email, body_html) flash("Mail sent to %s from %s with subject '%s'. Check your SPAM folder if you don't receive it." % (user.email, from_email, subject), 'success') except: db.session.delete(token) db.session.delete(user) db.session.commit() flash("There was an error sending the e-mail. This might be because of a invalid e-mail address. Please re-check it.", "error") return render_template('register.html', form=form) flash("""Thanks for registering. You have an email with the steps to confirm your account""", 'success') return redirect(url_for('login')) return render_template('register.html', form=form)
def register(): """ Endpoint for registering a new user. Depending on the configuration, mail confirmation will be required or not. """ form = RegistrationForm(request.form) if not app.config['RECAPTCHA_ENABLED']: del form.recaptcha if request.method == 'POST' and form.validate(): # Extract data from the form full_name = form.full_name.data email = form.email.data password = form.password.data # Create user user = User(email, unicode(hashlib.sha1(password).hexdigest()), full_name) user.active = False user.creation_date = datetime.datetime.now() user.ip_address = request.headers.get('HTTP_X_FORWARDED_FOR', request.remote_addr) mail_confirmation = app.config["MAIL_CONFIRMATION_ENABLED"] # Add to database token = Token(str(uuid.uuid4()), datetime.datetime.now()) user.token = token if not mail_confirmation: user.active = True db.session.add(user) db.session.commit() try: from_email = '*****@*****.**' body_html = """ <html> <head></head> <body> <p>New registered user in wCloud: %s</p> </body> </html>""" % email body = "New registered user: %s" % email subject = 'New registration' utils.send_email(app, body, subject, from_email, app.config['ADMINISTRATORS'], body_html) except: traceback.print_exc() if mail_confirmation: # Create email from_email = '*****@*****.**' link = url_for('confirm', email=email, token=token.token, _external=True) body_html = """ <html> <head></head> <body> <p>Welcome!<p> <p>This is the wcloud system, which creates new WebLab-Deusto instances. Your account is ready, and you can activate it:</p> <ul> <li><a href="%(link)s">%(link)s</a>.</li> </ul> <p>If you didn't register, feel free to ignore this e-mail.</p> <p>Best regards,</p> <p>WebLab-Deusto team</p> </body> </html>""" % dict(link=link) print(body_html) body = """Welcome to wcloud. Click %s to confirm your registration.""" % link subject = 'wCloud registration' # Send email try: utils.send_email(app, body, subject, from_email, user.email, body_html) except: db.session.delete(token) db.session.delete(user) db.session.commit() flash( "There was an error sending the e-mail. This might be because of a invalid e-mail address. Please re-check it.", "error") return render_template('register.html', form=form) else: flash( "Mail sent to %s from %s with subject '%s'. Check your SPAM folder if you don't receive it." % (user.email, from_email, subject), 'success') flash( """Thanks for registering. You have an email with the steps to confirm your account""", 'success') # No mail confirmation. else: flash( """Thanks for registering. Your account is ready. Please, login.""", 'success') return redirect(url_for('login')) return render_template('register.html', form=form)
def register(): """ Endpoint for registering a new user. Depending on the configuration, mail confirmation will be required or not. """ form = RegistrationForm(request.form) if not app.config["RECAPTCHA_ENABLED"]: del form.recaptcha if request.method == "POST" and form.validate(): # Extract data from the form full_name = form.full_name.data email = form.email.data password = form.password.data # Create user user = User(email, unicode(hashlib.sha1(password).hexdigest()), full_name) user.active = False user.creation_date = datetime.datetime.now() user.ip_address = request.headers.get("HTTP_X_FORWARDED_FOR", request.remote_addr) mail_confirmation = app.config["MAIL_CONFIRMATION_ENABLED"] # Add to database token = Token(str(uuid.uuid4()), datetime.datetime.now()) user.token = token if not mail_confirmation: user.active = True db.session.add(user) db.session.commit() try: from_email = "*****@*****.**" body_html = ( """ <html> <head></head> <body> <p>New registered user in wCloud: %s</p> </body> </html>""" % email ) body = "New registered user: %s" % email subject = "New registration" utils.send_email(app, body, subject, from_email, app.config["ADMINISTRATORS"], body_html) except: traceback.print_exc() if mail_confirmation: # Create email from_email = "*****@*****.**" link = url_for("confirm", email=email, token=token.token, _external=True) body_html = """ <html> <head></head> <body> <p>Welcome!<p> <p>This is the wcloud system, which creates new WebLab-Deusto instances. Your account is ready, and you can activate it:</p> <ul> <li><a href="%(link)s">%(link)s</a>.</li> </ul> <p>If you didn't register, feel free to ignore this e-mail.</p> <p>Best regards,</p> <p>WebLab-Deusto team</p> </body> </html>""" % dict( link=link ) print (body_html) body = """Welcome to wcloud. Click %s to confirm your registration.""" % link subject = "wCloud registration" # Send email try: utils.send_email(app, body, subject, from_email, user.email, body_html) except: db.session.delete(token) db.session.delete(user) db.session.commit() flash( "There was an error sending the e-mail. This might be because of a invalid e-mail address. Please re-check it.", "error", ) return render_template("register.html", form=form) else: flash( "Mail sent to %s from %s with subject '%s'. Check your SPAM folder if you don't receive it." % (user.email, from_email, subject), "success", ) flash( """Thanks for registering. You have an email with the steps to confirm your account""", "success", ) # No mail confirmation. else: flash("""Thanks for registering. Your account is ready. Please, login.""", "success") return redirect(url_for("login")) return render_template("register.html", form=form)
def __call__(self, form, field): if User.user_exists(field.data): raise validators.ValidationError(self.message)