--- /dev/null
+{% extends 'main.html' %}
+{% from '_formhelpers.html' import render_field, submit_button %}
+
+{% block content %}
+<h1>WE COMMAND YOU TO CREATE AN ACCOUNT</h1>
+
+<form action="" method="post">
+ {{ form.hidden_tag() }}
+ {{ render_field(form.username) }}
+ {{ render_field(form.password) }}
+ {{ submit_button("Sign up") }}
+</form>
+{% endblock %}
blueprint = Blueprint('main', __name__, template_folder='templates')
+def do_login_user(user):
+ login_success = login.login_user(user, remember=False)
+ if login_success:
+ pass
+ else:
+ flash(u'Login failed for {} - is that user marked inactive?'.format(user.username), 'error')
+
@login_manager.user_loader
def load_user(userid):
return models.User.query.get(userid)
def index():
return render_template('index.html')
+@blueprint.route("/signup", methods=["GET", "POST"])
+def signup_page():
+ # LoginForm and SignupForm are functionally equivalent...
+ form = forms.LoginForm()
+ if form.validate_on_submit():
+ user = models.User.query.filter_by(username=form.username.data).first()
+ if user:
+ flash(u"That username is already taken.", 'error')
+ else:
+ user = models.User()
+ user.username = form.username.data
+ user.set_password(form.password.data)
+ db.session.add(user)
+ db.session.commit()
+ flash(u"Account created", 'success')
+ do_login_user(user)
+ return redirect(url_for('.test_protected'))
+ return render_template('signup.html', form=form)
+
@blueprint.route("/login", methods=["GET", "POST"])
def login_page():
form = forms.LoginForm()
user = models.User.query.filter_by(username=form.username.data).first()
if not user:
# User does not exist.
- flash(u'Username or password is incorrect', 'error')
+ flash(u'Username is incorrect', 'error')
elif not scrypt.check_password_hash(form.password.data, user.pw_hash, user.pw_salt):
- # User exists, but wrong password. Give same behavior as no user
- # existing, to try to prevent mining of usernames.
- flash(u'Username or password is incorrect', 'error')
+ # User exists, but wrong password. Since we have open signup, but
+ # prevent dual use of usernames, we can't protect against username
+ # mining. Oh well.
+ flash(u'Password is incorrect', 'error')
else:
# Successful login.
- login_success = login.login_user(user, remember=False)
- if login_success:
- pass
- else:
- flash(u'Login failed for {} - is that user marked inactive?'.format(user.username), 'error')
+ do_login_user(user)
return redirect(url_for('.test_protected'))
return render_template('login.html', form=form)