def register(): email = request.json.get('email') fullname = request.json.get('fullname') password = request.json.get('password') if not email: return jsonify({"msg": "You need to write yor email"}), 422 if not fullname: return jsonify({"msg": "You need to write your name"}), 422 if not password: return jsonify({"msg": "You need to write your password"}), 422 consumer = Consumer.query.filter_by(email=email).first() if consumer: return jsonify({"msg": "This email already exist"}), 422 consumer = Consumer() consumer.email = email consumer.fullname = fullname consumer.password = bcrypt.generate_password_hash(password) db.session.add(consumer) db.session.commit() if bcrypt.check_password_hash(consumer.password, password): access_token = create_access_token(identity=consumer.email) data = {"access_token": access_token, "consumer": consumer.serialize()} return jsonify(data), 200 else: return jsonify({"msg": "Email or password is incorrect"}), 401
def change_password(): email = request.json.get('email', None) if not email or email == '': return None consumer = Consumer() consumer.email = email consumer = Consumer.query.filter_by(email=email).first() if not consumer: return jsonify({"msg": "This email is not registered"}), 404 token = generate_confirmation_token(consumer.email) 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.", consumer.email, html) return jsonify({"success": "Email send successfully"}), 200