/** * login with facebook sdk * * @param String $appId, $appSecret, $redirectUrl * * @return boolean */ public function login($appId, $appSecret, $redirectUrl) { $redirectUrl = 'http://' . $_SERVER['HTTP_HOST'] . $redirectUrl; $request = new Request(); FacebookSession::setDefaultApplication($appId, $appSecret); $helper = new FacebookRedirectLoginHelper($redirectUrl); try { $session = $helper->getSessionFromRedirect(); } catch (FacebookRequestException $ex) { // When Facebook returns an error } catch (\Exception $ex) { // When validation fails or other local issues } $this->loginurl = $helper->getLoginUrl(); if ($session) { $FacebookRequest = new FacebookRequest($session, 'GET', '/me'); $response = $FacebookRequest->execute(); $graph = $response->getGraphObject(GraphUser::classname()); $name = $graph->getName(); $accessToken = $session->getAccessToken(); $request->setSession('facebook', (string) $accessToken); return true; } else { return false; } }
public function view() { $request = new Request(); $post = ""; $get = ""; if ($request->post['post']) { $post = $request->post['post']; } if ($request->get['get']) { $get = $request->get['get']; } //set cookie $request->setCookie('test', 'testValue', 300); $cookie = $request->cookie['test']; //destroy cookie $request->destroyCookie('test'); //check if an file was sent if (isset($request->files['file'])) { $fileset = 'true'; } else { $fileset = 'false'; } $server = $request->server; //set session $request->setSession('test', 'testSessionValue'); $session = $request->session['test']; return $this->render("usability:http.html", array('post' => $post, 'get' => $get, 'cookie' => $cookie, 'fileset' => $fileset, 'server' => $server, 'session' => $session)); }
/** * * The loginMethod check if logged or login when the datas are right * * @return boolean */ public function login() { $request = new Request(); $em = new EntityManager(); $securityConfig = Config::securityConfig(); $identificator = $securityConfig['identificator']; $passwordKey = $securityConfig['passwordKey']; $entityShortcut = $securityConfig['entityShortcut']; //get the dbConnection $em->getConnection(); $entity = $em->getEntity($entityShortcut); //if the authentificationSession is empty then check then loginRequest if (empty($request->session['userid'])) { //check if the authentificationPostParameters aren't empty then check if the datas are valid then return if (!empty($request->post[$identificator]) && !empty($request->post[$passwordKey])) { //set the identificatorValue and the passwordValue $identificatorValue = $request->post[$identificator]; $passwordValue = $request->post[$passwordKey]; //salt and hash the password $salt1 = "74930slei93kdie9i3kdie93kdie9kdie93kdie93kdie93kdie9kei309ioögeut3fhsoöiutusü0emiß+m0gü8wvtpomuv,ß+,xiü.uim vüiri3mß"; $salt2 = "dsajkflsafis543908530ljfksld4sdf34453ß0klsdjflkdslkjflksjflkdsjflkjdslkfjdslkfjlkdsjflkdsjfldsjlfdslkflsdjflkdsjlfdslkjfldskjflkjdslfjdslklsl"; $password = hash('sha512', $salt1 . $passwordValue . $salt2); //get identificatorValue $em->find($identificator, $identificatorValue); $identificatorValue = call_user_func(array($entity, 'get' . ucfirst($identificator))); //if identificatorValue isn't empty and if the password is right return true else set an error number if (!empty($identificatorValue) && $entity->getPassword() === $password) { $this->userObject = $entity; $request->setSession('userid', $entity->getID()); return true; } else { //the identificatior is empty or password $this->errorNumber = 1; } } else { //one of the postParameters is/are empty $this->errorNumber = 2; } } else { //set the userObject $this->userObject = $entity; $em->find('id', $request->session['userid']); return true; } return false; }