-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin_users.py
More file actions
33 lines (27 loc) · 1.23 KB
/
admin_users.py
File metadata and controls
33 lines (27 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from flask import Flask, render_template, request, redirect, url_for, flash
from app import create_app
from app.models import db, User
from werkzeug.security import generate_password_hash
app = create_app()
def add_admin(username, hashed_password):
with app.app_context():
# Check for existing user
existing_user = User.query.filter_by(username=username).first()
if existing_user:
print("An account with this email already exists.")
return
if isinstance(hashed_password, bytes):
hashed_password = hashed_password.decode('utf-8')
# Hash the password
hashed_password = generate_password_hash(hashed_password)
admin_user = User(email=email, username=username, hashed_password=hashed_password, is_admin=True)
db.session.add(admin_user)
db.session.commit()
print(f"Admin {username} {hashed_password} added successfully.")
if __name__ == '__main__':
email = input("Enter admin name: ")
username = input("Enter admin email: ")
# last_name = input("Enter admin last name: ")
# email = input("Enter admin email: ")
hashed_password = input("Enter admin password: ")
add_admin(username, hashed_password)