bwakad Posted May 3, 2014 Share Posted May 3, 2014 There are many topics about accomplish this, but none of them have a 'best answer' - leaving me with the questions: - is it working as aspected? - do I have to concern about security issues? - Is it a work in progress? - which ones are good examples? I also see a module, but once again, in some topics were concerns about the code written in modules as they should be in the preferred format. This leave me with a feeling not to use it. Link to comment Share on other sites More sharing options...
adrian Posted May 3, 2014 Share Posted May 3, 2014 This is what I have based my front-end logins off and all work great: https://processwire.com/talk/topic/1716-integrating-a-member-visitor-login-form/?p=15919 2 Link to comment Share on other sites More sharing options...
bwakad Posted May 3, 2014 Author Share Posted May 3, 2014 thanks, I have seen this topic. However, one respons in this topic is linking to another topic, one part is from ryan's code, while others talk about a module. Which should I use? Sorry, you linked to the specific post from ryan... thanks! Link to comment Share on other sites More sharing options...
bwakad Posted May 6, 2014 Author Share Posted May 6, 2014 well, I copied all code, followed instructions, but the login simply fails. Can't even login as admin from the front. The only thing working is the logout. Link to comment Share on other sites More sharing options...
adrian Posted May 6, 2014 Share Posted May 6, 2014 We're going to need more than that to help you Any errors with debug mode on? Post your final code so we can a look. Link to comment Share on other sites More sharing options...
Martijn Geerts Posted May 6, 2014 Share Posted May 6, 2014 Does: $session->login('admin', 'tralalala'); Work? (remove the tralala party with your password ) Link to comment Share on other sites More sharing options...
bwakad Posted May 6, 2014 Author Share Posted May 6, 2014 Hi all, I have used the code as in Ryan's example but only needed the login. But since it did not work I tried this code for the login which does work. However, taking into account that Ryan is the expert, I really want to know if this code is save to use: // login.php <?php if($user->isLoggedin()) { // user is already logged in, so they don't need to be here $session->redirect("/profile/"); } // 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("/profile/"); } } ?> <?php include("./myinclude/head.inc");?> <form action='./' method='post'> <?php if($input->post->user) echo "<h2 class='error'>Login failed</h2>"; ?> <p><label>User <input type='text' name='user' /></label></p> <p><label>Password <input type='password' name='pass' /></label></p> <p><input type='submit' name='submit' value='Login' /></p> </form> <?php include("./myinclude/foot.inc");?> Then is kept the following for profile page: //profile.php <?php // if user isn't logged in, then we pretend this page doesn't exist if(!$user->isLoggedin()) throw new Wire404Exception(); // need to redirect here if not logged in .............. include("./myinclude/head.inc"); echo "hello ". $user->name; $selects = $pages->find("template=child-template, limit=2"); // can I select here by user ID??? include("./myinclude/browse.inc"); include("./myinclude/foot.inc");?> On the include file I have this code to test the logged in user ID and name - which is working: //browse.inc <?php foreach ($selects as $child) { ?> <?php if($user->isLoggedin()) { if($child->created_users_id === $user->id) echo $child->created_users_id . " " . $user->name; } ?> And what I know need is to display only items OF the logged in user on this profile page - and a way to edit this items on front-end.... Link to comment Share on other sites More sharing options...
Martijn Geerts Posted May 6, 2014 Share Posted May 6, 2014 What do you want to do here : $selects = $pages->find("template=child-template, limit=2"); // can I select here by user ID??? Link to comment Share on other sites More sharing options...
bwakad Posted May 6, 2014 Author Share Posted May 6, 2014 What do you want to do here : $selects = $pages->find("template=child-template, limit=2"); // can I select here by user ID??? Already found the answer and it seems to work fine - but there are times I never know exactly if this code is good since I only found created_users_id inside the database, and not on the api or cheatsheet...: $selects = $pages->find("template=child-template, created_users_id={$user}, limit=2"); // select only from current logged in user This way, in combination with my login.php I am able to only display items belonging to the current logged in user on the profile page. 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