Example #1
0
def register():
    """
    Registration Form
    """
    form = RegisterForm(request.form)
    if form.validate_on_submit():
        # create an user instance not yet stored in the database
        user = User(
            first_name = form.first_name.data, 
            last_name = form.last_name.data,
            email = form.email.data, 
            password = generate_password_hash(form.password.data)
            )
        # Insert the record in our database and commit it
        try:
            user.save()
        except NotUniqueError:
            form.email.errors.append('Email address is already registered')
        else:
            # Log the user in, as he now has an id
            session['user_id'] = user.id
            
            # flash will display a message to the user
            flash("Welcome to SoFly! An email has been sent to verify your email address.", 'info')        
            mail.send_activation_email(user=user)
            
            # redirect user to the 'home' method of the user module.
            return redirect(url_for('users.home'))
    return render_template("users/register.html", form=form)    
Example #2
0
def login_provider(provider=None):
    """
    Login handler, must accept both GET and POST to be able to use OpenID.
    """
    authomatic = Authomatic(config=config.config, 
                            secret=config.SECRET_KEY, 
                            report_errors=True,
                            logging_level=log.level)    
    response = make_response(redirect(redirect_url()))
    result = authomatic.login(WerkzeugAdapter(request, response), provider)
    if result:
        user = result.user
        if user:
            user.update()
            verified = mongoUtils.verify_user(user, provider=provider)
            if not verified:
                verified = mail.send_activation_email(email=user.email)    
                flash("Welcome to SoFly! An email has been sent to verify your email address.", 
                    category='info')
            session['user'] = dict(
                email      = user.email,
                first_name = user.first_name,
                last_name  = user.last_name,
                name       = user.name, 
                id         = user.id,
                verified   = verified
            )
            log.debug(session['user'])
    return response
Example #3
0
def activation_email():
    if g.user:
        mail.send_activation_email()
        flash("An email has been sent to verify your email address.", 'info')
    return redirect(url_for('users.home'))