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

Merge branch "ui" into branch "dev" #827

Merged
merged 9 commits into from
Dec 28, 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
1 change: 1 addition & 0 deletions .gitleaksignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/ui/templates/profile.html:hashicorp-tf-password:343
36 changes: 20 additions & 16 deletions src/common/core/errors/files/error.html

Large diffs are not rendered by default.

33 changes: 29 additions & 4 deletions src/common/db/Database.py
Original file line number Diff line number Diff line change
Expand Up @@ -1674,18 +1674,43 @@ def get_plugin_template(self, plugin: str) -> Optional[Any]:
def get_ui_user(self) -> Optional[dict]:
"""Get ui user."""
with self.__db_session() as session:
user = session.query(Users).with_entities(Users.username, Users.password).filter_by(id=1).first()
user = session.query(Users).with_entities(Users.username, Users.password, Users.is_two_factor_enabled, Users.secret_token, Users.method).filter_by(id=1).first()
if not user:
return None
return {"username": user.username, "password_hash": user.password.encode("utf-8")}
return {
"username": user.username,
"password_hash": user.password.encode("utf-8"),
"is_two_factor_enabled": user.is_two_factor_enabled,
"secret_token": user.secret_token,
"method": user.method,
}

def create_ui_user(self, username: str, password: bytes) -> str:
def create_ui_user(self, username: str, password: bytes, *, secret_token: Optional[str] = None, method: str = "manual") -> str:
"""Create ui user."""
with self.__db_session() as session:
if self.get_ui_user():
return "User already exists"

session.add(Users(id=1, username=username, password=password.decode("utf-8")))
session.add(Users(id=1, username=username, password=password.decode("utf-8"), secret_token=secret_token, method=method))

try:
session.commit()
except BaseException:
return format_exc()

return ""

def update_ui_user(self, username: str, password: bytes, is_two_factor_enabled: bool = False, secret_token: Optional[str] = None) -> str:
"""Update ui user."""
with self.__db_session() as session:
user = session.query(Users).filter_by(id=1).first()
if not user:
return "User not found"

user.username = username
user.password = password.decode("utf-8")
user.is_two_factor_enabled = is_two_factor_enabled
user.secret_token = secret_token

try:
session.commit()
Expand Down
3 changes: 3 additions & 0 deletions src/common/db/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ class Users(Base):
id = Column(Integer, primary_key=True, default=1)
username = Column(String(256), nullable=False, unique=True)
password = Column(String(60), nullable=False)
is_two_factor_enabled = Column(Boolean, nullable=False, default=False)
secret_token = Column(String(32), nullable=True, unique=True)
method = Column(METHODS_ENUM, nullable=False, default="manual")


class Metadata(Base):
Expand Down
Loading
Loading