Added capability to log in via email
This commit is contained in:
parent
f121bb0cdf
commit
510bf923b0
3 changed files with 18 additions and 13 deletions
|
|
@ -7,6 +7,7 @@
|
||||||
* Improved repository with better README, CHANGELOG, requirements.txt and option to specify port on run_example.py
|
* Improved repository with better README, CHANGELOG, requirements.txt and option to specify port on run_example.py
|
||||||
* Split app config from app module.
|
* Split app config from app module.
|
||||||
* Added the capability to specify post privacy. Now you can choose to post your message to the public, to friends (mutual followers) or only you.
|
* Added the capability to specify post privacy. Now you can choose to post your message to the public, to friends (mutual followers) or only you.
|
||||||
|
* Now Python 3 is enforced.
|
||||||
|
|
||||||
## 0.3
|
## 0.3
|
||||||
|
|
||||||
|
|
|
||||||
20
app.py
20
app.py
|
|
@ -391,7 +391,7 @@ def register():
|
||||||
|
|
||||||
# mark the user as being 'authenticated' by setting the session vars
|
# mark the user as being 'authenticated' by setting the session vars
|
||||||
auth_user(user)
|
auth_user(user)
|
||||||
return redirect(url_for('homepage'))
|
return redirect(request.args.get('next','/'))
|
||||||
|
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
flash('That username is already taken')
|
flash('That username is already taken')
|
||||||
|
|
@ -402,23 +402,27 @@ def register():
|
||||||
def login():
|
def login():
|
||||||
if request.method == 'POST' and request.form['username']:
|
if request.method == 'POST' and request.form['username']:
|
||||||
try:
|
try:
|
||||||
|
username = request.form['username']
|
||||||
pw_hash = pwdhash(request.form['password'])
|
pw_hash = pwdhash(request.form['password'])
|
||||||
user = User.get(
|
if '@' in username:
|
||||||
(User.username == request.form['username']) &
|
user = User.get(User.email == username)
|
||||||
(User.password == pw_hash))
|
else:
|
||||||
|
user = User.get(User.username == username)
|
||||||
|
if user.password != pw_hash:
|
||||||
|
flash('The password entered is incorrect.')
|
||||||
|
return render_template('login.html')
|
||||||
except User.DoesNotExist:
|
except User.DoesNotExist:
|
||||||
flash('The password entered is incorrect')
|
flash('A user with this username or email does not exist.')
|
||||||
else:
|
else:
|
||||||
auth_user(user)
|
auth_user(user)
|
||||||
return redirect(url_for('homepage'))
|
return redirect(request.args.get('next', '/'))
|
||||||
|
|
||||||
return render_template('login.html')
|
return render_template('login.html')
|
||||||
|
|
||||||
@app.route('/logout/')
|
@app.route('/logout/')
|
||||||
def logout():
|
def logout():
|
||||||
session.pop('logged_in', None)
|
session.pop('logged_in', None)
|
||||||
flash('You were logged out')
|
flash('You were logged out')
|
||||||
return redirect(url_for('homepage'))
|
return redirect(request.args.get('next','/'))
|
||||||
|
|
||||||
@app.route('/+<username>/')
|
@app.route('/+<username>/')
|
||||||
def user_detail(username):
|
def user_detail(username):
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<h2>Login</h2>
|
<h2>Login</h2>
|
||||||
{% if error %}<p class=error><strong>Error:</strong> {{ error }}{% endif %}
|
{% if error %}<p class=error><strong>Error:</strong> {{ error }}{% endif %}
|
||||||
<form action="{{ url_for('login') }}" method=post>
|
<form action="{{ url_for('login') }}" method="POST">
|
||||||
<dl>
|
<dl>
|
||||||
<dt>Username:
|
<dt>Username or email:
|
||||||
<dd><input type=text name=username>
|
<dd><input type="text" name="username">
|
||||||
<dt>Password:
|
<dt>Password:
|
||||||
<dd><input type=password name=password>
|
<dd><input type="password" name="password">
|
||||||
<dd><input type=submit value=Login>
|
<dd><input type="submit" value="Login">
|
||||||
</dl>
|
</dl>
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue