mirror of
https://github.com/simple-login/app.git
synced 2024-09-28 20:51:29 +02:00
default to UUID for api key code if the previous one is already used
This commit is contained in:
parent
3c81f982ca
commit
0075cee1ee
@ -1769,18 +1769,12 @@ class ApiKey(db.Model, ModelMixin):
|
|||||||
user = db.relationship(User)
|
user = db.relationship(User)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, user_id, name):
|
def create(cls, user_id, name=None, **kwargs):
|
||||||
# generate unique code
|
|
||||||
found = False
|
|
||||||
while not found:
|
|
||||||
code = random_string(60)
|
code = random_string(60)
|
||||||
|
if cls.get_by(code=code):
|
||||||
|
code = str(uuid.uuid4())
|
||||||
|
|
||||||
if not cls.get_by(code=code):
|
return super().create(user_id=user_id, name=name, code=code, **kwargs)
|
||||||
found = True
|
|
||||||
|
|
||||||
a = cls(user_id=user_id, code=code, name=name)
|
|
||||||
db.session.add(a)
|
|
||||||
return a
|
|
||||||
|
|
||||||
|
|
||||||
class CustomDomain(db.Model, ModelMixin):
|
class CustomDomain(db.Model, ModelMixin):
|
||||||
|
Loading…
Reference in New Issue
Block a user