コード例 #1
0
def forget_password():
    email = request.json.get('email', None)
    if not email or email == '':
        return None
    worker = Worker()
    worker.email = email
    worker = Worker.query.filter_by(email=email).first()
    if not worker:
        return jsonify({"msg": "This email is not registered"}), 404
    token = generate_confirmation_token(worker.email)
    print(token)
    confirm_url = 'http://localhost:3000/confirmation/' + token
    html = render_template('email_confirmation.html', confirm_url=confirm_url)
    subject = "Por favor, Confirmar su email."
    sendMail("Por favor, Confirmar su email.", '', '', worker.email, html)
    return jsonify({"success": "Email send successfully"}), 200
コード例 #2
0
def register():
    email = request.json.get('email')
    name = request.json.get('name')
    password = request.json.get('password')
    if not email:
        return jsonify({"error": "Email is required"}), 422
    if not name:
        return jsonify({"error": "name is required"}), 422
    if not password:
        return jsonify({"error": "Password is required"}), 422
    worker = Worker.query.filter_by(email=email).first()
    if worker:
        return jsonify({"error": "This email already exist"}), 422
    worker = Worker()
    worker.email = email
    worker.name = name
    worker.password = bcrypt.generate_password_hash(password)
    db.session.add(worker)
    db.session.commit()
    if bcrypt.check_password_hash(worker.password, password):
        access_token = create_access_token(identity=worker.email)
        data = {"access_token": access_token, "worker": worker.serialize()}
        return jsonify(data), 200