Setting Up StorGUI Explanation - shmolyneaux/SquareJam GitHub Wiki

This tutorial covers a variety of topics including the following:

Store the user's name in the user variable:

  user = self.__connection__.__username__;

Check if the user is already logged in as the root user, or is about to log in: log in if the user isn't already the root user:

  if user == 'root' or ( 'username' in req.form and 'password' in req.form ):
    if user != 'root':
      req.storage.login( req.form['username'], req.form['password'] );

Link the storgui attribute of the parent object to the location of storgui in Library.storgui:

    self.__container__.storgui = req.storage.Library.storgui;

The rest of the code is covered is Getting Started Explanation, or is based on prerequisite HTML knowledge.

The entire script is as follows:

def html( self, req ):
  user = self.__connection__.__username__;
  if user == 'root' or ( 'username' in req.form and 'password' in req.form ):
    if user != 'root':
      req.storage.login( req.form['username'], req.form['password'] );
    self.__container__.storgui = req.storage.Library.storgui;
    req.content_type = 'text/plain';
    req.content = "Success!";

  else:
    req.content_type = 'text/html';
    req.content = """
<html>
  <head>
    <title>Login</title>
  </head>
  <body>
    <form method='POST' action'/'>
      Username: <input type='text' name='username' /> <br />
      Password: <input type='password' name='password' /> <br />
      <input type='submit' value='Login' />
    </form>
  </body>
</html>""";
⚠️ **GitHub.com Fallback** ⚠️