Set user session
    :param user: user object chould be model instance or dict
    :return:
334493
def set_user_session(user):
    
    from uliweb import settings, request

    user_fieldname = settings.get_var('AUTH/GET_AUTH_USER_FIELDNAME', 'id')
    share_session = settings.get_var('AUTH/AUTH_SHARE_USER_SESSION', False)
    if isinstance(user, dict):
        user_id = user[user_fieldname]
    else:
        user_id = getattr(user, user_fieldname)

    if share_session:
        cache = functions.get_cache()
        key = get_user_session_key(user_id)
        session_id = cache.get(key, None)
        log.debug('Auth: user session user_id={}, session_id={}, key={}'.format(user_id, session_id, key))
        if not session_id:
            request.session.save()
            log.debug('Auth: set user session mapping userid={}, '
                      'session_id={}, expiry time={}'.format(user_id,
                                                             request.session.key,
                                                             request.session.expiry_time))
            cache.set(key, request.session.key, expire=request.session.expiry_time)
        elif session_id != request.session.key:
            log.debug('Auth: load oldkey={}, key={}'.format(request.session.key, session_id))
            request.session.delete()
            request.session.load(session_id)
    if isinstance(user, dict):
        request.session[_get_auth_key()] = user
    else:
        request.session[_get_auth_key()] = user_id
    request.user = user
814843
def _create_session(self):
        
        self.driver = requests.Session(**self.driver_args)
        # Set default headers
        self.update_headers(self.current_headers)
        self.update_cookies(self.current_cookies)
        self.set_proxy(self.current_proxy)
902637
protected function setUserSessionBackup()
    {
        $this->userSessionBackup = isset($_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL]) ? $_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL] : null;
        $fakeUser = new \stdClass();
        $fakeUser->username = self::SESSION_PARAMETER_FORM_COMPONENT;
        $_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL] = $fakeUser;
    }
898293
public static void setUser(Object user)
    {
        HttpSession session = WebContextFactory.get().getSession(true);
        session.setAttribute(USER, user);
    }
1160973
def _set_session(self, username, realname, email, language):
        
        self._session.loggedin = True
        self._session.email = email
        self._session.username = username
        self._session.realname = realname
        self._session.language = language
        self._session.token = None
        if "lti" not in self._session:
            self._session.lti = None
1225633
def update_user(self, instance, user, name=None, password=None, host=None):
        
        return instance.update_user(user, name=name, password=password,
                host=host)
322614
def get_user_from_session(session_key):
    
    session = Session.objects.get(session_key=session_key)
    session_data = session.get_decoded()
    uid = session_data.get('_auth_user_id')
    user = get_user_model().objects.filter(id=uid).first()  # get object or none
    return user
864936
protected function startUserSession(object $user): Session
    {
        $session = new Session();

        $session->set('is_granted', true);
        $session->set('user', $user);

        return $session;
    }
672537
def _login(self, user, provider=None, remember=False, force=False, **attrs):
        
        user.last_login_at = datetime.datetime.now()
        user.last_login_provider = provider or self.options["default_auth_provider_name"]
        user.last_login_from = request.remote_addr
        populate_obj(user, attrs)
        save_model(user)
        flask_login.login_user(user, remember=remember, force=force)
884842
def _register_oauth_session_user(self, user):
        
        oauth_session = get_oauth_session()
        if oauth_session:
            if "provider" in oauth_session and "user_id" in oauth_session:
                user.add_federated_login(provider=oauth_session.get("provider"),
                                      federated_id=oauth_session.get("user_id"))
        delete_oauth_session()
813742
def create_user(user, opts = {})
      data, _status_code, _headers = create_user_with_http_info(user, opts)
      return data
    end
438011
def create_user(self, instance, name, password, database_names, host=None):
        
        return instance.create_user(name=name, password=password,
                database_names=database_names, host=host)
1344911
def user_session_show(self, user_id, id, **kwargs):
        ""
        api_path = "/api/v2/users/{user_id}/sessions/{id}.json"
        api_path = api_path.format(user_id=user_id, id=id)
        return self.call(api_path, **kwargs)
364743
def _get_session(self, session):
        

        if not session:
            logger.debug('(SESSION_CREATE) User: %s' % self._user)
            s = requests.Session()
            s.auth = HTTPBasicAuth(self._user, self._password)
        else:
            logger.debug('(SESSION_CREATE) Object: %s' % session)
            s = session

        s.headers.update(
            {
                'content-type': 'application/json',
                'accept': 'application/json',
                'User-Agent': 'pysnow/%s' % pysnow.__version__
            }
        )

        return s
477196
def user(self, login=None):
        '''
        
        '''
        if login:
            url = '%s/user/%s' % (self.domain, login)
        else:
            url = '%s/user' % (self.domain)

        res = self.session.get(url, verify=self.session.verify)
        self._check_response(res)

        return res.json()
739292
def _load_user(self):
        ''''''

        if self._user_callback is None and self._request_callback is None:
            raise Exception(
                "Missing user_loader or request_loader. Refer to "
                "http://flask-login.readthedocs.io/#how-it-works "
                "for more info.")

        user_accessed.send(current_app._get_current_object())

        # Check SESSION_PROTECTION
        if self._session_protection_failed():
            return self._update_request_context_with_user()

        user = None

        # Load user from Flask Session
        user_id = session.get('user_id')
        if user_id is not None and self._user_callback is not None:
            user = self._user_callback(user_id)

        # Load user from Remember Me Cookie or Request Loader
        if user is None:
            config = current_app.config
            cookie_name = config.get('REMEMBER_COOKIE_NAME', COOKIE_NAME)
            header_name = config.get('AUTH_HEADER_NAME', AUTH_HEADER_NAME)
            has_cookie = (cookie_name in request.cookies and
                          session.get('remember') != 'clear')
            if has_cookie:
                cookie = request.cookies[cookie_name]
                user = self._load_user_from_remember_cookie(cookie)
            elif self._request_callback:
                user = self._load_user_from_request(request)
            elif header_name in request.headers:
                header = request.headers[header_name]
                user = self._load_user_from_header(header)

        return self._update_request_context_with_user(user)
1322207
def setUser(self, *args, **kwargs):
        
        try:
            user = self.mambuuserclass(entid=self['assignedUserKey'], *args, **kwargs)
        except KeyError as kerr:
            err = MambuError("La cuenta %s no tiene asignado un usuario" % self['id'])
            err.noUser = True
            raise err
        except AttributeError as ae:
            from .mambuuser import MambuUser
            self.mambuuserclass = MambuUser
            try:
                user = self.mambuuserclass(entid=self['assignedUserKey'], *args, **kwargs)
            except KeyError as kerr:
                err = MambuError("La cuenta %s no tiene asignado un usuario" % self['id'])
                err.noUser = True
                raise err

        self['user'] = user

        return 1