1

I am playing with deployd and am having trouble figuring out how to take the session info from one page to another. In the login demo on the deployd site they have some code to redirect a logged in user to a new page and welcome them. However if I visit that page normally in the url it is still visible if I dont use the login form. I assume this is just a very basic demo, but I would like to know how to deny a user if they haven't logged in and just try and visit the page.

Even some tips in the right direction will give me a lot of help, Thanks!

Here is my index page code

<body>
     <section id="test"></div>

           <form id="drop" >
             User Name:<input id="user" type="text" name="username"><br>
            Password<input id="pass" type="password" name="password"><br>

           <input type="submit" value="login">
             </form>
    </body>

    <script>
    $(document).ready(function() {
    dpd.things.get(function(result, error) {


    $.each(result, function(i,result){
      content = '<div class="'+result.name+'">' + '<p >' + result.name + '</p>' + '<p   id="'+result.about+'">' + result.about + '</p>'  + '</div>' ;
     // about = '<p>' + result.about + '</p>';
     $(content).appendTo("#test");
     // $(about).appendTo("#about");
     $('#test').attr('class', result.name);
     $("#"+result.name).click(function() {
     console.log(result);
     dpd.things.del(result.id, function(well, error) {
     $("."+result.name).remove();
    }); }); }); }); });

     $( "#drop" ).on( "submit", function( event ) {
      event.preventDefault();
      var hello = $("#user").val();
      var goodbye = $("#pass").val();

      dpd.users.login({"username": hello, "password": goodbye}, function(user, err) {
      if(err) return console.log(err);
      console.log(user);
      location.href = "users.html";
    }); });
</script>

and here is my users.html page js

    <div class="container">
        <h1></h1>
        <button class="btn" id="logout-btn">Logout</button>
      </div>
      <script type="text/javascript" src="/js/lib/jquery.js"></script>
      <script type="text/javascript" src="/dpd.js"></script>
      <script type="text/javascript">
        dpd.users.me(function(user) {
          if (user) {
            $('h1').text("Welcome, " + user.username + "!");
          } else {
            location.href = "/";
          }
        });
</script>
Anders Kitson
  • 1,413
  • 6
  • 38
  • 98
  • please format code to remove big gaps of empty lines and clean indentation. There's no reason to expect people to have to scroll for the amount of code you have – charlietfl Dec 27 '13 at 02:49
  • @charlietfl sorry I was being hasty I am usually very careful about this. You have any ideas about my question. I am starting to think using deployd is pointless for me (at least my knowledge) since there doesn't seem to be a very big community around it. – Anders Kitson Dec 27 '13 at 04:11

0 Answers0