Esempio n. 1
0
    def login_callback(user_info):
        """Login user base on SSO context (create one if necessary).

        Function should not raise an exception if `user_info` is not valid
        or `User` was not found in database.
        """
        from invenio.modules.accounts.models import User
        from invenio.ext.login import (authenticate, login_redirect,
                                       current_user)
        from invenio.ext.sqlalchemy import db

        user_info['group'] = fetch_groups(user_info['group']).values()
        user_info['external'] = fetch_external(user_info.get('external'))
        try:
            auth = authenticate(user_info['email'], login_method='SSO')
            if auth is None:
                user = User()
                user.nickname = user_info['nickname']
                user.email = user_info['email']
                user.password = ''
                user.settings = {'login_method': 'SSO'}
                db.session.add(user)
                db.session.commit()
                auth = authenticate(user_info['email'], login_method='SSO')
                if auth is None:
                    return redirect('/')

            current_user.info['group'] = current_user.get('group', []) + \
                user_info['group']
            current_user.save()
        except:
            flash('Problem with login (%s)' % (str(user_info)), 'error')
            return redirect('/')

        return login_redirect()
Esempio n. 2
0
    def login_callback(user_info):
        """Login user base on SSO context (create one if necessary).

        Function should not raise an exception if `user_info` is not valid
        or `User` was not found in database.
        """
        from invenio.modules.accounts.models import User
        from invenio.ext.login import (authenticate, login_redirect,
                                       current_user)
        from invenio.ext.sqlalchemy import db

        user_info['group'] = fetch_groups(user_info['group']).values()
        user_info['external'] = fetch_external(user_info.get('external'))
        try:
            auth = authenticate(user_info['email'], login_method='SSO')
            if auth is None:
                user = User()
                user.nickname = user_info['nickname']
                user.email = user_info['email']
                user.password = ''
                user.settings = {'login_method': 'SSO'}
                db.session.add(user)
                db.session.commit()
                auth = authenticate(user_info['email'], login_method='SSO')
                if auth is None:
                    return redirect('/')

            current_user.info['group'] = current_user.get('group', []) + \
                user_info['group']
            current_user.save()
        except:
            flash('Problem with login (%s)' % (str(user_info)), 'error')
            return redirect('/')

        return login_redirect()
def is_current_user_allowed_to_deposit(meta):
    # the user's groups are not updated unless we call reload()
    current_user.reload()
    user_groups = current_user.get('group', [])
    depositing_groups = getattr(meta, 'depositing_groups', [])
    if depositing_groups and not [g for g in user_groups if g in depositing_groups]:
        # depositing is restricted for this domain
        # and the current user is not allowed to make deposits
        return False
    return True
Esempio n. 4
0
def is_current_user_allowed_to_deposit(meta):
    # the user's groups are not updated unless we call reload()
    current_user.reload()
    user_groups = current_user.get('group', [])
    depositing_groups = getattr(meta, 'depositing_groups', [])
    if depositing_groups and not [
            g for g in user_groups if g in depositing_groups
    ]:
        # depositing is restricted for this domain
        # and the current user is not allowed to make deposits
        return False
    return True
Esempio n. 5
0
 def _spam_check(form, field):
     if check_email_domain(current_user.get('email', '')):
         if check_text(field.data):
             raise ValidationError(message)