# Copyright (c) 2024, JINGROW
# For license information, please see license.txt

# import jingrow
from jingrow.model.page import Page


class User2FA(Page):
	# begin: auto-generated types
	# This code is auto-generated. Do not modify anything in this block.

	from typing import TYPE_CHECKING

	if TYPE_CHECKING:
		from jingrow.types import DF

		enabled: DF.Check
		totp_secret: DF.Password | None
		user: DF.Link | None
	# end: auto-generated types

	def validate(self):
		if self.enabled and not self.totp_secret:
			self.generate_secret()

	def generate_secret(self):
		import pyotp

		self.totp_secret = pyotp.random_base32()
