double user creation fail
This commit is contained in:
parent
b70806195e
commit
b53aab012d
1 changed files with 20 additions and 13 deletions
|
@ -4,6 +4,7 @@ from datetime import datetime
|
||||||
|
|
||||||
from passlib.context import CryptContext
|
from passlib.context import CryptContext
|
||||||
from pydantic import BaseModel, validator
|
from pydantic import BaseModel, validator
|
||||||
|
from sqlalchemy.exc import IntegrityError
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
|
@ -83,10 +84,12 @@ class User(UserBase):
|
||||||
.first())
|
.first())
|
||||||
|
|
||||||
if user is None:
|
if user is None:
|
||||||
|
# inexistent user, fake doing password verification
|
||||||
crypt_context.dummy_verify()
|
crypt_context.dummy_verify()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if not crypt_context.verify(password, user.password):
|
if not crypt_context.verify(password, user.password):
|
||||||
|
# password hash mismatch
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return cls.from_orm(user)
|
return cls.from_orm(user)
|
||||||
|
@ -97,7 +100,8 @@ class User(UserBase):
|
||||||
db: Session,
|
db: Session,
|
||||||
user: UserCreate,
|
user: UserCreate,
|
||||||
crypt_context: CryptContext,
|
crypt_context: CryptContext,
|
||||||
) -> User:
|
) -> User | None:
|
||||||
|
try:
|
||||||
user = models.User(
|
user = models.User(
|
||||||
name=user.name,
|
name=user.name,
|
||||||
password=crypt_context.hash(user.password),
|
password=crypt_context.hash(user.password),
|
||||||
|
@ -113,6 +117,9 @@ class User(UserBase):
|
||||||
|
|
||||||
return cls.from_orm(user)
|
return cls.from_orm(user)
|
||||||
|
|
||||||
|
except IntegrityError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class DistinguishedNameBase(BaseModel):
|
class DistinguishedNameBase(BaseModel):
|
||||||
cn_only: bool
|
cn_only: bool
|
||||||
|
|
Loading…
Reference in a new issue