Creates an active session for a user.

@param string  $sid    session ID
@param int     $userId
@param Request $req

@return ActiveSession
179042
private function createSession($sid, $userId, Request $req)
    {
        $sessionCookie = session_get_cookie_params();
        $expires = time() + $sessionCookie['lifetime'];

        $session = new ActiveSession();
        $session->id = $sid;
        $session->user_id = $userId;
        $session->ip = $req->ip();
        $session->user_agent = $req->agent();
        $session->expires = $expires;
        $session->save();

        return $session;
    }
886385
public function enableAction(Request $request, $userClass)
    {
        $confirmationToken = $request->query->get('token');
        if (null === $confirmationToken) {
            return new JsonResponse(null, 404);
        }

        try {
            $this->get('bengor_user.' . $userClass . '.api_command_bus')->handle(
                new EnableUserCommand($confirmationToken)
            );

            return new JsonResponse();
        } catch (UserTokenNotFoundException $exception) {
            return new JsonResponse(
                sprintf(
                    'The "%s" confirmation token does not exist',
                    $confirmationToken
                ),
                400
            );
        }
    }
1258357
def setup_session(endpoint_context, areq, uid, client_id='', acr='', salt='salt',
                  authn_event=None):
    
    if authn_event is None and acr:
        authn_event = AuthnEvent(uid=uid, salt=salt, authn_info=acr,
                                 authn_time=time.time())

    if not client_id:
        client_id = areq['client_id']

    sid = endpoint_context.sdb.create_authz_session(authn_event, areq,
                                                    client_id=client_id,
                                                    uid=uid)
    endpoint_context.sdb.do_sub(sid, uid, '')
    return sid
1122398
public function serverSelect($sid, $virtual = null)
  {
    if($this->whoami !== null && $this->serverSelectedId() == $sid) return;

    $virtual = ($virtual !== null) ? $virtual : $this->start_offline_virtual;
    $getargs = func_get_args();

    $this->execute("use", array("sid" => $sid, $virtual ? "-virtual" : null));

    if($sid != 0 && $this->predefined_query_name !== null)
    {
      $this->execute("clientupdate", array("client_nickname" => (string) $this->predefined_query_name));
    }

    $this->whoamiReset();

    $this->setStorage("_server_use", array(__FUNCTION__, $getargs));

    TeamSpeak3_Helper_Signal::getInstance()->emit("notifyServerselected", $this);
  }
1019865
public static function upload_data($userid,$file_data,$session,$offset){
		$expired = time() + self::EXPIRED_SECONDS;
		$url = self::generateResUrl($userid);
		$sign = Auth::appSign($url, $expired);

		$data = array(
            'FileContent' => $file_data,
			'op' => 'upload_slice',
			'session' => $session,
			'offset' => $offset,
        );

        $req = array(
            'url' => $url,
            'method' => 'post',
            'timeout' => 10,
            'data' => $data,
            'header' => array(
                'Authorization:'.$sign,
            ),
        );

		$rsp = Http::send($req);
		$info = Http::info();
		$ret = json_decode($rsp, true);
		if ($ret) {
			if (0 === $ret['code']) {
				$ret['httpcode'] = $info['http_code'];
				return $ret;
			} else {
				return array(
					'httpcode' => $info['http_code'],
					'code' => $ret['code'],
					'message' => $ret['message'],
					'data' => array()
				);
			}
		} else {
			return array(
					'httpcode' => $info['http_code'],
					'code' => self::VIDEO_NETWORK_ERROR,
					'message' => 'network error', 'data' => array()
				);
		}
	}
1189351
public function session_exists($sid) {
        $sid = clean_param($sid, PARAM_FILE);
        if (!$sid) {
            return false;
        }
        $sessionfile = "$this->sessiondir/sess_$sid";
        return file_exists($sessionfile);
    }
449568
public function switchUserStart(User $user, Request $request)
    {
        if (! session()->has('original_user')) {
            session()->put('original_user', $request->user()->id);
        }
        Auth::login($user);

        return back();
    }
233465
public static function doLogout($sid): bool {

		$app = Application::getInstance();
		$db  = Database::getInstance();

		// delete session
		$res = $db->exec('DELETE FROM `sessions` WHERE id = ?', $sid);

		// unset all persistent states
		$app->unsetAllPersistentStates();

		// unset RememberMe
		$app->currentUser->unsetRememberMe();
		
		// reset the user in Application object
		$app->currentUser = NULL;
		
		return (bool)$res;
	
	}
1215309
public Object getSession(HttpServletRequest req) {
        if (req.getCookies() == null) {
            return null;
        }

        Cookie cookie = Arrays.stream(req.getCookies()).filter(c -> c.getName().equalsIgnoreCase("ValidationSession")).findFirst().orElse(null);

        if (cookie == null) {
            return null;
        }
        return this.sessionMap.get(cookie.getValue());
    }
