Exemple #1
0
    def test_low_level_login(data, self):
        users = data.UserData

        assert current_user.is_guest
        login_user(users.admin.id)
        assert current_user.get_id() == users.admin.id
        logout_user()
        assert current_user.get_id() != users.admin.id
        assert current_user.is_guest
        login_user(users.romeo.id)
        assert not current_user.is_guest
        assert current_user.get_id() == users.romeo.id
        login_user(users.admin.id)
        assert current_user.get_id() == users.admin.id
        logout_user()
    def test_low_level_login(data, self):
        users = data.UserData

        assert current_user.is_guest
        login_user(users.admin.id)
        assert current_user.get_id() == users.admin.id
        logout_user()
        assert current_user.get_id() != users.admin.id
        assert current_user.is_guest
        login_user(users.romeo.id)
        assert not current_user.is_guest
        assert current_user.get_id() == users.romeo.id
        login_user(users.admin.id)
        assert current_user.get_id() == users.admin.id
        logout_user()
 def login_user(self, username='******'):
     from invenio.legacy.websession_model import User
     from invenio.ext.login import login_user, current_user
     user_id = User.query.filter_by(nickname=username).one().id
     login_user(user_id)
     assert user_id == current_user.get_id()
     return user_id
Exemple #4
0
def api():
    """Handle AJAX requests."""
    from invenio.ext.login import current_user
    from invenio.utils.json import json_unicode_to_utf8
    from invenio.legacy.bibedit.utils import user_can_edit_record_collection
    from invenio.legacy.bibedit.engine import perform_request_ajax

    uid = current_user.get_id()
    json_data = json.loads(request.form['jsondata'].encode("utf-8"))
    json_data = json_unicode_to_utf8(json_data)
    json_response = {'resultCode': 0, 'ID': json_data['ID']}

    recid = None
    if 'recID' in json_data:
        recid = int(json_data['recID'])
        json_response.update({'recID': recid})

    if json_data['requestType'] == "getRecord":
        # Authorize access to record.
        if not user_can_edit_record_collection(request, recid):
            json_response.update({'resultCode': 101})
            return json.dumps(json_response)

    # Handle AJAX request.
    json_response.update(perform_request_ajax(request, recid, uid, json_data))
    return jsonify(json_response)
Exemple #5
0
def api():
    """Handle AJAX requests."""
    from invenio.ext.login import current_user
    from invenio.utils.json import json_unicode_to_utf8
    from invenio.legacy.bibedit.utils import user_can_edit_record_collection
    from invenio.legacy.bibedit.engine import perform_request_ajax

    uid = current_user.get_id()
    json_data = json.loads(request.form['jsondata'].encode("utf-8"))
    json_data = json_unicode_to_utf8(json_data)
    json_response = {'resultCode': 0, 'ID': json_data['ID']}

    recid = None
    if 'recID' in json_data:
        recid = int(json_data['recID'])
        json_response.update({'recID': recid})

    if json_data['requestType'] == "getRecord":
        # Authorize access to record.
        if not user_can_edit_record_collection(request, recid):
            json_response.update({'resultCode': 101})
            return json.dumps(json_response)

    # Handle AJAX request.
    json_response.update(perform_request_ajax(request, recid, uid,
                                              json_data))
    return jsonify(json_response)
Exemple #6
0
 def login_user(self, username='******'):
     from invenio.legacy.websession_model import User
     from invenio.ext.login import login_user, current_user
     user_id = User.query.filter_by(nickname=username).one().id
     login_user(user_id)
     assert user_id == current_user.get_id()
     return user_id
    def widget(self):
        user = User.query.get(current_user.get_id())
        email = user.email
        email_field = "8560_"
        deposit_count = len(perform_request_search(f=email_field, p=email, of="id"))

        return render_template_to_string('deposits_user_settings.html',
            email=email, email_field=email_field, deposit_count=deposit_count)
Exemple #8
0
 def __init__(self, keys, attr=None):
     self._keys = keys
     self._user = User.query.get(current_user.get_id())
     self._attr = attr
     if self._attr is None:
         self._data = dict(self._user.settings)
     else:
         self._data = dict(self._user.settings.get(self._attr, {}))
Exemple #9
0
 def __init__(self, keys, attr=None):
     self._keys = keys
     self._user = User.query.get(current_user.get_id())
     self._attr = attr
     if self._attr is None:
         self._data = dict(self._user.settings)
     else:
         self._data = dict(self._user.settings.get(self._attr, {}))
Exemple #10
0
    def widget(self):
        user = User.query.get(current_user.get_id())
        email = user.email
        email_field = "8560_"
        deposit_count = len(
            perform_request_search(f=email_field, p=email, of="id"))

        return render_template_to_string('deposits_user_settings.html',
                                         email=email,
                                         email_field=email_field,
                                         deposit_count=deposit_count)
