Jump to content

Recommended Posts

Posted

i made a control for loggedin users and redirect them in different pages for admins and registered users.

if($user->isLoggedin()) {
    if ($user->isSuperuser()){
    	$session->redirect("/processwire/"); 
    }else{
    	$session->redirect("/members/" .$user); 
    }
}

everytime redirect goes to /members/user/ but if i refresh the redirect for superuser works, it seems the first time i login i cannot see the isSuperuser status... ???

Posted

Since you are doing redirects, make sure that these are done before you output anything. Redirects use http headers, which have to come before any markup.

Another thing to check is that there is no template caching being used. Check that in Admin > Templates > your template > Advanced, that the cache time is not set (or is 0).

If neither of these are it, please post everything that comes before this snippet you pasted in your template (or just the whole template).

Posted

the cache time is already set to 0.

this is my template

<?
if($user->isLoggedin()==true) {
    if ($user->isSuperuser()==true){
    	$session->redirect("/processwire/"); 
    }else{
    	$session->redirect("/members/" .$user); 
    }
}
require_once('./func.inc');
// check for login before outputting markup
if($input->post->user && $input->post->pass) {

    	$user = $sanitizer->username($input->post->user);
    	$pass = $input->post->pass; 

    	if($session->login($user, $pass)) {
        	// login successful
        	$session->redirect("/members/". $user); 
    	}
}
?>
<!DOCTYPE html>
<html lang="en">
<? require_once('./head.inc'); ?>
<body>
<div id="container">
	<? include('./top.inc'); ?>
	<div class="clearfix"></div>
	<div id="login">
		<h1>Login</h1>
		<div id="block">
			<form action='./' method='post'>
        			<?php if($input->post->user) echo "<h2 class='error'>Login failed</h2>"; ?>
        			<label>User</label><input type='text' name='user' class="uname" /><br />
       		 		<label>Password</label><input type='password' name='pass' class="uname" /><br />
        			<input type='submit' name='submit' value='Login' class="loginbutton" /><br />
    			</form>	
    		</div>
    		<div id="block">
    			<?=$page->body?>
    		</div>
    		<div class="clearfix"></div>
	</div>
	<div class="clearfix"></div>
</div>
<? include('./footer.inc'); ?>
</body>
</html>
Posted

It looks to me like this problem is here:

    	if($session->login($user, $pass)) {
        	// login successful
        	$session->redirect("/members/". $user); 
    	}

That's where you should put your isSuperuser() check.

    	
        if($session->login($user, $pass)) {
        	// login successful
                if($user->isSuperuser()) $session->redirect("/processwire/"); 
        	    else $session->redirect("/members/". $user); 
    	}

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...