<commit_before># -*- coding: utf-8 -*-

"""
A decorators related authentication.

:copyright: (c) 2009 by Kay Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""

from functools import update_wrapper

from werkzeug import redirect

from kay.utils import create_login_url

def login_required(func):
  def inner(request, *args, **kwargs):
    if request.user.is_anonymous():
      return redirect(create_login_url(request))
    return func(request, *args, **kwargs)
  update_wrapper(inner, func)
  return inner

def admin_required(func):
  def inner(request, *args, **kwargs):
    if users.current_user_is_admin():
      # TODO: The user could be logged in already,
      # which means the login page might redirect back
      # and cause redirect loops. 
      # Need to allow redirecting to an error page.
      return redirect(create_login_url(request))
    return func(request, *args, **kwargs)
  update_wrapper(inner, func)
  return inner<commit_msg>Fixed a bug in kay.auth.decorators.<commit_after># -*- coding: utf-8 -*-

"""
A decorators related authentication.

:copyright: (c) 2009 by Kay Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""

from functools import update_wrapper

from google.appengine.api import users
from werkzeug import redirect

from kay.utils import create_login_url

def login_required(func):
  def inner(request, *args, **kwargs):
    if request.user.is_anonymous():
      return redirect(create_login_url(request))
    return func(request, *args, **kwargs)
  update_wrapper(inner, func)
  return inner

def admin_required(func):
  def inner(request, *args, **kwargs):
    if users.is_current_user_admin():
      # TODO: The user could be logged in already,
      # which means the login page might redirect back
      # and cause redirect loops. 
      # Need to allow redirecting to an error page.
      return redirect(create_login_url(request))
    return func(request, *args, **kwargs)
  update_wrapper(inner, func)
  return inner
{'fraction_non_alphanumeric': 0.09788489916379735, 'fraction_numerical': 0.004918839153959666, 'mean_word_length': 4.059701492537314, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2605291', 'n_tokens_mistral': 601, 'n_tokens_neox': 589, 'n_words': 209}