Exemplo n.º 1
0
def register():
	form = RegistrationForm(request.form)
	if request.method == 'POST' and form.validate():
		db = db_connect()
		cur = db.cursor()
		salt = get_salt()
		password_hash = phash(form.password.data + salt)
		# TODO: Clean up this handling.
		# Handles case where email is not present, inserts NULL below.
		# Notice lack of single quotes in query which facilitates this.
		if form.email.data != "":
			email = "'{}'".format(form.email.data)
		else:
			email = "NULL"

		query = "INSERT INTO users (username, l_username, first_name, " \
				"last_name, password_hash, salt, email) VALUES " \
				"('{username}', LOWER('{username}'), '{first_name}', " \
				"'{last_name}', '{password_hash}', '{salt}', {email})".format(
						username=form.username.data,
						first_name=form.first_name.data,
						last_name=form.last_name.data,
						password_hash=password_hash,
						salt=salt,
						email=email
					)
		cur.execute(query)
		db.commit()

		session['logged'] = form.username.data
		return redirect(url_for('homepage'))
	
	return render_template("register.html", form=form)
Exemplo n.º 2
0
def register():
    form = RegistrationForm(request.form)
    if request.method == 'POST' and form.validate():
        user_id = registration_logic.register_user(form)
        user = User.objects.get(pk=user_id)
        login_user(user)
        return redirect(url_for('index'))
    else:
        print form.errors
        return 'Registration Failed. %s' % str(form.errors)
Exemplo n.º 3
0
def register():
    form = RegistrationForm(request.form)
    if request.method == "POST" and form.validate():
        user_id = registration_logic.register_user(form)
        user = User.objects.get(pk=user_id)
        login_user(user)
        return redirect(url_for("index"))
    else:
        print form.errors
        return "Registration Failed. %s" % str(form.errors)
Exemplo n.º 4
0
def register_post():
    """Processes input from the registration form and registers a new user."""
    form = RegistrationForm(request.form)
    if form.validate():
        user = User(form.name.data, form.username.data, form.password.data)
        db.session.add(user)
        db.session.commit()
        session["user"] = dict((k, getattr(user, k)) for k in ("name", "id", "username"))
        if User.query.count() == 1:
            # If there's only one user in the database at this point (i.e. this is the first user in the DB), then give that user administrative rights.
            for priv in privs:
                give_user_privilege(user, priv)
        return redirect(url_for("main"))
    else:
        return render_template("register.html", form=form)
Exemplo n.º 5
0
def register_post():
    """Processes input from the registration form and registers a new user."""
    form = RegistrationForm(request.form)
    if form.validate():
        user = User(form.name.data, form.username.data, form.password.data)
        db.session.add(user)
        db.session.commit()
        session['user'] = dict(
            (k, getattr(user, k)) for k in ('name', 'id', 'username'))
        if User.query.count() == 1:
            # If there's only one user in the database at this point (i.e. this is the first user in the DB), then give that user administrative rights.
            for priv in privs:
                give_user_privilege(user, priv)
        return redirect(url_for('main'))
    else:
        return render_template("register.html", form=form)
Exemplo n.º 6
0
Arquivo: app.py Projeto: dadhia/durak
def register():
    """ Handles a registration request from a client and verifies that all necessary information is provided. """
    form = RegistrationForm()
    if form.validate_on_submit():
        password_hash = pbkdf2_sha256.hash(form.Password.data)
        try:
            new_user = User(email=form.Email.data,
                            password=password_hash,
                            screen_name=form.ScreenName.data)
            db.session.add(new_user)
            db.session.commit()
            login_user(new_user)
            return redirect(url_for('console'))
        except IntegrityError:
            return render_template('index-with-errors.html',
                                   error_message=DUPLICATE_EMAIL,
                                   login_form=LoginForm(),
                                   registration_form=RegistrationForm())
    return render_template('index-with-errors.html',
                           error_message=GENERIC_ERROR_MESSAGE,
                           login_form=LoginForm(),
                           registration_form=RegistrationForm())
Exemplo n.º 7
0
Arquivo: app.py Projeto: dadhia/durak
def login():
    """ Handles a login request from a client. """
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter(User.email == form.email.data).first()
        if user is not None and pbkdf2_sha256.verify(form.password.data,
                                                     user.password):
            login_user(user)
            return redirect(url_for('console'))
    return render_template(
        'index-with-errors.html',
        login_form=LoginForm(),
        registration_form=RegistrationForm(),
        error_message='Invalid username and password combination.')
Exemplo n.º 8
0
Arquivo: app.py Projeto: dadhia/durak
def index():
    """ Renders the home page. """
    return render_template('index.html',
                           login_form=LoginForm(),
                           registration_form=RegistrationForm())
Exemplo n.º 9
0
def register_form():
    """Presents a form for user registration.

    Form details are handed by the WTForm RegistrationForm."""
    form = RegistrationForm(request.form)
    return render_template("register.html", form=form)