Exemple #11
0
 def __init__(self):
     super(DepositsSettings, self).__init__()
     self.icon = 'folder-open'
     self.title = _('Deposits')
     try:
         user = User.query.get(current_user.get_id())
         email = user.email
         email_field = "8560_"
         self.view = url_for('search.search', f=email_field, p=email)
     except:
         self.view = ''
Exemple #12
0
 def __init__(self):
     super(DepositsSettings, self).__init__()
     self.icon = 'folder-open'
     self.title = _('Deposits')
     try:
         user = User.query.get(current_user.get_id())
         email = user.email
         email_field = "8560_"
         self.view = url_for('search.search', f=email_field, p=email)
     except:
         self.view = ''
Exemple #13
0
class WebAccountPasswordSettings(Settings):

    keys = ['password']
    form_builder = ChangePasswordForm
    storage_builder = ModelSettingsStorageBuilder(
        lambda: User.query.get(current_user.get_id()))

    def __init__(self):
        super(WebAccountPasswordSettings, self).__init__()
        self.edit = url_for('webaccount.edit', name=self.name)
        self.widget = None

    @property
    def is_authorized(self):
        return current_user.is_authenticated()
Exemple #14
0
def collect_user_info(req, login_time=False, refresh=False):
    """Given the mod_python request object rec or a uid it returns a dictionary
    containing at least the keys uid, nickname, email, groups, plus any external keys in
    the user preferences (collected at login time and built by the different
    external authentication plugins) and if the mod_python request object is
    provided, also the remote_ip, remote_host, referer, agent fields.
    NOTE: if req is a mod_python request object, the user_info dictionary
    is saved into req._user_info (for caching purpouses)
    setApacheUser & setUid will properly reset it.
    """
    from flask_login import current_user
    from invenio.ext.login import UserInfo

    if (type(req) in [long, int] and current_user.get_id() != req) \
            or req is None:
        return UserInfo(req)

    return current_user._get_current_object()
Exemple #15
0
def collect_user_info(req, login_time=False, refresh=False):
    """Given the mod_python request object rec or a uid it returns a dictionary
    containing at least the keys uid, nickname, email, groups, plus any external keys in
    the user preferences (collected at login time and built by the different
    external authentication plugins) and if the mod_python request object is
    provided, also the remote_ip, remote_host, referer, agent fields.
    NOTE: if req is a mod_python request object, the user_info dictionary
    is saved into req._user_info (for caching purpouses)
    setApacheUser & setUid will properly reset it.
    """
    from flask_login import current_user
    from invenio.ext.login import UserInfo

    if (type(req) in [long, int] and current_user.get_id() != req) \
            or req is None:
        return UserInfo(req)

    return current_user._get_current_object()
Exemple #16
0
        if CFG_ACCESS_CONTROL_LEVEL_GUESTS == 0:
            return uid
        elif CFG_ACCESS_CONTROL_LEVEL_GUESTS >= 1:
            return -1
    else:
        res = run_sql("SELECT note FROM user WHERE id=%s", (uid,))
        if CFG_ACCESS_CONTROL_LEVEL_ACCOUNTS == 0:
            return uid
        elif CFG_ACCESS_CONTROL_LEVEL_ACCOUNTS >= 1 and res and res[0][0] in [1, "1"]:
            return uid
        else:
            return -1


from invenio.ext.login import current_user, login_user, logout_user
getUid = lambda req: current_user.get_id()


def setUid(req, uid, remember_me=False):
    """It sets the userId into the session, and raise the cookie to the client.
    """
    if uid > 0:
        login_user(uid, remember_me)
    else:
        logout_user()
    return uid

def session_param_del(req, key):
    """
    Remove a given key from the session.
    """
Exemple #17
0
        elif CFG_ACCESS_CONTROL_LEVEL_GUESTS >= 1:
            return -1
    else:
        res = run_sql("SELECT note FROM user WHERE id=%s", (uid, ))
        if CFG_ACCESS_CONTROL_LEVEL_ACCOUNTS == 0:
            return uid
        elif CFG_ACCESS_CONTROL_LEVEL_ACCOUNTS >= 1 and res and res[0][0] in [
                1, "1"
        ]:
            return uid
        else:
            return -1


from invenio.ext.login import current_user, login_user, logout_user
getUid = lambda req: current_user.get_id()


def setUid(req, uid, remember_me=False):
    """It sets the userId into the session, and raise the cookie to the client.
    """
    if uid > 0:
        login_user(uid, remember_me)
    else:
        logout_user()
    return uid


def session_param_del(req, key):
    """
    Remove a given key from the session.
Exemple #18
0
def logoutUser(req):
    """It logout the user of the system, creating a guest user.
    """
    from invenio.ext.login import logout_user
    logout_user()
    return current_user.get_id()