Пример #1
0
def login_route():
    # Retrieve the registration form.
    form = LoginForm(request.form)
    options = {'error': []}
    # Deal with POST requests.
    if request.method == "POST":
        if form.validate():
            if not database.username_exists(form.username.data):
                options['error'] = ['Username does not exist']
                # Display.
                return render_template("login.html", form=form, **options)
            # Check if the password is correct.
            password_is_correct = database.check_password(
                form.username.data, form.password.data)
            if not password_is_correct:
                options['error'] = \
                 ['Password is incorrect for the specified username']
                # Display.
                return render_template("login.html", form=form, **options)
            # Update session.
            session['logged_in'] = True
            session['username'] = form.username.data
            # Get the url argument.
            url = request.args.get('url')
            if not url is None:  # requested a private page and passed the check
                return redirect(url)
            # Display.
            return redirect(url_for('main.main_route'))
    # Display.
    return render_template("login.html", form=form, **options)
Пример #2
0
def login_route():
	# Retrieve the registration form.
	form = LoginForm(request.form)
	options = {
		'error': []
	}
	# Deal with POST requests.
	if request.method == "POST":
		if form.validate():
			if not database.username_exists(form.username.data):
				options['error'] = ['Username does not exist']
				# Display.
				return render_template("login.html", form=form, **options)
			# Check if the password is correct.
			password_is_correct = database.check_password(form.username.data, 
				form.password.data)
			if not password_is_correct:
				options['error'] = \
					['Password is incorrect for the specified username']
				# Display.
				return render_template("login.html", form=form, **options)
			# Update session.
			session['logged_in'] = True
			session['username'] = form.username.data
			# Get the url argument.
			url = request.args.get('url')
			if not url is None: # requested a private page and passed the check
				return redirect(url)
			# Display.
			return redirect(url_for('main.main_route'))
	# Display.
	return render_template("login.html", form=form, **options)
def username_existence_check(form, field):
    if database.username_exists(form.username.data):  # already exists
        raise ValidationError('This username is taken')
Пример #4
0
def username_existence_check(form, field):
	if database.username_exists(form.username.data): # already exists
		raise ValidationError('This username is taken')