示例#1
0
文件: views.py 项目: Best1a/Di
def signup():
    def check_email(email):
        cur = g.db.execute('select 1 from user where email=?', [email])
        row = cur.fetchone()
        return True if row else False

    error = None
    if request.method == 'POST':
        username = request.form['username']
        email = request.form['email']
        raw_password = request.form['password']
        raw_password2 = request.form['password2']

        if get_user_id(username):
            error = 'username exists!'
        elif check_email(email):
            error = 'email exists!'
        elif raw_password != raw_password2:
            error = '2 password dont match'
        else:
            salt = gen_salt()
            salted_pwd = salt + '.' + hash_password(username, raw_password,
                                                    salt)
            g.db.execute('''insert into user(username, salted_pwd, email)
                            values(?,?,?)''', [username, salted_pwd, email])
            g.db.commit()
            return redirect(url_for('signin'))
    return render_template('signup.html', error=error)
示例#2
0
文件: views.py 项目: Best1a/Di
def modify_password():
    raw_password = request.form['password']
    raw_password2 = request.form['password2']

    if raw_password != raw_password2:
        flash('2 password dont match.')
    else:
        salt = gen_salt()
        salted_pwd = salt + '.' + hash_password(session['username'],
                                                raw_password, salt)
        g.db.execute('update user set salted_pwd=? where user_id=?',
                     [salted_pwd, g.user['user_id']])
        g.db.commit()
        flash('Password update successful.')
    return redirect(url_for('user_setting'))