Ejemplo n.º 1
0
def signup():
    """ End Point for signups
        *Requires some sort of database
    """
    if request.method == 'GET':
        return render_template('signup.html')

    if request.method == 'POST':
        if request.form['userpass'] != request.form['userpass2']:
            error = 'Passwords do not match'
            return render_template('signup.html', error=error)

        salt = getRandomSalt(16)
        thehash = pbkdf2_hex(request.form['userpass'].encode('utf-8'),
                             salt.encode('utf-8'))

        # Make a new user out of the info
        new_user = {
            'name': request.form['username'],
            'salt': unicode(salt),
            'hash': unicode(thehash)
        }

        # You'll need a database to save it to
        # user_id = db.users.save(new_user)
        # store user id in the session
        session['user'] = new_user['name']

        return redirect('/home')
Ejemplo n.º 2
0
def signup():
    """ End Point for signups
        *Requires some sort of database
    """
    if request.method == 'GET':
        return render_template('signup.html')

    if request.method == 'POST':
        if request.form['userpass'] != request.form['userpass2']:
            error = 'Passwords do not match'
            return render_template('signup.html', error=error)

        salt = getRandomSalt(16)
        thehash = pbkdf2_hex(request.form['userpass'].encode('utf-8'),
                             salt.encode('utf-8'))

        # Make a new user out of the info
        new_user = {
            'name': request.form['username'],
            'salt': unicode(salt),
            'hash': unicode(thehash)
        }

        # You'll need a database to save it to
        # user_id = db.users.save(new_user)
        # store user id in the session
        session['user'] = new_user['name']

        return redirect('/home')
Ejemplo n.º 3
0
def creatuser():
    """
    GET: Render the create account form
    POST: Create the user
    """
    if request.method == 'GET':
        return render('index.html')

    
    elif request.method == 'POST':
        salt =  getRandomSalt(16)
        thehash = pbkdf2_hex(request.form['password'].encode('utf-8'), salt.encode('utf-8'))

        # Make a new user out of the info
        new_user = store.add(User())
        new_user.username = request.form['username']
        new_user.salt = unicode(salt)
        new_user.hash = unicode(thehash)
        store.commit()

        # store user id in the session
        session['userid'] = new_user.id

        return redirect('/home')