Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update : Added Comments #68

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions website/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

@auth.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
if request.method == 'POST': #Getting the form from the HTML
email = request.form.get('email')
password = request.form.get('password')

user = User.query.filter_by(email=email).first()
if user:
if check_password_hash(user.password, password):
user = User.query.filter_by(email=email).first() #Checks the user in the database by key "email" and returns the first user
if user:
if check_password_hash(user.password, password): #Checks wheather the password entered match the password that has been set
flash('Logged in successfully!', category='success')
login_user(user, remember=True)
return redirect(url_for('views.home'))
Expand All @@ -31,22 +31,22 @@ def login():
@auth.route('/logout')
@login_required
def logout():
logout_user()
logout_user() #Logouts the user and returns to the login page
return redirect(url_for('auth.login'))


@auth.route('/sign-up', methods=['GET', 'POST'])
def sign_up():
if request.method == 'POST':
email = request.form.get('email')
email = request.form.get('email')
first_name = request.form.get('firstName')
password1 = request.form.get('password1')
password2 = request.form.get('password2')

user = User.query.filter_by(email=email).first()
if user:
flash('Email already exists.', category='error')
elif len(email) < 4:
user = User.query.filter_by(email=email).first() # again checks the user in user database and returns the first if exists returns the first email
if user:
flash('Email already exists.', category='error') #if an same email exists then an error will be raised
elif len(email) < 4: #checks the strength of password
flash('Email must be greater than 3 characters.', category='error')
elif len(first_name) < 2:
flash('First name must be greater than 1 character.', category='error')
Expand All @@ -56,7 +56,7 @@ def sign_up():
flash('Password must be at least 7 characters.', category='error')
else:
new_user = User(email=email, first_name=first_name, password=generate_password_hash(
password1, method='sha256'))
password1, method='sha256')) # if the conditions matches then the user will be created in the database
db.session.add(new_user)
db.session.commit()
login_user(new_user, remember=True)
Expand Down