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

Fix few bugs in branch: main, merge main into development #41

Merged
merged 3 commits into from
Feb 12, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ MAIL_USERNAME="website email"
MAIL_PASSWORD="Your app password need to get it from your email provider"
ADMIN_USERNAME="optional"
ADMIN_PASSWORD="optional min 6 char"
ADMIN_EMAIL="not optional"
ADMIN_EMAIL="not optional"
2 changes: 1 addition & 1 deletion templates/components/search_contents.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h3 class="mt-5 text-center text-capitalize"> Find your pair-programming partner
{{ form_search.is_supporter(class_="form-select") }}
</div>
<div class="col-12 d-flex align-items-center justify-content-center">
{{ form_search.submit_register(class_= "form-control") }}
{{ form_search.submit(class_= "form-control") }}
</div>
</form>
<p>message: {{ message }}</p>
Expand Down
56 changes: 31 additions & 25 deletions utils/models/auth_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import os

from sqlalchemy.exc import IntegrityError
from sqlalchemy import cast, String
# from sqlalchemy import cast, String #miku
from sqlalchemy import cast, String, create_engine #miku
from sqlalchemy.engine import reflection #miku
from flask_login import UserMixin, login_user
from werkzeug.security import check_password_hash, generate_password_hash

Expand All @@ -15,30 +17,34 @@


def create_admin():
users = UserProfile.query.all()
if len(users) == 0 and os.getenv("ADMIN_EMAIL"):
user_id = str(uuid.uuid4())
password = "admin1" if not os.getenv("ADMIN_PASSWORD") else os.getenv("ADMIN_PASSWORD")
hashed_password = generate_password_hash(
password,
method='pbkdf2:sha256',
salt_length=8
)
user = UserProfile(
email=os.getenv("ADMIN_EMAIL"),
user_name="admin" if not os.getenv("ADMIN_USERNAME") else os.getenv("ADMIN_USERNAME"),
user_profile_id=user_id,
is_supporter=True,
is_admin=True
)

password = UserPassword(user_id=user_id, password=hashed_password)
db.session.add(user)
db.session.add(password)
db.session.commit()

if not os.getenv("ADMIN_EMAIL"):
print("The ADMIN_EMAIL must be set in the env file")
engin = create_engine(os.getenv('POSTGRES_URL')) #miku
inspect = db.inspect(engin).get_table_names() #miku

if inspect != []: #miku
users = UserProfile.query.all()
if len(users) == 0 and os.getenv("ADMIN_EMAIL"):
user_id = str(uuid.uuid4())
password = "admin1" if not os.getenv("ADMIN_PASSWORD") else os.getenv("ADMIN_PASSWORD")
hashed_password = generate_password_hash(
password,
method='pbkdf2:sha256',
salt_length=8
)
user = UserProfile(
email=os.getenv("ADMIN_EMAIL"),
user_name="admin" if not os.getenv("ADMIN_USERNAME") else os.getenv("ADMIN_USERNAME"),
user_profile_id=user_id,
is_supporter=True,
is_admin=True
)

password = UserPassword(user_id=user_id, password=hashed_password)
db.session.add(user)
db.session.add(password)
db.session.commit()

if not os.getenv("ADMIN_EMAIL"):
print("The ADMIN_EMAIL must be set in the env file")


class AuthManager(UserMixin):
Expand Down