Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
final touch ups
  • Loading branch information
noga-acumen committed Oct 1, 2021
commit a2c6a933ba3d493384eb2076ac3618a8fae8a43b
17 changes: 8 additions & 9 deletions lms/lmsweb/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,26 @@ def ratelimit_handler(e):
)


@webapp.route('/login', methods=['GET', 'POST']) # TODO: change this to use WTForms, like '/signup'
@webapp.route('/login', methods=['GET', 'POST'])
@limiter.limit(
f'{LIMITS_PER_MINUTE}/minute;{LIMITS_PER_HOUR}/hour',
deduct_when=lambda response: response.status_code != 200,
)
def login(login_message: Optional[str] = None):
next_page = request.form.get('next')
if current_user.is_authenticated:
return get_next_url(request.args.get('next'))
return get_next_url(next_page)

form = LoginForm() # above the is.auth...?
form = LoginForm()
login_message = request.args.get('login_message')
if not form.validate_on_submit():
return render_template('login.html', form=form)
return render_template(
'login.html', form=form, login_message=login_message
)

username = form.username.data
password = form.password.data
next_page = request.form.get('next') # TODO: what is this? what's the best way to do it on WTForms?
login_message = request.args.get('login_message') # maybe move those to inside the `if` statement?

# if request.method == 'POST':
try:
user = auth(username, password)
except (ForbiddenPermission, UnauthorizedError) as e:
Expand All @@ -123,8 +124,6 @@ def login(login_message: Optional[str] = None):
session['_invalid_password_tries'] = 0
return get_next_url(next_page)

# return render_template('login.html', login_message=login_message) # form=form?


@webapp.route('/signup', methods=['GET', 'POST'])
@limiter.limit(f'{LIMITS_PER_MINUTE}/minute;{LIMITS_PER_HOUR}/hour')
Expand Down