Decorator function to check if user is loged in.

    :raises: :class:`FMBaseError` if not logged in
351664
def not_completed(f):
    

    @wraps(f)
    def check_if_complete(cls, *args, **kwargs):
        if cls.is_complete:
            raise FMBaseError('Transfer already completed.')

        return f(cls, *args, **kwargs)

    return check_if_complete
933815
def require_login(func):
    

    @wraps(func)
    def decorated(*args, **kwargs):
        auth = request.authorization
        if not auth:
            return authenticate()

        user = session.query(User).filter(
            User.name == auth.username
        ).first()
        if user and user.check(auth.password):
            g.user = user
            return func(*args, **kwargs)
        else:
            return authenticate()

    return decorated
651734
def user_is(role, get_user=import_user):
    
    def wrapper(func):
        @wraps(func)
        def inner(*args, **kwargs):
            from .models import Role
            current_user = get_user()
            if role in current_user.roles:
                return func(*args, **kwargs)
            raise Forbidden("You do not have access")
        return inner
    return wrapper
26366
def login_required(func):
    ''''''
    def ret(obj, *args, **kw):
        if not hasattr(obj, 'sessionToken'):
            message = '%s requires a logged-in session' % func.__name__
            raise ResourceRequestLoginRequired(message)
        return func(obj, *args, **kw)
    return ret
394294
def _on_login(self, user):
        
        self._bot = bool(user.bot)
        self._self_input_peer = utils.get_input_peer(user, allow_self=False)
        self._authorized = True

        return user
1140914
def admin_required(function=None):
    
    def check_perms(user):
        # if user not logged in, show login form
        if not user.is_authenticated:
            return False
        # if this site doesn't allow admin access, fail
        if settings.ADMIN_IGNORED:
            raise PermissionDenied
        # check if the user has admin rights
        if not user.is_admin:
            raise PermissionDenied
        return True

    actual_decorator = user_passes_test(check_perms, login_url=_login_url)
    if function:
        return actual_decorator(function)
    return actual_decorator
498914
def required(self, fn):
        """"""
        @functools.wraps(fn)
        def decorated(*args, **kwargs):
            if (not self._check_auth()
               # Don't try to force authentication if the request is part
               # of the authentication process - otherwise we end up in a
               # loop.
               and request.blueprint != self.blueprint.name):
                return redirect(url_for("%s.login" % self.blueprint.name,
                                        next=request.url))
            return fn(*args, **kwargs)
        return decorated
195364
def _verify_authentication(self, handler, args, kwargs):
        
        if not self.user_manager.session_logged_in():
            raise APIForbidden()
        return handler(*args, **kwargs)
355138
def authenticated(func):
    
    @wraps(func)
    def wrapper(*args, **kwargs):
        self = args[0]
        if self.refresh_token is not None and \
           self.token_expiration_time <= dt.datetime.utcnow():
            self.re_authenticate()
        return func(*args, **kwargs)
    return wrapper
647394
def authenticated_users(func):
    
    is_object_permission = "has_object" in func.__name__

    @wraps(func)
    def func_wrapper(*args, **kwargs):
        request = args[0]
        # use second parameter if object permission
        if is_object_permission:
            request = args[1]

        if not(request.user and request.user.is_authenticated):
            return False

        return func(*args, **kwargs)

    return func_wrapper
503100
def login_required(view):
    """"""

    @functools.wraps(view)
    def wrapped_view(**kwargs):
        if g.user is None:
            return redirect(url_for("auth.login"))

        return view(**kwargs)

    return wrapped_view
852338
def login_required(function=None, username=None, basic=False, must=None):
    

    if function and not callable(function):
        raise ValueError(
            'Decorator receives only named arguments, '
            'try login_required(username="foo")'
        )

    def check(validators):
        """Return in the first validation error, else return None"""
        if validators is None:
            return
        if not isinstance(validators, (list, tuple)):
            validators = [validators]
        for validator in validators:
            error = validator(get_username())
            if error is not None:
                return SimpleLogin.get_message('auth_error', error), 403

    def dispatch(fun, *args, **kwargs):
        if basic and request.is_json:
            return dispatch_basic_auth(fun, *args, **kwargs)

        if is_logged_in(username=username):
            return check(must) or fun(*args, **kwargs)
        elif is_logged_in():
            return SimpleLogin.get_message('access_denied'), 403
        else:
            flash(SimpleLogin.get_message('login_required'), 'warning')
            return redirect(url_for('simplelogin.login', next=request.path))

    def dispatch_basic_auth(fun, *args, **kwargs):
        simplelogin = current_app.extensions['simplelogin']
        auth_response = simplelogin.basic_auth()
        if auth_response is True:
            return check(must) or fun(*args, **kwargs)
        else:
            return auth_response

    if function:
        @wraps(function)
        def simple_decorator(*args, **kwargs):
            """This is for when decorator is @login_required"""
            return dispatch(function, *args, **kwargs)
        return simple_decorator

    def decorator(f):
        """This is for when decorator is @login_required(...)"""
        @wraps(f)
        def wrap(*args, **kwargs):
            return dispatch(f, *args, **kwargs)
        return wrap
    return decorator
928203
def is_logged_in(self, name_id):
        
        identity = self.users.get_identity(name_id)[0]
        return bool(identity)
903671
private String isLoggedIn() throws RuntimeException {
        if(authManager != null && authManager.getUser() != null && authManager.getUser().getAuthToken() != null){
            return "CUSTOM " + authManager.getUser().getAuthToken();
        } else {
            throw new RuntimeException("User state error.");
        }
    }
372760
def user_loggedin(sender, **kwargs):
    
    values = {
        'value': 1,
        'path': kwargs['request'].path,
        'user_id': str(kwargs['user'].pk),
        'username': kwargs['user'].username,
    }
    write('user_logins', values=values)
1154438
private String isLoggedIn() throws RuntimeException {
        if(this.getUser() != null && this.getUser().getAuthToken() != null){
            return "CUSTOM " + this.getUser().getAuthToken();
        } else {
            throw new RuntimeException("User state error.");
        }
    }
687450
def confirm_login():
    '''
    
    '''
    session['_fresh'] = True
    session['_id'] = current_app.login_manager._session_identifier_generator()
    user_login_confirmed.send(current_app._get_current_object())