Skip to content

Commit

Permalink
Copied code for separate admin login from
Browse files Browse the repository at this point in the history
flask_security login
  • Loading branch information
monotasker committed Sep 1, 2023
1 parent 6469ba4 commit 6cf74ee
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions site/knowledge_commons_repository/views/admin_login/admin_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,41 @@
password. It is not linked to from any other page in the repository.
"""

from flask import render_template
from flask import (
render_template, current_app, request, redirect, session, after_this_request
)
from flask.views import MethodView
from flask_security.utils import get_post_login_redirect, login_user
from werkzeug.local import LocalProxy

_security = LocalProxy(lambda: current_app.extensions['security'])

_datastore = LocalProxy(lambda: _security.datastore)

def _ctx(endpoint):
return _security._run_ctx_processor(endpoint)
class AdminLogin(MethodView):
"""
Class providing view class for administrative login.
"""

def __init__(self):
self.template = "knowledge_commons_repository/admin_login.html"
self.template = "knowledge_commons_repository/view_templates/admin_login.html"

def get (self):
"""
Render the template for GET requests.
"""
form_class = _security.login_form

form = form_class(request.form)

if form.validate_on_submit():
login_user(form.user)
after_this_request(_datastore.commit())

return redirect(get_post_login_redirect(form.next.data))

return render_template(self.template)
return _security.render_template(self.template,
login_user_form=form,
**_ctx('login'))

0 comments on commit 6cf74ee

Please sign in to comment.