Exemple #1
0
def register():
    if (current_user.is_authenticated):
        return redirect(url_for('index'))
    form = RegistrationForm()
    if (form.is_submitted()):
        if (form.validate()):
            #test user existance
            uname = form.username.data
            pword = form.password.data
            mfaid = form.mfaid.data
            #print(uname+":"+pword+":"+mfaid)
            #note, this doesn't actually do anything, since the RegForm already has a validator on name
            user = User.query.filter_by(username=uname).first()
            if (user != None):
                return render_template(
                    'register_results.html',
                    title='Register Failed',
                    form=form,
                    results="Registration failure: username in use")
            user = User(username=uname, mfaid=mfaid)
            user.setpw(pword)
            db.session.add(user)
            db.session.commit()
            return render_template('register_results.html',
                                   title='Register Successful',
                                   form=form,
                                   results="Registration success")
        else:
            return render_template(
                'register_results.html',
                title='Register Failed',
                form=form,
                results="Registration failure: invalid fields")
    return render_template('register.html', title='Register', form=form)
Exemple #2
0
def register():
    form = RegistrationForm(request.form)
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=form.password.data)
        user.save()
        login_user(user)
        flash('Registration successful. You are logged in.', 'success')
        return redirect(url_for("main.index"))
    elif form.is_submitted():
        flash('The given data was invalid.', 'danger')
    return render_template('auth/register.html', form=form)
Exemple #3
0
def signup():
    if current_user.is_authenticated:
        return redirect(url_for("main.index"))
    form = RegistrationForm(request.form)
    if form.validate_on_submit():
        user = User(
            first_name=form.first_name.data,
            last_name=form.last_name.data,
            email=form.email.data,
            country=form.country.data,
            organization=form.organization.data,
        )
        user.set_password(form.password.data)
        user.save()
        # login_user(user)
        flash("Registration successful.", "success")
        log(log.DEBUG, "Registration successful.")

        # SEND CONFIRMATION EMAIL
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            confirm_url = generate_password_reset_url(user.email)
            html = render_template(
                "auth/email_signup_confirmation.html",
                confirm_url=confirm_url,
                first_name=user.first_name,
                last_name=user.last_name,
                email=user.email,
            )
            subject = "Greetings from Visual Approach Analytics!"
            send_email(user.email, subject, html)
            log(
                log.DEBUG,
                "A confirmation email has been sent.",
            )

        return redirect(url_for("auth.signin"))
    elif form.is_submitted():
        for error in form.errors:
            for msg in form.errors[error]:
                log(log.ERROR, "signup(): %s", msg)
                flash(msg, "danger")
    return render_template("auth/register.html",
                           form=form,
                           dashboards=accessed_links())
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()

    if form.is_submitted():
        print("Submitted Successfully!")
    if form.validate():
        print("Validated")
    print(form.errors)

    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Awesome, you\'re all set up!')
        sleep(3)
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Exemple #5
0
def login_page():
    # if user is already logged in then redirect to index page...
    if current_user.is_authenticated:
        return redirect(url_for('login_bp.index'))

    # if a login request is received...
    login_form = LoginForm()
    if login_form.validate_on_submit():
        user = User.query.filter_by(username=login_form.LoginUsername.data).first()
        if user is None or not user.check_password(login_form.LoginPassword.data):
            flash('Username not recognised or invalid password provided - please try again')
            return redirect(url_for('login_bp.login_page'))
        else:
            login_user(user)
            return redirect(url_for('login_bp.index'))

    # if a registration request is received...
    registration_form = RegistrationForm()
    if registration_form.is_submitted():
        if registration_form.validate():
            user = User(username=registration_form.RegistrationUsername.data,
                        identity=registration_form.Identity.data,
                        alignment=registration_form.Alignment.data,
                        gender=registration_form.Gender.data,
                        sex=registration_form.Sex.data,
                        eye_colour=registration_form.EyeColour.data,
                        hair_colour=registration_form.HairColour.data,
                        is_alive={'living': True, 'deceased': False}[registration_form.Alive.data],
                        appearances=registration_form.Appearances.data)
            user.set_password(registration_form.RegistrationPassword.data)
            db.session.add(user)
            db.session.commit()
            login_user(user)
            return redirect(url_for('login_bp.index'))
        else:
            return render_template('login.html', login_form=login_form, registration_form=registration_form, registration_active=True), 205

    # else we have landed on the login page via a GET request...
    return render_template('login.html', login_form=login_form, registration_form=registration_form, registration_active=False)