circlet Posted December 1, 2013 Share Posted December 1, 2013 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 Thanks Link to comment Share on other sites More sharing options...
Wanze Posted December 1, 2013 Share Posted December 1, 2013 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 } 2 Link to comment Share on other sites More sharing options...
circlet Posted December 1, 2013 Author Share Posted December 1, 2013 Thank you for your reply, Wanze! So, the "username" and "password" are textfield names, right? Sorry, if it sounds too noob Link to comment Share on other sites More sharing options...
Wanze Posted December 1, 2013 Share Posted December 1, 2013 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". 1 Link to comment Share on other sites More sharing options...
circlet Posted December 2, 2013 Author Share Posted December 2, 2013 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 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. 3 Link to comment Share on other sites More sharing options...
pwFoo Posted December 3, 2013 Share Posted December 3, 2013 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 More sharing options...
Soma Posted March 31, 2014 Share Posted March 31, 2014 Just in case. This login code in here with custom login code, will break if login throttle is enabled and kicks in: See here for how to handle this: https://processwire.com/talk/topic/107-custom-login/?p=58627 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now