# Path: src/bepasty/utils/http.py
# def redirect_next_referrer(endpoint, **values):
#     return redirect(_redirect_target_url(request.form, True, endpoint, **values))
# 
# Path: src/bepasty/utils/permissions.py
# LOGGEDIN = 'loggedin'
# 
# PERMISSIONS = 'permissions'
# 
# def lookup_permissions(token):
#     """
#     look up the permissions string for the secret <token> in the configuration.
#     if no such secret is configured, return None
#     """
#     return current_app.config['PERMISSIONS'].get(token)


from flask import request, session
from flask.views import MethodView
from ..utils.http import redirect_next_referrer
from ..utils.permissions import LOGGEDIN, PERMISSIONS, lookup_permissions



class LoginView(MethodView):
    def post(self):
        token = request.form.get('token')
        if token is not None:
            permissions_for_token = lookup_permissions(token)
            if permissions_for_token is not None:
                session[PERMISSIONS] = permissions_for_token
                session[LOGGEDIN] = True

# Path: src/bepasty/utils/http.py
# def redirect_next_referrer(endpoint, **values):
#     return redirect(_redirect_target_url(request.form, True, endpoint, **values))
# 
# Path: src/bepasty/utils/permissions.py
# LOGGEDIN = 'loggedin'
# 
# PERMISSIONS = 'permissions'
# 
# def lookup_permissions(token):
#     """
#     look up the permissions string for the secret <token> in the configuration.
#     if no such secret is configured, return None
#     """
#     return current_app.config['PERMISSIONS'].get(token)


# Path: src/bepasty/views/login.py
from flask import request, session
from flask.views import MethodView
from ..utils.http import redirect_next_referrer
from ..utils.permissions import LOGGEDIN, PERMISSIONS, lookup_permissions




class LoginView(MethodView):
    def post(self):
        token = request.form.get('token')
        if token is not None:
            permissions_for_token = lookup_permissions(token)
            if permissions_for_token is not None:
                session[PERMISSIONS] = permissions_for_token
                session[LOGGEDIN] = True

        return redirect_next_referrer('bepasty.index')