Privacy page redirection in drupal 7 - drupal-7

In my project I have a privacy policy form page. After login, though custom code I am redirecting to that page. When user check the privacy policy, I will store the data in variable table.
What I need is if I click any page with out accepting the privacy policy, I need to again redirect to privacy page. I need to check this logic in every page load. Where I need to check this? Is it on hook_init(). When I given this in hook_init(), which is not working. Please see my below code.
$getAcc = variable_get('privacy_38');
if($getAcc == 1) {
global $user;
$accessRedirection = 'privacy/accept';
$afterUserView = 'user/' . $user->uid . '/view';
$options = array('query' => array('destination' => $afterUserView));
drupal_goto($accessRedirection, $options
}
Where I need to put this code. Is it in theme template. If so, in which hook, I need to put this code. Please anybody help me.

That's definitely the place to do it (hook_init), but will take a bit more than what you have to fully achieve what you need. There's a module that implements something very similar to this that you might want to have a look at if you haven't yet: https://www.drupal.org/project/legal
Hope this helps!

Related

Restrict access to a page in Gatsby.js to logged in users

On my gatsby.js static site, I want to restrict access to my pages/dashboard page using client-side authentication. The plug-in, gatsby-plugin-meta-redirect says that I can create a redirect with this...
createRedirect({ fromPath: '/old-url', toPath: '/new-url', isPermanent: true });
...but I'm not sure where to place that in my code. I'm assuming gatsby-node.js, but I'm not sure how.
I want to do something like this,
if (user.loggedIn) {
// redirect to '/dashboard'
} else {
// redirect to '/'
}
This is assuming that the state of user is available throughout the site. Is this possible?
Also, in the gatsby-plugin-meta-redirect docs, it states that this plugin should be put last in the array in gatsby-config.js. But I already have gatsby-plugin-netlify placed last. Would that be a problem?
What you can do is give a programmatic, non-direct access to the /dashboard page using navigateTo in Link.
See this issue.

Setting permissions in cakephp Pages controller

I followed Andrew Perkins excellent tutorial on setting up permissions in CakePHP 2.0.
My question, however, relates to how to use the allow and deny method in the Pages controller. Currently I have $this->Auth->allow('display') which allows all methods in the Pages controller to be view.
What if I only want the home page allowed but the rest denied? How do I code that?
Thanks in advance.
Make sure you have copied the PageController.php to your app/Controller folder. Then, add a beforeFilter callback method and set access based on the passed page parameter:
public function beforeFilter() {
// Use $this->request->pass to get the requested page name/id
// Decide on access with $this->Auth->allow()
}
This should solve your problem.
You can find more information on request's lifecycle in CakePHP manual. That's pretty useful stuff.
Have you tried this code?
You can out it into your PageController or into your Controller directly
$views = array ('index'); //array of view that you want allow
$this->Auth->allow($views);

Logout an user in CakePHP

I'd like to know whether it's possible to logout an user in CakePHP.
I don't want to logout the current user, but to end the session of a selected user.
Thank you.
I imagine you could do a simple conditional check:
With authsome component:
if (Authsome::get('User.id') == $idOfUserYouWantToLogout){
Authsome::logout();
}
Note: you could of course use $this->Authsome->get('User.id') and $this->Authsome->logout() if you wanted.
With normal auth component:
if ($this->Auth->get('id') == $idOfUserYouWantToLogout){
$this->Auth->logout();
}
This is kind of a work-around, because it will log out the current user, but only if they are the user that you want logged out.
Basically it isn't possible. CakePHP at least doesn't have some internal ways to do it.

How can a canvas app redirect to another tab such as the Wall?

I'm trying to create a so-called "Welcome Tab" app for a business page. What I want to happen is that either my canvas app displays a message when a vistor hasn't Liked the page, or the normal "Wall" tab when they have.
I've done this by setting my canvas page as the default landing tab and then checking the 'liked' parameter passed by Facebook and my PHP can successfully deterime what it should be doing. As per this extract:
if ($results['page']['liked'] == 1) {
$redirect = $pages[$results['page']['id']]['liked']; } else {
$redirect = $pages[$results['page']['id']]['unliked']; }
header('Location: '.$baseurl.$redirect);
However using header() to load a page which in turn contains a little bit of Javascript to do a "top.location = http://www.facebook.com/pages/xxxxxxx/yyyyyyy?sk=wall" redirection takes a second or so and results in the visitor seeing a blank canvas page briefly and then a full page reload.
However this page https://www.facebook.com/ourcarnoustie seems to be able to instantly display the Wall to Likers, and its own "Welcome" tab to non-Likers without any apparent delay or refresh.
Any suggestions or pointers would be greatly appreciated. Thanks.
Facebook defaults to the wall for people who've liked the page. In fact it's usually the reverse that's requested on how to set the welcome page for everyone :)
For what you're asking you shouldn't need to do anything as that's the behavior.
Hmmm this is funny you posted this cause I've just landed myself with the same issue today.
I'm using this php currently to change my html between 'liked' and 'not liked...
<?php
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["page"]["liked"])) {
//echo 'UNLIKED';
} else {
//echo 'USER HAS LIKED';
}
?>
But I also need to find away some how for the users that have already liked the page, to be redirect to the wall - instead of seeing the welcome app.
Because it's inside an iframe, do you think it's possible?
I also looked at that facebook page with welcome app that you said works, and it does work so must be possible unless its an older app that's not using a iframe to pull in the content.
I've found the answer to my own question.
The Facebook Pages FAQ includes this statement:
Why can't I choose a landing tab for existing followers of my Page?
The default landing tab can only be adjusted for people that are not following your Page. Once they follow your Page, they will see the Page's wall as the default.
So people who LIKE the page are automatically taken to the Wall page regardless of the landing tab selected in the Page settings. Therefore the landing tab app doesn't have to do any of the redirection I have been trying to figure out as Facebook already does it anyway!

CakePHP Logs Me Out Prematurely

I have a CakePHP app that seems to be terminating my session on one specific action. I have a page which, when a link is clicked, launches a Fancybox overlay of the iframe type. In that overlay, the user fills out and submits a form. The form is submitted properly, does its work (including sending an email), loads the success view and lets me close the overlay, but as soon as I try to get to any other page, I'm sent to the login screen to reauthenticate.
The value of my Security.level config setting is medium and my Session.timeout is 120, so that shouldn't be the problem. Anyone have any idea what could be creating this?
Thanks.
is it possible that your ajax calls and redirects are not going to the same place, eg www.site.com and site.com? I have had that before and also kept getting logged out.
So this wasn't fun to track down, but it was me being an idiot. Buried in the code was some early-stage code to refresh user data in the authenticated session that wasn't doing what it should have been doing. It was attempting to update the entire Auth.User object directly (e.g. $this->Session->write( 'Auth', $user )) instead of calling the login method.
Once I changed the Session::write() code to $this->Auth->login( $user ), everything lined up nicely. A nice bit of reference material on this subject at http://milesj.me/blog/read/31/Refreshing-The-Auths-Session.

Resources