Exemplo n.º 1
0
def get_standard_template_values():
    """Get session information necessary to render any application page.

    Get session information necessary to render any application page including
    the email of the user currently logged in (or None if visitor not logged
    in), any waiting confirmation messages, and any waiting error messages.

    @return: Dictionary of values for rendering HTML templates.
    @rtype: dict
    """
    return {
        "email": get_user_email(),
        "confirmation": get_confirmation(),
        "error": get_error(),
        "user": user_util.get_user(get_user_email()),
        "scroll": get_scroll(),
    }
Exemplo n.º 2
0
 def decorated_function(*args, **kwargs):
     if not is_logged_in():
         flask.session[constants.ERROR_ATTR] = LOGIN_AGAIN_MSG
         return flask.redirect("/base/account/login")
     user = user_util.get_user(get_user_email())
     if not user:
         del flask.session["email"]
         flask.session[constants.ERROR_ATTR] = LOGIN_AGAIN_MSG
         return flask.redirect("/base/account/login")
     if access_data and not user.can_access_data:
         msg = NOT_AUTHORIZED_ACCESS_DATA_MSG
         flask.session[constants.ERROR_ATTR] = msg
         return flask.redirect("/base")
     if edit_parents and not user.can_edit_parents:
         flask.session[constants.ERROR_ATTR] = NOT_AUTHORIZED_PARENTS_MSG
         return flask.redirect("/base")
     if admin and not user.can_admin:
         flask.session[constants.ERROR_ATTR] = NOT_AUTHORIZED_ADMIN_MSG
         return flask.redirect("/base")
     if enter_data and not user.can_enter_data:
         msg = NOT_AUTHORIZED_ENTER_DATA_MSG
         flask.session[constants.ERROR_ATTR] = msg
         return flask.redirect("/base")
     if delete_data and not user.can_delete_data:
         msg = NOT_AUTHORIZED_DELETE_DATA_MSG
         flask.session[constants.ERROR_ATTR] = msg
         return flask.redirect("/base")
     if import_data and not user.can_import_data:
         msg = NOT_AUTHORIZED_IMPORT_DATA_MSG
         flask.session[constants.ERROR_ATTR] = msg
         return flask.redirect("/base")
     if change_formats and not user.can_change_formats:
         msg = NOT_AUTHORIZED_CHANGE_FORMATS_MSG
         flask.session[constants.ERROR_ATTR] = msg
         return flask.redirect("/base")
     if use_api_key and not user.can_use_api_key:
         msg = NOT_AUTHORIZED_API_KEYS_MSG
         flask.session[constants.ERROR_ATTR] = msg
         return flask.redirect("/base")
     return orig_view(*args, **kwargs)
Exemplo n.º 3
0
def get_user_id():
    """Get the id of the user currently logged in."""
    user = user_util.get_user(get_user_email())
    if not user:
        return None
    return user.db_id