add new field type in model DID
This commit is contained in:
parent
c0dba1c423
commit
47cf19f129
|
@ -639,13 +639,13 @@ class DidRegisterView(Credentials, CreateView):
|
|||
icon = 'bi bi-patch-check-fill'
|
||||
wallet = True
|
||||
model = DID
|
||||
fields = ('label',)
|
||||
fields = ('label', 'type')
|
||||
success_url = reverse_lazy('idhub:admin_dids')
|
||||
object = None
|
||||
|
||||
def form_valid(self, form):
|
||||
form.instance.user = self.request.user
|
||||
form.instance.set_did(form.instance.type)
|
||||
form.instance.set_did()
|
||||
form.save()
|
||||
messages.success(self.request, _('DID created successfully'))
|
||||
Event.set_EV_ORG_DID_CREATED_BY_ADMIN(form.instance)
|
||||
|
|
|
@ -403,6 +403,13 @@ class Event(models.Model):
|
|||
|
||||
|
||||
class DID(models.Model):
|
||||
class Types(models.IntegerChoices):
|
||||
KEY = 1, "Key"
|
||||
WEB = 2, "Web"
|
||||
type = models.PositiveSmallIntegerField(
|
||||
_("Type"),
|
||||
choices=Types.choices,
|
||||
)
|
||||
created_at = models.DateTimeField(auto_now=True)
|
||||
label = models.CharField(_("Label"), max_length=50)
|
||||
did = models.CharField(max_length=250)
|
||||
|
@ -424,11 +431,11 @@ class DID(models.Model):
|
|||
return True
|
||||
return False
|
||||
|
||||
def set_did(self, type):
|
||||
def set_did(self):
|
||||
self.key_material = generate_did_controller_key()
|
||||
if type == "key":
|
||||
if self.type == self.Types.KEY:
|
||||
self.did = keydid_from_controller_key(self.key_material)
|
||||
elif type == "web":
|
||||
elif self.type == self.Types.WEB:
|
||||
didurl, document = webdid_from_controller_key(self.key_material)
|
||||
self.did = didurl
|
||||
self.didweb_document = document
|
||||
|
|
Loading…
Reference in a new issue