913430
public function inviteAction(Request $request, $userClass)
    {
        $form = $this->get('form.factory')->createNamedBuilder('', InviteType::class, null, [
            'roles'           => $this->getParameter('bengor_user.' . $userClass . '_default_roles'),
            'csrf_protection' => false,
        ])->getForm();

        $form->handleRequest($request);
        if ($form->isValid()) {
            try {
                $this->get('bengor_user.' . $userClass . '.api_command_bus')->handle(
                    $form->getData()
                );

                return new JsonResponse([
                    'user_id' => $form->getData()->id(),
                    'email'   => $form->getData()->email(),
                    'role'    => $form->getData()->roles(),
                ]);
            } catch (UserAlreadyExistException $exception) {
                return new JsonResponse(
                    sprintf(
                        'The %s email is already invited',
                        $form->getData()->email()
                    ),
                    409
                );
            }
        }

        return new JsonResponse(FormErrorSerializer::errors($form), 400);
    }
1079251
public static function can_create_data_deletion_request_for_self(int $userid = null): bool {
        global $USER;
        $userid = $userid ?: $USER->id;
        return has_capability('tool/dataprivacy:requestdelete', \context_user::instance($userid), $userid);
    }
427085
public static function can_create_data_deletion_request_for_children(int $userid, int $requesterid = null): bool {
        global $USER;
        $requesterid = $requesterid ?: $USER->id;
        return has_capability('tool/dataprivacy:makedatadeletionrequestsforchildren', \context_user::instance($userid),
            $requesterid);
    }
1308451
public function createSessionAction(Request $request)
    {
        /** @var $sessionInput \eZ\Publish\Core\REST\Server\Values\SessionInput */
        $sessionInput = $this->inputDispatcher->parse(
            new Message(
                array('Content-Type' => $request->headers->get('Content-Type')),
                $request->getContent()
            )
        );
        $request->attributes->set('username', $sessionInput->login);
        $request->attributes->set('password', $sessionInput->password);

        try {
            $session = $request->getSession();
            if ($session->isStarted() && $this->hasStoredCsrfToken()) {
                $this->checkCsrfToken($request);
            }

            $token = $this->authenticator->authenticate($request);
            $csrfToken = $this->getCsrfToken();

            return new Values\UserSession(
                $token->getUser()->getAPIUser(),
                $session->getName(),
                $session->getId(),
                $csrfToken,
                !$token->hasAttribute('isFromSession')
            );
        } catch (Exceptions\UserConflictException $e) {
            // Already logged in with another user, this will be converted to HTTP status 409
            return new Values\Conflict();
        } catch (AuthenticationException $e) {
            $this->authenticator->logout($request);
            throw new UnauthorizedException('Invalid login or password', $request->getPathInfo());
        } catch (AccessDeniedException $e) {
            $this->authenticator->logout($request);
            throw new UnauthorizedException($e->getMessage(), $request->getPathInfo());
        }
    }
880467
public function deleteAction(Request $request, $userId)
    {
        $successorUserId = $request->request->get('successor');

        $userManager = $this->get('phlexible_user.user_manager');

        $successorUser = $userManager->find($successorUserId);
        $user = $userManager->find($userId);

        $userManager->deleteUserWithSuccessor($user, $successorUser);

        $this->get('phlexible_message.message_poster')
            ->post(UsersMessage::create('User "'.$user->getUsername().'" deleted.'));

        return new ResultResponse(true);
    }
220991
def user_sessions(self, user_id, **kwargs):
        ""
        api_path = "/api/v2/users/{user_id}/sessions.json"
        api_path = api_path.format(user_id=user_id)
        return self.call(api_path, **kwargs)
950453
protected function doInsert($sid, $data, $uid=null) {
		if(is_array($data)) {
			$data = serialize($data);
		}
		
		$sqlData = array(
			'session_id'	=> $sid,
			'session_data'	=> $data
		);
		if(!is_null($uid) && strlen($uid)) {
			$sqlData['uid'] = $uid;
		}
		elseif(!is_null($uid) && !strlen($uid)) {
			// no data in UID; it was specifically supplied empty, make it null in DB
			$sqlData['uid'] = null;
		}
		
		try {
			$sql = 'INSERT INTO '. self::tableName .' '. $this->create_sql_insert_string($sqlData);

			$rowsInserted = $this->db->run_query($sql, $sqlData);
			if($rowsInserted != 1) {
				throw new exception(__METHOD__ .": failed to insert data, rows inserted=(". $rowsInserted .")");
			}
		}
		catch(Exception $e) {
			$this->exception_handler($e->getMessage());
		}
		
		return($sid);
	}
925514
protected function startSession(Request $request)
    {
        $session = $this->manager->driver();

        $session->setId(
            $this->getSessionId($request, $session)
        );

        $session->setRequestOnHandler($request);

        $session->start();

        return $session;
    }