Skip to content

Commit

Permalink
Add a function to check admin in the user class and fix codacy errors…
Browse files Browse the repository at this point in the history
… and improve the admin creation command
  • Loading branch information
carpecodeum committed Mar 10, 2020
1 parent 9901093 commit 7596e94
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
15 changes: 13 additions & 2 deletions fact-bounty-flask/api/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import coverage
import sys
import click
from flask import current_app, make_response, jsonify
from flask import current_app, make_response
from flask.cli import with_appcontext
from flask_migrate import upgrade
from werkzeug.exceptions import MethodNotAllowed, NotFound
Expand Down Expand Up @@ -201,7 +201,17 @@ def create_admin():
create an admin user
"""
admin_username = input("Enter the admin username: ")
admin_password = getpass.getpass(prompt="Enter the admin password: ")
passwords_not_same = False

while not passwords_not_same:
admin_password = getpass.getpass(prompt="Enter the admin password: ")
admin_password2 = getpass.getpass(prompt="Renter the admin password: ")
valid = bool(admin_password == admin_password2)
if valid:
break
else:
print("Passwords dont match renter the passwords")
pass
admin_role = "admin"
valid = False
while not valid:
Expand All @@ -219,5 +229,6 @@ def create_admin():
role=admin_role,
)
user.save()

except Exception as e:
return {"Error occured": str(e)}
11 changes: 11 additions & 0 deletions fact-bounty-flask/api/user/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ def find_by_verification_token(cls, verification_token):
verification_token=verification_token
).first()

@classmethod
def verify_admin(cls, email):
"""
Verify admin role
"""
try:
query = cls.query.filter_by(email=email, role="admin").first()
return print(query)
except Exception as err:
print("Error: ", err)

@staticmethod
def generate_token():
"""
Expand Down

0 comments on commit 7596e94

Please sign in to comment.