add admin login and optimize the swagger definition
parent
bc039efdaf
commit
db36e3edf9
@ -0,0 +1,8 @@
|
||||
from flask import Blueprint
|
||||
|
||||
from libs.external_api import ExternalApi
|
||||
|
||||
bp = Blueprint("admin_api", __name__, url_prefix="/admin")
|
||||
api = ExternalApi(bp)
|
||||
|
||||
from .auth import login
|
||||
@ -0,0 +1,124 @@
|
||||
from flask import Blueprint
|
||||
from flask_restful import Api, Resource # type: ignore
|
||||
|
||||
from controllers.admin import api
|
||||
|
||||
class SendVerificationCodeApi(Resource):
|
||||
def post(self):
|
||||
"""Send verification code to admin's phone number.
|
||||
---
|
||||
tags:
|
||||
- admin
|
||||
summary: Send Verification Code
|
||||
description: Sends a verification code to the provided admin phone number for authentication
|
||||
parameters:
|
||||
- in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
type: object
|
||||
required:
|
||||
- phone
|
||||
properties:
|
||||
phone:
|
||||
type: string
|
||||
description: Admin's phone number
|
||||
example: "13800138000"
|
||||
responses:
|
||||
200:
|
||||
description: Code sent successfully
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
success:
|
||||
type: boolean
|
||||
message:
|
||||
type: string
|
||||
400:
|
||||
description: Invalid phone number format
|
||||
404:
|
||||
description: Phone number not registered as admin
|
||||
"""
|
||||
pass
|
||||
|
||||
class LoginApi(Resource):
|
||||
def post(self):
|
||||
"""Admin login with phone number and verification code.
|
||||
---
|
||||
tags:
|
||||
- admin
|
||||
summary: Admin Login
|
||||
description: Authenticates an admin using phone number and verification code
|
||||
parameters:
|
||||
- in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
type: object
|
||||
required:
|
||||
- phone
|
||||
- code
|
||||
properties:
|
||||
phone:
|
||||
type: string
|
||||
description: Admin's phone number
|
||||
example: "13800138000"
|
||||
code:
|
||||
type: string
|
||||
description: Verification code
|
||||
example: "123456"
|
||||
responses:
|
||||
200:
|
||||
description: Login successful
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
token:
|
||||
type: string
|
||||
description: JWT access token
|
||||
user:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
phone:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
role:
|
||||
type: string
|
||||
enum: [admin, super_admin]
|
||||
400:
|
||||
description: Invalid or expired verification code
|
||||
404:
|
||||
description: Phone number not registered
|
||||
"""
|
||||
pass
|
||||
|
||||
class LogoutApi(Resource):
|
||||
def post(self):
|
||||
"""Admin logout.
|
||||
---
|
||||
tags:
|
||||
- admin
|
||||
summary: Admin Logout
|
||||
description: Logs out the authenticated admin and invalidates the JWT token
|
||||
security:
|
||||
- JWT: []
|
||||
responses:
|
||||
200:
|
||||
description: Logout successful
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
success:
|
||||
type: boolean
|
||||
401:
|
||||
description: Missing or invalid token
|
||||
"""
|
||||
pass
|
||||
|
||||
# Register the resources
|
||||
api.add_resource(SendVerificationCodeApi, '/auth/send-code')
|
||||
api.add_resource(LoginApi, '/auth/login')
|
||||
api.add_resource(LogoutApi, '/auth/logout')
|
||||
Loading…
Reference in New Issue