Jump to content

which example to use for frontend login


Recommended Posts

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

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

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
if($user->isLoggedin()) {
    // user is already logged in, so they don't need to be here

// 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

<?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>
<?php include("./myinclude/foot.inc");?>

Then is kept the following for profile page:

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


echo "hello ". $user->name;
    $selects = $pages->find("template=child-template,  limit=2"); // can I select here by user ID???


On the include file I have this code to test the logged in user ID and name - which is working:

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

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

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