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

33
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,20 +210,22 @@ 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:
invite_code = str(uuid4()) old_qr = mongo.db.users.find_one({'_id': ObjectId(current_user.id)})
qr_update = mongo.db.users.update_one({'_id': ObjectId(current_user.id)}, {'$set': {'referral_code': invite_code}}) print(old_qr)
print(qr_update) invite_code = str(uuid4())
if not current_user.is_admin: qr_update = mongo.db.users.update_one({'_id': ObjectId(current_user.id)}, {'$set': {'referral_code': invite_code}})
pins = list(mongo.db.pins.find({"added_by": current_user.id})) print(invite_code)
return render_template('dashboard.html', pins=pins, invite_code=invite_code) if not current_user.is_admin:
if current_user.is_admin: pins = list(mongo.db.pins.find({"added_by": current_user.id}))
users = list(mongo.db.users.find()) return render_template('dashboard.html', pins=pins, invite_code=invite_code)
pins = list(mongo.db.pins.find()) if current_user.is_admin:
return render_template('dashboard.html', users=users, pins=pins, invite_code=invite_code) users = list(mongo.db.users.find())
pins = list(mongo.db.pins.find())
return render_template('dashboard.html', users=users, pins=pins, invite_code=invite_code)
@app.cli.command('add_user') @app.cli.command('add_user')
def add_user(): def add_user():

View File

@ -2,4 +2,5 @@ class Config:
MONGO_URI = 'mongodb://localhost:27017/mapDB' MONGO_URI = 'mongodb://localhost:27017/mapDB'
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 %}