def requires_login(f=None, redirect=True):
 if (f is None):
  return functools.partial(requires_login, redirect=redirect)
 @functools.wraps(f)
 def decorated(*args, **kwargs):
  username = get_username()
  if (not username):
   if (request_wants_json() or (not redirect)):
    raise werkzeug.exceptions.Unauthorized()
   else:
    return flask.redirect(flask.url_for('digits.views.login', next=flask.request.path))
  try:
   validate_username(username)
  except ValueError as e:
   raise werkzeug.exceptions.BadRequest(('Invalid username - %s' % e.message))
  return f(*args, **kwargs)
 return decorated

def requires_login ( f = None , redirect = True ) : if ( f is None ) : return functools . partial ( requires_login , redirect = redirect ) @ functools . wraps ( f ) def decorated ( * args , ** kwargs ) : username = get_username ( ) if ( not username ) : if ( request_wants_json ( ) or ( not redirect ) ) : raise werkzeug . exceptions . Unauthorized ( ) else : return flask . redirect ( flask . url_for ( 'digits.views.login' , next = flask . request . path ) ) try : validate_username ( username ) except ValueError as e : raise werkzeug . exceptions . BadRequest ( ( 'Invalid username - %s' % e . message ) ) return f ( * args , ** kwargs ) return decorated
decorator for views that require the user to be logged in keyword arguments: f -- the function to decorate redirect -- if true .