durusmail: qp: Adding new accounts to 'users'
Adding new accounts to 'users'
2006-09-19
2006-09-19
2006-09-20
2006-09-20
2006-09-21
2006-09-21
2006-09-23
2006-09-23
2006-09-24
2006-09-25
2006-09-25
2006-09-25
Re: Adding new accounts to 'users'
2006-09-25
Adding new accounts to 'users'
John Tidmarsh
2006-09-20
On 9/19/06, David Binger  wrote:
>
> If this code is part of your user registration form, you
> don't need to call commit() yourself.  The publisher
> will do that before sending the response, if there
> is something to commit, and there are no exceptions.
>
> I'm not sure what your user_db is.
> Is it an instance of some persistent class?
> How does it actually hold the User instances that are added?
> Has the user_db already been committed to the database?
>
> Are you familiar with the "-i" and "-l" commands of the "qp"
> command?  We find them very helpful.
> Can you start "qp -i" and find your user_db instance
> waiting for you?


I was actually using the built-in users - dropped the confusing users_db.
Still, the new user doesn't persist if I restart the site. The source:
--------------------------------------------------------------------------------
-------------------------------------------------------------
from qp.pub.publish import DurusPublisher
from qp.pub.common import header, footer, redirect
from qp.fill.directory import Directory
from qp.fill.form import Form
from qp.pub.common import get_publisher
from qp.fill.widget import StringWidget, PasswordWidget, SubmitWidget
from qp.pub.user import User

class SitePublisher (DurusPublisher):

    configuration = dict(
        http_address=('', 8004),
        as_https_address=('localhost', 9004),
        https_address=('localhost', 10004),
        scgi_address=('localhost', 11004),
        )

class SiteDirectory (Directory):
    """
    This site displays the http request.
    """
    def get_exports(self):
        yield '', 'index', None, None
        yield 'test1', 'test1', None, None
        yield 'create_new_user', 'create_new_user', None, None

    def index [html] (self):
        header('Test Login Page')
        form = Form(use_tokens=False)
        form.add(StringWidget, "name", title="Your Name",
                 size=20, required=True)
        form.add(PasswordWidget, "password", title="Password",
                 size=20, maxlength=20, required=True)
        form.add_submit('go', "Go")
        form.add_submit('newuser', "Create New User")
        form.render()
        footer()
        if form.get('go'):
            login_name = form.get('name')
            passwd = form.get('password')
            users = get_publisher().get_users()
            if users[login_name] is not None:
                if users[login_name].has_password(passwd):
                    return """
                        
                        """
            redirect('..')
        elif form.get('newuser'):
            redirect('create_new_user')

    def test1 [html] (self):
        return """
                  
                   Test1 Page
                  
                  """

    def create_new_user [html] (self):
        header('Create Account')
        form2 = Form(use_tokens=False)
        form2.add(StringWidget, "newusername", title="Login", size=20,
                 maxlength=20, required=True)
        form2.add(PasswordWidget, "newuserpassword", title="Password",
                 size=20, maxlength=20, required=True)
        form2.add(PasswordWidget, "confirmpassword", title="Confirm
Password",
                 size=20, maxlength=20, required=True)
        form2.add_submit('createuser', "Create User")
        form2.render()
        if form2.get('createuser'):
            login_name = form2.get('newusername')
            passwd = form2.get('newuserpassword')
            confirm_passwd = form2.get('confirmpassword')
            if passwd !=  confirm_passwd:
                return """
                         
                       """
                redirect('../')
            else:
                new_user = User(login_name)
                new_user.set_password(passwd)
                users = get_publisher().get_users()
                users[login_name] = new_user
--------------------------------------------------------------------------------
--------
Regards
John
reply