Jump to content

how to login/ logout ?!


Recommended Posts

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 

Link to comment
Share on other sites

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')) {
} else {
  // Wrong username or password
  • Like 2
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

Yes, PW Community and especially Ryan helping with tipps and code examples :)

Ryans login example, a modified version from renobird. Another version from Ryan with login, reset password and profile.

Haven't used the examples yet, but maybe in the near future.

But why nobody write a login module to have a shared base for all? Should be great for new users to get started ;)

Link to comment
Share on other sites

  • 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...