EmailCRUD
Some checks failed
K8S Fission Deployment / Deployment fission functions (push) Failing after 21s
Some checks failed
K8S Fission Deployment / Deployment fission functions (push) Failing after 21s
This commit is contained in:
@@ -89,6 +89,7 @@ def main():
|
||||
|
||||
|
||||
def user_insert_email():
|
||||
# 1. Lấy user_id từ header (identity.id Kratos)
|
||||
user_id = request.headers.get("X-UserId")
|
||||
if not user_id:
|
||||
return jsonify({"errorCode": "USER_ID_REQUIRED"}), 400, CORS_HEADERS
|
||||
@@ -97,7 +98,7 @@ def user_insert_email():
|
||||
if not data:
|
||||
return jsonify({"errorCode": "NO_DATA_PROVIDED"}), 400, CORS_HEADERS
|
||||
|
||||
parsed = UserEmailRequest(**data) # parsed luu du lieu gi ?
|
||||
parsed = UserEmailRequest(**data) # parsed(object) luu du lieu validate body ma data gui len la 1 dict
|
||||
except ValidationError as e:
|
||||
return jsonify({"errorCode": "VALIDATION_ERROR", "details": e.errors()}), 422, CORS_HEADERS
|
||||
except Exception as e:
|
||||
@@ -106,7 +107,7 @@ def user_insert_email():
|
||||
try:
|
||||
add_email, status_code, headers = crud.add_email_to_user(
|
||||
user_id, parsed.email)
|
||||
if parsed.is_primary:
|
||||
if parsed.is_primary: # Neu parsed la nick email chinh
|
||||
# update email kratos
|
||||
identity = kratos.get_identity(user_id)
|
||||
traits = identity.traits
|
||||
@@ -135,7 +136,7 @@ def user_filter_emails():
|
||||
try:
|
||||
conn = init_db_connection()
|
||||
with conn.cursor() as cursor:
|
||||
records = __filter_email(cursor, paging, user_id) # Xu ly gi day ?
|
||||
records = __filter_email(cursor, paging, user_id) # Xu ly gi day ? goi ham _filter_email
|
||||
|
||||
return jsonify(
|
||||
records,
|
||||
|
||||
@@ -168,13 +168,13 @@ def add_email_to_user(user_id: str, email: str): # Add email
|
||||
with conn.cursor() as cursor:
|
||||
cursor.execute("""
|
||||
SELECT user_id FROM ailbl_user_email WHERE email = %s;
|
||||
""", (email,))
|
||||
existing = cursor.fetchone()
|
||||
""", (email,)) # Truy van ra ket qua email
|
||||
existing = cursor.fetchone() # Tao ra bien existing save email duoc add
|
||||
if existing:
|
||||
return {"errorCode": "EMAIL_ALREADY_EXISTS"}, 409, CORS_HEADERS
|
||||
|
||||
id = str(uuid_lib.uuid4())
|
||||
provider = auto_detect_provider(email)
|
||||
provider = auto_detect_provider(email) # Ham xu li lay phan sau cua @
|
||||
cursor.execute("""
|
||||
INSERT INTO ailbl_user_email (id, user_id, email, provider, created, modified)
|
||||
VALUES (%s, %s, %s, %s, now(), now())
|
||||
|
||||
@@ -3,7 +3,7 @@ from typing import Optional
|
||||
|
||||
# Validate dau vao email
|
||||
|
||||
class UserEmailRequest(BaseModel):
|
||||
class UserEmailRequest(BaseModel): #Pased luu gia tri validate email
|
||||
email: EmailStr = Field(..., description="Email address")
|
||||
provider: Optional[str] = Field(None, description="Email service provider")
|
||||
is_primary: Optional[bool] = Field(None, description= "is primary email ")
|
||||
|
||||
Reference in New Issue
Block a user