From a3b38a5c327ba45515c75efccbd18e813c27aad0 Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Fri, 4 Jun 2021 00:06:28 +0530 Subject: added user sign in --- app/__init__.py | 9 ++++++++- app/forms/app_forms.py | 4 ++++ app/templates/auth/signin.html | 28 ++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 app/templates/auth/signin.html diff --git a/app/__init__.py b/app/__init__.py index 7145f96..1c759e7 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -3,12 +3,16 @@ from flask import Flask from flask_bcrypt import Bcrypt from flask.cli import AppGroup from flask_sqlalchemy import SQLAlchemy +import flask_login app = Flask(__name__) app.config.from_object('app.config') bcrypt = Bcrypt(app) db = SQLAlchemy(app) +login_manager = flask_login.LoginManager() + +login_manager.init_app(app) from app.models import User @@ -22,5 +26,8 @@ def delete_database(): app.cli.add_command(database_cli) +from app.views import main -from app.views import main \ No newline at end of file +@login_manager.user_loader +def load_user(email): + return User.query.filter(User.email == email).first() \ No newline at end of file diff --git a/app/forms/app_forms.py b/app/forms/app_forms.py index 2e2991d..005b53a 100644 --- a/app/forms/app_forms.py +++ b/app/forms/app_forms.py @@ -14,3 +14,7 @@ class UserSignUp(FlaskForm): last_name = StringField('Last Name') email = EmailField('Email',validators=[DataRequired(),Email()]) password = PasswordField('Password',validators=[DataRequired()]) + +class UserLogIn(FlaskForm): + email = EmailField('Email',validators=[DataRequired()]) + password = PasswordField('Password',validators=[DataRequired()]) \ No newline at end of file diff --git a/app/templates/auth/signin.html b/app/templates/auth/signin.html new file mode 100644 index 0000000..eecff34 --- /dev/null +++ b/app/templates/auth/signin.html @@ -0,0 +1,28 @@ +{% extends "base.html" %} + +{% block title %}Sign Up{% endblock %} + +{% block head %} + {{ super() }} +{% endblock %} + +{% block content %} +
+

User Login

+

Sign in to your account.

+
+ {% include 'flash_messages.html' %} + {{ form.csrf_token }} + {% from "_formhelpers.html" import render_field %} +
+ {{ render_field(form.email) }} +
+
+ {{ render_field(form.password) }} +
+
+ +
+
+
+{% endblock %} \ No newline at end of file -- cgit v1.2.3