Added capability to log in via email

This commit is contained in:
Yusur 2019-10-11 12:57:40 +02:00
parent f121bb0cdf
commit 510bf923b0
3 changed files with 18 additions and 13 deletions

View file

@ -7,6 +7,7 @@
* Improved repository with better README, CHANGELOG, requirements.txt and option to specify port on run_example.py
* 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.
* Now Python 3 is enforced.
## 0.3

20
app.py
View file

@ -391,7 +391,7 @@ def register():
# mark the user as being 'authenticated' by setting the session vars
auth_user(user)
return redirect(url_for('homepage'))
return redirect(request.args.get('next','/'))
except IntegrityError:
flash('That username is already taken')
@ -402,23 +402,27 @@ def register():
def login():
if request.method == 'POST' and request.form['username']:
try:
username = request.form['username']
pw_hash = pwdhash(request.form['password'])
user = User.get(
(User.username == request.form['username']) &
(User.password == pw_hash))
if '@' in username:
user = User.get(User.email == username)
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:
flash('The password entered is incorrect')
flash('A user with this username or email does not exist.')
else:
auth_user(user)
return redirect(url_for('homepage'))
return redirect(request.args.get('next', '/'))
return render_template('login.html')
@app.route('/logout/')
def logout():
session.pop('logged_in', None)
flash('You were logged out')
return redirect(url_for('homepage'))
return redirect(request.args.get('next','/'))
@app.route('/+<username>/')
def user_detail(username):

View file

@ -2,13 +2,13 @@
{% block body %}
<h2>Login</h2>
{% 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>
<dt>Username:
<dd><input type=text name=username>
<dt>Username or email:
<dd><input type="text" name="username">
<dt>Password:
<dd><input type=password name=password>
<dd><input type=submit value=Login>
<dd><input type="password" name="password">
<dd><input type="submit" value="Login">
</dl>
</form>
{% endblock %}