Jump to content

Recommended Posts

Posted

Dear all,

A beginner here. When I went to this link:http://processwire.com/api/user-access/ to find out how to make login/ logout pages, nothing showed up. Any tutorial regarding this topic for guidance? I'd like to have two different groups of users and each goes to certain different pages after login. When they are logged out, both can see some general pages. Probably there is a very basic answer but I am not an advanced web programmer. Help me out, please  :undecided:  Thanks 

Posted

Hi circlet, welcome to ProcessWire!

How is your current setup for the users? I Assume you created two different roles to distinguish them and assigned one of them to your users.

You can log-in a user with the API: http://processwire.com/api/variables/session/

Short example:

/* After the form with username/password was sent... */

// Log in the user
$username = $sanitizer->pageName($input->post->username); //Sanitize username
$u = $session->login($username, $input->post->password);

// Check if a user was returned or null
if (!is_null($u)) {
  // Redirect based on role
  if ($u->hasRole('role-A')) {
    $session->redirect($pages->get('/path/to/page/for/role-a/')->url);
  }
} else {
  // Wrong username or password
}
  • Like 2
Posted

You're welcome!

Yes exactly. It's the same as getting the values from  php's $_POST array, but it's a nice "Pw-way" of doing it :)

Plus you get the advantage that if a variable is not set, $input returns null whereas accessing a variable that does not exist in the $_POST array returns a Notice "undefined index".

  • Like 1
Posted

Thank you, Wanze!

I think I got it in a way. I was afraid no one would reply such a noob question. But you guys are so responsive, you rock :lol: Sometimes, even a tiny little thing would not make a sense and you have to ask someone else who knows. Such a welcoming community. I'll explore PW more and will make this website. Thanks again.

  • Like 3
  • 3 months later...

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
×
×
  • Create New...