From 3c40553b4531c5402d134ffa33f8159fe48ad0a2 Mon Sep 17 00:00:00 2001 From: warren yun Date: Tue, 22 Oct 2024 17:56:14 -0400 Subject: [PATCH] update user schema --- goathacks/models.py | 4 ++ goathacks/registration/__init__.py | 72 ++++++++++++++++-------------- 2 files changed, 42 insertions(+), 34 deletions(-) diff --git a/goathacks/models.py b/goathacks/models.py index f0cbcd2..9f48d0a 100644 --- a/goathacks/models.py +++ b/goathacks/models.py @@ -20,6 +20,10 @@ class User(db.Model, UserMixin): school = Column(String, nullable=True) phone = Column(String, nullable=True) gender = Column(String, nullable=True) + newsletter = Column(Boolean, nullable=False, default=False) + country = Column(String, nullable=False) + age = Column(Integer, nullable=False) + dietary_restrictions = Column(String, nullable=True) def __str__(self): return f"{self.first_name} {self.last_name} ({self.email})" diff --git a/goathacks/registration/__init__.py b/goathacks/registration/__init__.py index 46370eb..0585489 100644 --- a/goathacks/registration/__init__.py +++ b/goathacks/registration/__init__.py @@ -35,44 +35,48 @@ def register(): dietary_restrictions = request.form.get('dietary_restrictions') newsletter = request.form.get('newsletter') - # if password == password_c: - # # Passwords match! + if password == password_c: + # Passwords match! - # # Count of all non-waitlisted hackers - # num_not_waitlisted = len(User.query.filter_by(waitlisted=False).all()) - # waitlisted = False - # print(num_not_waitlisted) - # print(current_app.config['MAX_BEFORE_WAITLIST']) - # if num_not_waitlisted >= current_app.config['MAX_BEFORE_WAITLIST']: - # waitlisted = True - # user = User( - # email=email, - # password=generate_password_hash(password), - # first_name=first_name, - # last_name=last_name, - # last_login=datetime.now(), - # waitlisted=waitlisted, - # school=school, - # phone=phone, - # gender=gender - # ) - # db.session.add(user) - # db.session.commit() - # flask_login.login_user(user) + # Count of all non-waitlisted hackers + num_not_waitlisted = len(User.query.filter_by(waitlisted=False).all()) + waitlisted = False + print(num_not_waitlisted) + print(current_app.config['MAX_BEFORE_WAITLIST']) + if num_not_waitlisted >= current_app.config['MAX_BEFORE_WAITLIST']: + waitlisted = True + user = User( + email=email, + password=generate_password_hash(password), + first_name=first_name, + last_name=last_name, + last_login=datetime.now(), + waitlisted=waitlisted, + school=school, + phone=phone, + gender=gender, + country=country, + age=age, + dietary_restrictions=dietary_restrictions, + newsletter=newsletter + ) + db.session.add(user) + db.session.commit() + flask_login.login_user(user) - # if waitlisted: - # msg = Message("Goathacks - Waitlist Confirmation") - # else: - # msg = Message("GoatHacks - Registration Confirmation") + if waitlisted: + msg = Message("Goathacks - Waitlist Confirmation") + else: + msg = Message("GoatHacks - Registration Confirmation") - # msg.add_recipient(user.email) - # msg.sender = ("GoatHacks Team", "hack@wpi.edu") - # msg.body = render_template("emails/registration.txt", user=user) - # app_mail.send(msg) + msg.add_recipient(user.email) + msg.sender = ("GoatHacks Team", "hack@wpi.edu") + msg.body = render_template("emails/registration.txt", user=user) + app_mail.send(msg) - # return redirect(url_for("dashboard.home")) - # else: - # flash("Passwords do not match") + return redirect(url_for("dashboard.home")) + else: + flash("Passwords do not match") return render_template("register.html", form=form)