Ejemplo n.º 1
0
def confirm(theform, userdir, thisscript):
    """Confirm a login.
    Either from an invite or from a user who has registered."""
    from dataenc import pass_dec, pass_enc
    from login import encodestring
    fail = False
    try:
        theval, daynumber, timestamp = pass_dec(theform['id'].value)
    except:
        # FIXME: bare except....
        newloginfail()
    tempstore = ConfigObj(userdir + 'temp.ini')
    if not tempstore.has_key(theval):
        newloginfail()
    uservals = tempstore[theval]
    del tempstore[theval]
    username = uservals['username']
    if username in tempstore['pending']:
        tempstore['pending'].remove(username)
    tempstore.write()
    #
    newconfig = ConfigObj(userdir + 'default.ini')
    newpath = userdir + username + '.ini'
    if os.path.isfile(newpath):
        newloginfail()
    newconfig.filename = newpath
    # FIXME: should this be '' ?
    action = None
    for entry in uservals:
        if entry == 'action':
            action = uservals[entry]
        elif entry == 'password':
            password = uservals[entry]
            newconfig[entry] = pass_enc(password, timestamp=True, daynumber=True)
        else:
            newconfig[entry] = uservals[entry]
    newconfig.write()
    #
    # next we need to create the cookie header to return it 
    from Cookie import SimpleCookie
    thecookie = SimpleCookie()
    thecookie['userid'] = encodestring(newconfig['username'], password)
    config = ConfigObj(userdir + 'config.ini')
    maxage = newconfig['max-age'] 
    cookiepath = config['cookiepath']
    if maxage and int(maxage):            # possible cause of error here if the maxage value in a users file isn't an integer !!
        thecookie['userid']['max-age'] = int(maxage) 
    if cookiepath:
        thecookie['userid']['path'] = cookiepath 
    if config['adminmail']:
        msg = 'A new user has created a login - "%s".\n\n' % thisscript
        for entry in newconfig:
            if entry != 'password':
                msg += entry + '   :   ' + newconfig[entry] + '\n'
        # FIXME: should be mailme
        sendmailme(config['adminmail'], msg, config['email_subject'],
                config['adminmail'], html=False)
    return action, newconfig, thecookie.output()
Ejemplo n.º 2
0
def makecookie(userconfig, password, cookiepath):
    """
    Return the current valid cookie heaader for the values supplied in the
    userconfig, the straight password and the cookiepath.
    """
    from login import encodestring
    from Cookie import SimpleCookie
    thecookie = SimpleCookie()
    cookiestring = encodestring(userconfig['username'],password)
    maxage = userconfig['max-age']
    thecookie['userid'] = cookiestring
    if maxage and int(maxage):            # possible cause of error here if the maxage value in a users file isn't an integer !!
        thecookie['userid']['max-age'] = int(maxage) 
    if cookiepath:
        thecookie['userid']['path'] = cookiepath
    return thecookie.output()                         # XXXX may need to be able to return the cookie object
Ejemplo n.º 3
0
def makecookie(userconfig, password, cookiepath):
    """
    Return the current valid cookie heaader for the values supplied in the
    userconfig, the straight password and the cookiepath.
    """
    from login import encodestring
    from Cookie import SimpleCookie
    thecookie = SimpleCookie()
    cookiestring = encodestring(userconfig['username'],password)
    maxage = userconfig['max-age']
    thecookie['userid'] = cookiestring
    if maxage and int(maxage):            # possible cause of error here if the maxage value in a users file isn't an integer !!
        thecookie['userid']['max-age'] = int(maxage) 
    if cookiepath:
        thecookie['userid']['path'] = cookiepath
    return thecookie.output()                         # XXXX may need to be able to return the cookie object
Ejemplo n.º 4
0
def confirm(theform, userdir, thisscript):
    """Confirm a login.
    Either from an invite or from a user who has registered."""
    from modules.dataenc import pass_dec, pass_enc
    from login import encodestring
    fail = False
    try:
        theval, daynumber, timestamp = pass_dec(theform['id'].value)
    except:
        # FIXME: bare except....
        newloginfail()
    tempstore = ConfigObj(userdir + 'temp.ini')
    if not tempstore.has_key(theval):
        newloginfail()
    uservals = tempstore[theval]
    del tempstore[theval]
    username = uservals['username']
    if username in tempstore['pending']:
        tempstore['pending'].remove(username)
    tempstore.write()
    #
    newconfig = ConfigObj(userdir + 'default.ini')
    newpath = userdir + username + '.ini'
    if os.path.isfile(newpath):
        newloginfail()
    newconfig.filename = newpath
    # FIXME: should this be '' ?
    action = None
    for entry in uservals:
        if entry == 'action':
            action = uservals[entry]
        elif entry == 'password':
            password = uservals[entry]
            pwd_hash = pwd_context.hash(password, salt="")
            newconfig[entry] = pass_enc(pwd_hash,
                                        timestamp=True,
                                        daynumber=True)
        else:
            newconfig[entry] = uservals[entry]
    newconfig.write()
    #
    # next we need to create the cookie header to return it
    from Cookie import SimpleCookie
    thecookie = SimpleCookie()
    pwd_hash = pwd_context.hash(password, salt="")
    thecookie['userid'] = encodestring(newconfig['username'], pwd_hash)
    config = ConfigObj(userdir + 'config.ini')
    maxage = newconfig['max-age']
    cookiepath = config['cookiepath']
    if maxage and int(
            maxage
    ):  # possible cause of error here if the maxage value in a users file isn't an integer !!
        thecookie['userid']['max-age'] = int(maxage)
    if cookiepath:
        thecookie['userid']['path'] = cookiepath
    if config['adminmail']:
        msg = 'A new user has created a login - "%s".\n\n' % thisscript
        for entry in newconfig:
            if entry != 'password':
                msg += entry + '   :   ' + newconfig[entry] + '\n'
        # FIXME: should be mailme
        sendmailme(config['adminmail'],
                   msg,
                   config['email_subject'],
                   config['adminmail'],
                   html=False)
    return action, newconfig, thecookie.output()