diff --git a/application.py b/application.py index 5d6d255a..6aebd524 100644 --- a/application.py +++ b/application.py @@ -93,8 +93,8 @@ def register(): register() function displays the Registration portal (register.html) template route "/register" will redirect to register() function. RegistrationForm() called and if the form is submitted then various values are fetched and updated into database - Input: Username, Email, Password, Confirm Password - Output: Value update in database and redirected to home login page + Input: Username, Email, Password, Confirm Password, cuurent height, current weight, target weight, target date + Output: Value update in database and redirected to dashboard """ if not session.get('email'): form = RegistrationForm() @@ -103,14 +103,60 @@ def register(): username = request.form.get('username') email = request.form.get('email') password = request.form.get('password') + weight = request.form.get('weight') + height = request.form.get('height') + target_weight = request.form.get('target_weight') + target_date = request.form.get('target_date') + now = datetime.now() + now = now.strftime('%Y-%m-%d') mongo.db.user.insert_one({'name': username, 'email': email, 'pwd': bcrypt.hashpw( - password.encode("utf-8"), bcrypt.gensalt())}) + password.encode("utf-8"), bcrypt.gensalt()), 'weight': weight, 'height': height, 'target_weight': target_weight,'start_date' : now, 'target_date':target_date}) flash(f'Account created for {form.username.data}!', 'success') - return redirect(url_for('home')) + session['email'] = email + return redirect(url_for('dashboard')) else: return redirect(url_for('home')) return render_template('register.html', title='Register', form=form) +@app.route("/user_profile", methods=['GET', 'POST']) +def user_profile(): + """ + user_profile() function displays the UserProfileForm (user_profile.html) template + route "/user_profile" will redirect to user_profile() function. + user_profile() called and if the form is submitted then various values are fetched and updated into the database entries + Input: Email, height, weight, goal, Target weight + Output: Value update in database and redirected to home login page + """ + if session.get('email'): + form = UserProfileForm() + if form.validate_on_submit(): + if request.method == 'POST': + email = session.get('email') + weight = request.form.get('weight') + height = request.form.get('height') + goal = request.form.get('goal') + target_weight = request.form.get('target_weight') + temp = mongo.db.profile.find_one({'email': email}, { + 'height', 'weight', 'goal', 'target_weight'}) + if temp is not None: + mongo.db.profile.update_one({'email': email}, + {'$set': {'weight': temp['weight'], + 'height': temp['height'], + 'goal': temp['goal'], + 'target_weight': temp['target_weight']}}) + else: + mongo.db.profile.insert_one({'email': email, + 'height': height, + 'weight': weight, + 'goal': goal, + 'target_weight': target_weight}) + + flash(f'User Profile Updated', 'success') + return render_template('display_profile.html', status=True, form=form) + else: + return redirect(url_for('login')) + return render_template('user_profile.html', status=True, form=form) + @app.route("/calories", methods=['GET', 'POST']) def calories(): @@ -170,47 +216,6 @@ def workout(): return render_template('workout.html', form=form, time=now) -# print(intake) -@app.route("/user_profile", methods=['GET', 'POST']) -def user_profile(): - """ - user_profile() function displays the UserProfileForm (user_profile.html) template - route "/user_profile" will redirect to user_profile() function. - user_profile() called and if the form is submitted then various values are fetched and updated into the database entries - Input: Email, height, weight, goal, Target weight - Output: Value update in database and redirected to home login page - """ - if session.get('email'): - form = UserProfileForm() - if form.validate_on_submit(): - if request.method == 'POST': - email = session.get('email') - weight = request.form.get('weight') - height = request.form.get('height') - goal = request.form.get('goal') - target_weight = request.form.get('target_weight') - temp = mongo.db.profile.find_one({'email': email}, { - 'height', 'weight', 'goal', 'target_weight'}) - if temp is not None: - mongo.db.profile.update_one({'email': email}, - {'$set': {'weight': temp['weight'], - 'height': temp['height'], - 'goal': temp['goal'], - 'target_weight': temp['target_weight']}}) - else: - mongo.db.profile.insert_one({'email': email, - 'height': height, - 'weight': weight, - 'goal': goal, - 'target_weight': target_weight}) - - flash(f'User Profile Updated', 'success') - return render_template('display_profile.html', status=True, form=form) - else: - return redirect(url_for('login')) - return render_template('user_profile.html', status=True, form=form) - - @app.route("/history", methods=['GET']) def history(): # ############################ diff --git a/forms.py b/forms.py index a11802ce..ce6d664f 100644 --- a/forms.py +++ b/forms.py @@ -7,6 +7,7 @@ from wtforms.validators import DataRequired, Length, Email, EqualTo, ValidationError from apps import App + class RegistrationForm(FlaskForm): username = StringField('Username', validators=[DataRequired(), Length(min=2, max=20)]) @@ -16,6 +17,19 @@ class RegistrationForm(FlaskForm): confirm_password = PasswordField( 'Confirm Password', validators=[ DataRequired(), EqualTo('password')]) + weight = StringField( + 'Weight', validators=[ + DataRequired(), Length( + min=2, max=20), ]) + height = StringField( + 'Height', validators=[ + DataRequired(), Length( + min=2, max=20)]) + target_weight = StringField( + 'Target Weight', validators=[ + DataRequired(), Length( + min=2, max=20)]) + target_date = DateField(DataRequired()) submit = SubmitField('Sign Up') def validate_email(self, email): @@ -34,6 +48,7 @@ class LoginForm(FlaskForm): remember = BooleanField('Remember Me') submit = SubmitField('Login') + class WorkoutForm(FlaskForm): app = App() mongo = app.mongo @@ -55,6 +70,7 @@ class WorkoutForm(FlaskForm): burnout = StringField('Burn Out', validators=[DataRequired()]) submit = SubmitField('Save') + class CalorieForm(FlaskForm): app = App() mongo = app.mongo @@ -108,6 +124,7 @@ class EnrollForm(FlaskForm): mongo = app.mongo submit = SubmitField('Enroll') + class ResetPasswordForm(FlaskForm): password = PasswordField('Password', validators=[DataRequired()]) confirm_password = PasswordField( diff --git a/templates/register.html b/templates/register.html index 70597c4b..72b67820 100644 --- a/templates/register.html +++ b/templates/register.html @@ -1,72 +1,115 @@ {% extends "layout.html" %} {% block content %} -
-
- {{ form.hidden_tag() }} -
- Join Today -
- {{ form.username.label(class="form-control-label") }} +
+ + {{ form.hidden_tag() }} - {% if form.username.errors %} - {{ form.username(class="form-control form-control-lg is-invalid") }} -
- {% for error in form.username.errors %} - {{ error }} - {% endfor %} -
- {% else %} - {{ form.username(class="form-control form-control-lg") }} - {% endif %} +
+ Join Today +
+ {{ form.username.label(class="form-control-label") }} + {% if form.username.errors %} + {{ form.username(class="form-control form-control-lg is-invalid") }} +
+ {% for error in form.username.errors %} + {{ error }} + {% endfor %}
-
- {{ form.email.label(class="form-control-label") }} - {% if form.email.errors %} - {{ form.email(class="form-control form-control-lg is-invalid") }} -
- {% for error in form.email.errors %} - {{ error }} - {% endfor %} -
- {% else %} - {{ form.email(class="form-control form-control-lg") }} - {% endif %} + {% else %} + {{ form.username(class="form-control form-control-lg") }} + {% endif %} +
+
+ {{ form.email.label(class="form-control-label") }} + {% if form.email.errors %} + {{ form.email(class="form-control form-control-lg is-invalid") }} +
+ {% for error in form.email.errors %} + {{ error }} + {% endfor %}
-
- {{ form.password.label(class="form-control-label") }} - {% if form.password.errors %} - {{ form.password(class="form-control form-control-lg is-invalid") }} -
- {% for error in form.password.errors %} - {{ error }} - {% endfor %} -
- {% else %} - {{ form.password(class="form-control form-control-lg") }} - {% endif %} + {% else %} + {{ form.email(class="form-control form-control-lg") }} + {% endif %} +
+
+ {{ form.password.label(class="form-control-label") }} + {% if form.password.errors %} + {{ form.password(class="form-control form-control-lg is-invalid") }} +
+ {% for error in form.password.errors %} + {{ error }} + {% endfor %}
-
- {{ form.confirm_password.label(class="form-control-label") }} - {% if form.confirm_password.errors %} - {{ form.confirm_password(class="form-control form-control-lg is-invalid") }} -
- {% for error in form.confirm_password.errors %} - {{ error }} - {% endfor %} -
- {% else %} - {{ form.confirm_password(class="form-control form-control-lg") }} - {% endif %} + {% else %} + {{ form.password(class="form-control form-control-lg") }} + {% endif %} +
+
+ {{ form.confirm_password.label(class="form-control-label") }} + {% if form.confirm_password.errors %} + {{ form.confirm_password(class="form-control form-control-lg is-invalid") }} +
+ {% for error in form.confirm_password.errors %} + {{ error }} + {% endfor %}
-
+ {% else %} + {{ form.confirm_password(class="form-control form-control-lg") }} + {% endif %} +
+
+ {{ form.height.label(class="form-control-label") }} (cms) + {% if form.height.errors %} + {{ form.height(class="form-control form-control-lg is-invalid") }} +
+ {% for error in form.height.errors %} + {{ error }} + {% endfor %} +
+ {% else %} + {{ form.height(class="form-control form-control-lg") }} + {% endif %} +
+
+ {{ form.weight.label(class="form-control-label") }} (kgs) + {% if form.weight.errors %} + {{ form.weight(class="form-control form-control-lg is-invalid") }} +
+ {% for error in form.weight.errors %} + {{ error }} + {% endfor %} +
+ {% else %} + {{ form.weight(class="form-control form-control-lg") }} + {% endif %} +
+
+ {{ form.target_weight.label(class="form-control-label") }} (kgs) + {% if form.target_weight.errors %} + {{ form.goal(class="form-control form-control-lg is-invalid") }} +
+ {% for error in form.target_weight.errors %} + {{ error }} + {% endfor %} +
+ {% else %} + {{ form.target_weight(class="form-control form-control-lg") }} + {% endif %} +
- {{ form.submit(class="btn btn-outline-info") }} + +
- -
-
- - Already Have An Account? Sign In - -
+
+
+ {{ form.submit(class="btn btn-outline-info") }} +
+ +
+
+ + Already Have An Account? Sign In + +
{% endblock content %} \ No newline at end of file