コード例 #1
0
        session['user'] = user['username']
        response.set_cookie('AuthToken', user['username'])
        return response

def register_user(form_data):
    
    password = form_data.get('password').encode('utf-8')
    salt = bcrypt.gensalt()
    hashed = bcrypt.hashpw(password, salt)

    try:
        user = User(
            username = form_data.get('username'),
            password = hashed,
            email = form_data.get('email')
            )

        db.session.add(user)
        db.session.commit()
        return redirect(url_for('login'))

    except Exception as e:
        db.session.rollback()
        return make_response(jsonify({'message': str(e)}), 500)

if syncDB == True:
    db.create_all()

if resetDB == True:
    db.delete_all()
    db.create_all()
コード例 #2
0
def reset_database():
    db.delete_all()
    db.create_all()