1
0
forked from orson/bachemap

invite code fixed (but WHY)

This commit is contained in:
Orson 2024-09-12 16:56:41 -06:00
parent 849b5cbafc
commit ffcbaff534
3 changed files with 22 additions and 18 deletions

15
app.py
View File

@ -13,14 +13,15 @@ from wtforms.validators import DataRequired, Length
import requests import requests
from config import Config from config import Config
from geopy.geocoders import Nominatim from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent="Bachemapa @ baches.qro.mx") geolocator = Nominatim(user_agent="Bachemapa @ baches.qro.mx")
def create_app(config=Config): def create_app(config=Config):
app = Flask(__name__) app = Flask(__name__)
app.config.from_object(config) app.config.from_object(config)
mongo = PyMongo(app) mongo = PyMongo(app)
login_manager = LoginManager(app) login_manager = LoginManager(app)
login_manager.login_view = 'thelogin'
login_manager.session_protection = "strong" login_manager.session_protection = "strong"
class User(UserMixin): class User(UserMixin):
@ -209,13 +210,15 @@ def create_app(config=Config):
@app.route('/dashboard') @app.route('/dashboard')
@login_required @login_required
def dashboard(): def dashboard():
if request.method == 'GET': #if request.method == 'GET':
if current_user.is_authenticated == False: #if current_user.is_authenticated == False:
return redirect(url_for('thelogin')) # return redirect(url_for('thelogin'))
else: #else:
old_qr = mongo.db.users.find_one({'_id': ObjectId(current_user.id)})
print(old_qr)
invite_code = str(uuid4()) invite_code = str(uuid4())
qr_update = mongo.db.users.update_one({'_id': ObjectId(current_user.id)}, {'$set': {'referral_code': invite_code}}) qr_update = mongo.db.users.update_one({'_id': ObjectId(current_user.id)}, {'$set': {'referral_code': invite_code}})
print(qr_update) print(invite_code)
if not current_user.is_admin: if not current_user.is_admin:
pins = list(mongo.db.pins.find({"added_by": current_user.id})) pins = list(mongo.db.pins.find({"added_by": current_user.id}))
return render_template('dashboard.html', pins=pins, invite_code=invite_code) return render_template('dashboard.html', pins=pins, invite_code=invite_code)

View File

@ -3,3 +3,4 @@ class Config:
UPLOAD_FOLDER = 'uploads' UPLOAD_FOLDER = 'uploads'
SECRET_KEY = 'supersecretkey' SECRET_KEY = 'supersecretkey'
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'} ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
LOGIN_URL = '/thelogin'

View File

@ -15,7 +15,7 @@
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
var qrcode = new QRCode(document.getElementById("qrgen"), { var qrcode = new QRCode(document.getElementById("qrgen"), {
text: "https://baches.qro.mx/registrame/{{current_user.referral_code}}", text: "https://baches.qro.mx/registrame/{{invite_code}}",
width: 256, width: 256,
height: 256, height: 256,
colorDark : "#000000", colorDark : "#000000",
@ -25,7 +25,7 @@
</script> </script>
<div> <div>
<h2>Tu link es:</h2> <h2>Tu link es:</h2>
<p><a href="https://baches.qro.mx/registrame/{{current_user.referral_code}}">https://baches.qro.mx/registrame/{{current_user.referral_code}}</a></p> <p><a href="https://baches.qro.mx/registrame/{{invite_code}}">https://baches.qro.mx/registrame/{{invite_code}}</a></p>
</div> </div>
</div> </div>
{% if pins %} {% if pins %}