Exemple #1
0
def sign_up():
    data = request.get_json()
    name = data['name']
    dob = data['dob']
    email = data['email']
    password = data['password']
    user = Users.query.filter_by(email=email).first()
    if user:
        return jsonify({"message": "User already registered"})
    else:
        hashed_password = bcrypt.generate_password_hash(password).decode(
            'utf-8')
        users = Users()
        users.name = name
        users.dob = dob
        users.email = email
        users.password = hashed_password
        try:
            db.session.add(users)
            db.session.commit()
        except:
            return jsonify({
                "status": "error",
                "message": "Could not add user"
            }), 401

        return jsonify({
            "status": "success",
            "message": "User added successfully"
        }), 201
Exemple #2
0
def reg():
    form = Sign_Up()
    if form.validate_on_submit():
        users = Users()
        users.name = form.name.data
        users.password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        users.dob = form.dob.data
        user = Users.query.filter_by(email=form.email.data).first()
        if user:
            return jsonify({"message": "User already registered"})
        users.email = form.email.data
        db.session.add(users)
        db.session.commit()
        return redirect(url_for('raw.login_users'))
    return render_template('sign_up.html', form=form)