/** * @param \EasyBib\OAuth2\Client\TokenResponse\TokenResponse $tokenResponse */ public function updateFromTokenResponse(TokenResponse $tokenResponse) { // don't use replace(), as that resets first and then sets $this->session->set(self::KEY_ACCESS_TOKEN, $tokenResponse->getToken()); $this->session->set(self::KEY_REFRESH_TOKEN, $tokenResponse->getRefreshToken()); $this->session->set(self::KEY_EXPIRES_AT, $this->expirationTimeFor($tokenResponse)); }
public function loginAction(Request $request) { // Récupération du login et mot de passe $login = $request->request->get("username"); $pass = $request->request->get("password"); if (!empty($login) && $login !== "" && !empty($pass) && $pass !== "") { // $isConnected = AuthentificationLDAP::open($login, $pass); if (AuthentificationLDAP::open($login, $pass)) { AuthentificationLDAP::close(); $session = new Session(); // Rentre le nom d'utilisateur en session $session->set('username', $login); $session->set('password', $pass); // On recupère la promotion de l'étudiant qu'on met en session également $promotion = AuthentificationLDAP::getPromotion($login, $pass); $session->set('promotion', $promotion); // Ainsi qu'un boolean pour savoir si l'utilisateur est admin $isAdmin = AuthentificationLDAP::isAdmin($login, $pass); var_dump($isAdmin); if ($isAdmin) { $session->set("admin", true); } else { $session->set("admin", false); } $url = $this->generateUrl("glpmr_peripherique_gestion"); } else { CustomError::showMessage("Identifiants incorrects"); $url = $this->generateUrl("glpmr_authentification_homepage"); } } else { CustomError::showMessage("Il faut renseigner tous les champs"); $url = $this->generateUrl("glpmr_authentification_homepage"); } return $this->redirect($url); }
/** * @param InteractiveLoginEvent $event */ public function onInteractiveLogin(InteractiveLoginEvent $event) { $user = $event->getAuthenticationToken()->getUser(); if (null !== $user->getLocale()) { $this->session->set('_locale', $user->getLocale()); } }
/** * @inheritdoc */ public function setCart(Cart $cart) { $lineItems = $cart->getLineItems()->map(function (LineItem $lineItem) { return $lineItem->getQuantity()->getValue(); }); $this->session->set(self::NAME, $lineItems->toArray()); }
public function getCurrentSite(Request $request) { $currentSite = null; $siteId = $request->get('site'); if (!$siteId && $this->session->has(self::SESSION_NAME)) { $currentSiteId = $this->session->get(self::SESSION_NAME); $currentSite = $this->siteManager->find($currentSiteId); if (!$currentSite) { $sites = $this->getSites(); if (count($sites) > 0) { $currentSite = $this->getSites()[0]; } } } else { foreach ($this->getSites() as $site) { if ($siteId && $site->getId() == $siteId) { $currentSite = $site; } elseif (!$siteId && $site->getIsDefault()) { $currentSite = $site; } } if (!$currentSite && count($this->sites) > 0) { $currentSite = $this->sites[0]; } } if ($currentSite) { $this->session->set(self::SESSION_NAME, $currentSite->getId()); } return $currentSite; }
/** * {@inheritdoc} */ protected function getSessionToken() { if (!$this->session->has($this->name)) { $this->session->set($this->name, sha1(uniqid(rand(), true))); } return $this->session->get($this->name); }
/** * Place order and clear cart * @throws \Simplon\Mysql\MysqlException */ public function placeOrder($billingStreet, $billingCity, $billingState, $billingZip, $shippingStreet, $shippingCity, $shippingState, $shippingZip, $email) { $query = ' SELECT * FROM aca_cart_product WHERE cart_id= :cartId'; // Get all user orders that are in the cart $data = $this->cart->getCart(); // If there are products in the order if (!empty($data)) { // Add order to order table $orderId = $this->db->insert('aca_order', array('user_id' => $this->session->get('user_id'), 'billing_street' => $billingStreet, 'billing_city' => $billingCity, 'billing_state' => $billingState, 'billing_zip' => $billingZip, 'shipping_street' => $shippingStreet, 'shipping_city' => $shippingCity, 'shipping_state' => $shippingState, 'shipping_zip' => $shippingZip, 'email' => $email)); // Iterate through products and add to order product table foreach ($data as $product) { $this->db->insert('aca_order_product', array('order_id' => $orderId, 'product_id' => $product['cp_product_id'], 'quantity' => $product['cp_quantity'], 'price' => $product['cp_price'])); } // Delete order from cart $this->cart->removeCart(); // Add orderId to session $this->session->set('order_id', $orderId); } }
/** * @param \Symfony\Component\HttpFoundation\Session\Session $session */ public function handleSessionValidation(SymfonySession $session) { $ip_address = new IPAddress($this->request->getClientIp()); $request_ip = $ip_address->getIp(IPAddress::FORMAT_IP_STRING); $invalidate = false; $ip = $session->get('CLIENT_REMOTE_ADDR'); $agent = $session->get('CLIENT_HTTP_USER_AGENT'); $request_agent = $this->request->server->get('HTTP_USER_AGENT'); // Validate the request IP if ($this->shouldCompareIP() && $ip && $ip != $request_ip) { if ($this->logger) { $this->logger->debug('Session Invalidated. Session IP "{session}" did not match provided IP "{client}".', array('session' => $ip, 'client' => $request_ip)); } $invalidate = true; } // Validate the request user agent if ($this->shouldCompareAgent() && $agent && $agent != $request_agent) { if ($this->logger) { $this->logger->debug('Session Invalidated. Session user agent "{session}" did not match provided agent "{client}"', array('session' => $agent, 'client' => $request_agent)); } $invalidate = true; } if ($invalidate) { $session->invalidate(); } else { if (!$ip && $request_ip) { $session->set('CLIENT_REMOTE_ADDR', $request_ip); } if (!$agent && $request_agent) { $session->set('CLIENT_HTTP_USER_AGENT', $request_agent); } } }
/** * Writes contents into storage/session * * @param mixed $contents * * @return void */ public function write($contents) { if (!$this->session->isStarted()) { $this->session->start(); } $this->session->set(self::SESSION_STO_KEY . '-' . $this->namespace, $contents); }
/** * @Route("/", name="homepage") */ public function indexAction(Request $request) { //start session $session = new Session(new PhpBridgeSessionStorage()); $session->start(); $session->set('date', time()); //get products from DB $products = $this->getDoctrine()->getRepository('AppBundle:Cart')->findAll(); //get session products $sessionProducts = $session->get('products'); $productArray = null; //if post save to db && session if ($request->isMethod('post')) { $postProduct = [$request->request->get('product')]; if (!empty($sessionProducts)) { $productArray = array_merge($sessionProducts, $postProduct); } else { $productArray = $postProduct; } $productArray = array_unique($productArray); } $session->set('products', $productArray); // this helps create cookie for session $session->save(); return $this->render('default/index.html.twig', array('sessionProducts' => $productArray, 'products' => $products)); }
/** * {@inheritdoc} */ public function loadUserByOAuthUserResponse(UserResponseInterface $response) { $content = $response->getResponse(); $resourceOwner = $response->getResourceOwner(); try { $user = $this->loadUserByServiceAndId($resourceOwner->getName(), $content['id']); return $user; } catch (\Exception $e) { $name = $response->getRealName(); $nameArray = explode(' ', $name, 2); $firstName = $response->getFirstName(); $lastName = $response->getLastName(); if (empty($firstName) || empty($lastName)) { if (array_key_exists(0, $nameArray)) { $firstName = ucfirst(strtolower($nameArray[0])); } if (array_key_exists(1, $nameArray)) { $lastName = ucfirst(strtolower($nameArray[1])); } } $user = array(); $user['firstName'] = $firstName; $user['lastName'] = $lastName; $user['username'] = $this->createUsername($response->getNickname()); $user['mail'] = $response->getEmail(); $this->session->set('icap.oauth.user', $user); $resourceOwnerArray = array('name' => $resourceOwner->getName(), 'id' => $content['id']); $this->session->set('icap.oauth.resource_owner', $resourceOwnerArray); throw $e; } }
/** * @Route("/checkIn", name="loginCheck") * @Template() */ public function checkInAction() { if (isset($_GET['connectData'])) { //Jeżeli są dane, to loguje $wykop = $this->get('WykopApi'); $connect_data = $wykop->handleConnectData(); $session = new Session(); $session->set('token', $connect_data['token']); $session->set('sign', $connect_data['sign']); $profile = $wykop->doRequest('profile/index/' . $connect_data['login']); if (!$wykop->isValid()) { throw new Exception($this->api->getError()); } else { $answer = $wykop->doRequest('user/login', array('login' => $profile['login'], 'accountkey' => $session->get('token'))); if (!$wykop->isValid()) { throw new Exception($this->api->getError()); } $roles = ['ROLE_USER_WYKOP']; if ($profile['login'] === 'anonim1133') { $roles[] = 'ROLE_ADMIN'; } $token = new UsernamePasswordToken($profile['login'], $answer['userkey'], 'wykop', $roles); $token->setAttribute('wykop_login', $profile['login']); $token->setAttribute('wykop_sex', $profile['sex']); $token->setAttribute('wykop_group', $profile['author_group']); $token->setAttribute('wykop_avatar', $profile['avatar_med']); $token->setAttribute('wykop_login_date', new \DateTime('now')); $this->get('security.token_storage')->setToken($token); $session->set('_security_main', serialize($token)); } } return $this->redirect('/'); }
/** * @inheritdoc */ public function getUrl(ResourceObjectInterface $resource) { $url = $this->getLocationConfig('url', $resource->getLocation(), $this->config); preg_match_all('/\\{(\\w+)\\}/', $url, $matches); $accessor = new PropertyAccessor(); if (isset($matches[1])) { foreach ($matches[1] as $token) { if ($token === 'id') { //when mapping information contains {id} //for security reasons instead of set the real resource id //set a random value and save in session with the real id //the param converter resolve the real resource related for given hash //and keep the resource private for non public access $value = md5(mt_rand()); $this->session->set('_resource/' . $value, $resource->getId()); } else { if ($accessor->isReadable($resource, $token)) { $value = $accessor->getValue($resource, $token); } else { $msg = sprintf('Invalid parameter "{%s}" in %s resource mapping.', $token, $resource->getLocation()); throw new \InvalidArgumentException($msg); } } $url = str_replace("{{$token}}", $value, $url); } } return str_replace('//', '/', $url); }
/** * Sets the authentication flag. * * @param bool $authenticated The authentication status */ public function setAuthenticated($authenticated) { if (true === $authenticated) { $this->session->set('_auth_until', time() + $this->timeout); } else { $this->session->remove('_auth_until'); } }
public function it_do_not_authenticate_channel_when_cookie_name_is_missing(Session $session, ParameterBag $cookies) { $session->getName()->shouldBeCalled()->willReturn('session'); $cookies->get('session')->shouldBeCalled()->willReturn('invalid_channel'); $session->set('socketId', 1)->shouldNotBeCalled(); $session->set('channelName', 'new_channel')->shouldNotBeCalled(); $this->authenticate(1, 'new_channel')->shouldReturn(false); }
public function acceptCookiesAction($id) { array_push($this->blockIds, $id); $this->session->set(self::SESSION_KEY, $this->blockIds); $response = new JsonResponse(); $response->setData(['message' => 'Cookiewall block added to session']); return $response; }
/** * {@inheritdoc} */ public function save(BasketInterface $basket) { if ($basket->getCustomerId()) { $this->basketManager->save($basket); } else { $this->session->set(BasketSessionFactory::SESSION_BASE_NAME . 'new', $basket); } }
public function testCanUnsetAVariable() { $this->session->set('testUnset', 5); $this->assertEquals(5, $this->access->get('testUnset')); $this->access->remove('testUnset'); $this->assertFalse($this->session->has('testUnset')); $this->assertFalse($this->access->has('testUnset')); }
public function setUp() { parent::setUp(); $this->session = new Session(new MockArraySessionStorage()); $this->session->set(StateStore::KEY_STATE, 'ABC123'); $this->tokenStore = new TokenStore($this->session); $this->stateStore = new StateStore($this->session); $this->oauthSession = $this->createSession(); }
public function loginAsTestUserAction(Session $session, Player $user) { if (!$user->isTestUser()) { throw new Exception("The player you specified is not a test user!"); } $session->set("playerId", $user->getId()); $session->set("username", $user->getUsername()); return $this->goHome(); }
/** * @return ConnectionStore */ private function getStore() { $store = $this->session->get(self::CONNECTION_STORE_SESSION_INDEX, null); if (!$store) { $store = new ConnectionStore(); $this->session->set(self::CONNECTION_STORE_SESSION_INDEX, $store); } return $store; }
/** * @return string */ public function getState() { if ($state = $this->get(self::KEY_STATE)) { return $state; } $state = $this->stateGenerator->generate(); $this->session->set(self::KEY_STATE, $state); return $state; }
/** * @param Auth $auth * @param integer $duration * * @return Response|void */ public function login(Auth $auth, $duration = 0) { $user_groups = serialize($auth->getUserGroups()); $user_id = $auth->getUserId(); $user_name = $auth->getUserName(); $this->session->migrate(false, $duration); $this->session->set(self::USER_ID, $user_id); $this->session->set(self::USER_NAME, $user_name); $this->session->set(self::USER_GROUPS, $user_groups); }
public function authorize($redirectUri) { // Set the "auth" request option to "oauth" to sign using oauth $res = $this->client->post('oauth/request_token', array('body' => ['oauth_callback' => $redirectUri])); $params = (string) $res->getBody(); parse_str($params, $tokens); $this->session->set('oauth_token', $tokens['oauth_token']); $this->session->set('oauth_token_secret', $tokens['oauth_token_secret']); return new RedirectResponse("https://api.twitter.com/oauth/authorize?oauth_token=" . $tokens['oauth_token']); }
/** * @param array $sessionValues */ public function setSessionValues($sessionValues) { if (is_array($sessionValues)) { foreach ($sessionValues as $key => $value) { $longKey = $this->namespace . $key; $this->session->set($longKey, $value); } $this->session->save(); } }
/** * @param GetResponseForExceptionEvent $event */ public function onAccessDeniedException(GetResponseForExceptionEvent $event) { if ($event->getException() instanceof AccessDeniedHttpException) { $this->session->invalidate(); $this->session->set(SecurityContextInterface::ACCESS_DENIED_ERROR, ['message' => 'You are not allowed']); $this->securityContext->setToken(null); $route = $this->router->generate('oro_distribution_security_login'); $event->setResponse(new RedirectResponse($route)); } }
public function pushMessage($messageType, $messageTitle, $messageContent) { if ($this->session->has(Messages::$_MESSAGES_POOL_NAME)) { $poolOfMessages = $this->session->get(Messages::$_MESSAGES_POOL_NAME); } else { $poolOfMessages = array(); } $poolOfMessages[] = array("type" => $messageType, "title" => $messageTitle, "message" => $messageContent); $this->session->set(Messages::$_MESSAGES_POOL_NAME, $poolOfMessages); }
public function getMediacenterUserToken(User $user, Mediacenter $mediacenter) { $hasInwicastToken = $this->session->get("has_inwicast_token"); $token = $this->session->getId(); if (!$hasInwicastToken) { $this->mediacenterUserRepository->createInwicastUserIfNotExists($user, $token, $mediacenter); $this->session->set("has_inwicast_token", true); } return $token; }
/** * Grants access to ajaxfilemanager * * @param array $authorizedRoles * @return void */ public function authorize(array $authorizedRoles) { $authorized = false; if ($token = $this->securityContext->getToken()) { $user = $token->getUser(); if ($user != 'anon.' && count(array_intersect($user->getRoles(), $authorizedRoles)) > 0) { $authorized = true; } } $this->session->set('authorized', $authorized); }
public function setSessionLogin($username, $userid, $usertype) { $session = new Session(); $session->set('username', $username); $session->set('usertype', $usertype); // $session->set('usertype',$usertype); // $session->set('userid',$userid); // $this->get('session')->set('username',$username); // $this->get('session')->set('usertype',$usertype); // $this->get('session')->set('username',$username); }