Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
translation-server
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
qinmingyuan
translation-server
Commits
c9fa7831
Commit
c9fa7831
authored
Jan 09, 2025
by
mingyard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:swagger
parent
b1dc0400
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
97 additions
and
3 deletions
+97
-3
auth.controller.ts
src/controller/auth/auth.controller.ts
+27
-3
login.dto.ts
src/controller/auth/dto/req/login.dto.ts
+11
-0
register.dto.ts
src/controller/auth/dto/req/register.dto.ts
+16
-0
loginRes.dto.ts
src/controller/auth/dto/res/loginRes.dto.ts
+6
-0
userBase.dto.ts
src/controller/auth/dto/userBase.dto.ts
+37
-0
No files found.
src/controller/auth/auth.controller.ts
View file @
c9fa7831
...
...
@@ -14,7 +14,10 @@ import { ApiResponseInterceptor } from '@/common/interceptor/api.response.interc
import
{
ApiExceptionsFilter
}
from
'@/common/filter/api.exception.filter'
;
import
{
RegisterDto
}
from
'./dto/req/register.dto'
;
import
{
Auth
}
from
'@/common/decorators/auth.decorator'
;
import
{
ApiTags
,
ApiOperation
,
ApiResponse
}
from
'@nestjs/swagger'
;
import
{
LoginResDto
}
from
'./dto/res/loginRes.dto'
;
@
ApiTags
(
'auth'
)
@
Controller
(
'auth'
)
@
UseInterceptors
(
ApiResponseInterceptor
)
@
UseFilters
(
ApiExceptionsFilter
)
...
...
@@ -22,8 +25,14 @@ export class AuthController {
constructor
(
private
readonly
authService
:
AuthService
)
{}
// 登录接口
@
ApiOperation
({
summary
:
'用户登录'
})
@
ApiResponse
({
status
:
200
,
description
:
'登录成功'
,
type
:
LoginResDto
})
@
ApiResponse
({
status
:
401
,
description
:
'认证失败'
})
@
Post
(
'login'
)
async
login
(@
Body
()
loginDto
:
LoginDto
,
@
Req
()
req
:
IRequest
)
{
async
login
(
@
Body
()
loginDto
:
LoginDto
,
@
Req
()
req
:
IRequest
,
):
Promise
<
LoginResDto
>
{
const
record
:
LoginRecordDto
=
{
userId
:
null
,
ip
:
req
.
ip
,
...
...
@@ -38,15 +47,30 @@ export class AuthController {
}
// 注册接口
@
ApiOperation
({
summary
:
'用户注册'
})
@
ApiResponse
({
status
:
201
,
description
:
'注册成功'
,
type
:
LoginResDto
})
@
ApiResponse
({
status
:
400
,
description
:
'请求参数错误'
})
@
Post
(
'register'
)
async
register
(@
Body
()
registerDto
:
RegisterDto
)
{
async
register
(@
Body
()
registerDto
:
RegisterDto
)
:
Promise
<
LoginResDto
>
{
return
await
this
.
authService
.
register
(
registerDto
);
}
// 重置密码接口
@
ApiOperation
({
summary
:
'用户重置密码'
})
@
ApiResponse
({
status
:
200
,
description
:
'重置密码成功'
,
type
:
LoginResDto
})
@
ApiResponse
({
status
:
400
,
description
:
'请求参数错误'
})
@
Post
(
'resetPwd'
)
async
resetPwd
(@
Body
()
registerDto
:
RegisterDto
):
Promise
<
LoginResDto
>
{
return
await
this
.
authService
.
resetPwd
(
registerDto
);
}
// 退出登录接口
@
ApiOperation
({
summary
:
'用户退出登录'
})
@
ApiResponse
({
status
:
200
,
description
:
'退出登录成功'
})
@
ApiResponse
({
status
:
401
,
description
:
'认证失败'
})
@
Auth
()
@
Post
(
'logout'
)
async
logout
(@
Req
()
req
:
IRequest
)
{
async
logout
(@
Req
()
req
:
IRequest
)
:
Promise
<
void
>
{
return
await
this
.
authService
.
logout
(
req
.
token
,
req
.
decodedToken
.
exp
);
}
}
src/controller/auth/dto/req/login.dto.ts
View file @
c9fa7831
import
{
IsString
,
IsNotEmpty
,
IsPhoneNumber
}
from
'class-validator'
;
import
{
ApiProperty
}
from
'@nestjs/swagger'
;
export
class
LoginDto
{
@
ApiProperty
({
description
:
'用户的手机号码'
,
type
:
'string'
,
example
:
'13800138000'
,
})
@
IsNotEmpty
()
@
IsString
()
@
IsPhoneNumber
(
'CN'
)
phone
:
string
;
@
ApiProperty
({
description
:
'用户的密码'
,
type
:
'string'
,
example
:
'1234test'
,
})
@
IsNotEmpty
()
@
IsString
()
password
:
string
;
...
...
src/controller/auth/dto/req/register.dto.ts
View file @
c9fa7831
import
{
ApiProperty
}
from
'@nestjs/swagger'
;
import
{
IsString
,
IsNotEmpty
,
...
...
@@ -7,15 +8,30 @@ import {
}
from
'class-validator'
;
export
class
RegisterDto
{
@
ApiProperty
({
description
:
'用户的手机号码'
,
type
:
'string'
,
example
:
'13800138000'
,
})
@
IsNotEmpty
()
@
IsString
()
@
IsPhoneNumber
(
'CN'
)
phone
:
string
;
@
ApiProperty
({
description
:
'短信验证码'
,
type
:
'number'
,
example
:
1234
,
})
@
IsNotEmpty
()
@
IsNumber
()
code
:
number
;
@
ApiProperty
({
description
:
'用户的密码'
,
type
:
'string'
,
example
:
'1234test'
,
})
@
IsNotEmpty
()
@
IsString
()
@
Matches
(
/^
(?=
.*
[
A-Za-z
])(?=
.*
\d)[
A-Za-z
\d]{8,}
$/
,
{
...
...
src/controller/auth/dto/res/loginRes.dto.ts
View file @
c9fa7831
import
{
Expose
}
from
'class-transformer'
;
import
{
UserBaseDto
}
from
'../userBase.dto'
;
import
{
ApiProperty
}
from
'@nestjs/swagger'
;
export
class
LoginResDto
extends
UserBaseDto
{
@
ApiProperty
({
description
:
'用户的登录令牌'
,
type
:
'string'
,
example
:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
,
})
@
Expose
()
token
:
string
;
}
src/controller/auth/dto/userBase.dto.ts
View file @
c9fa7831
import
{
ApiProperty
}
from
'@nestjs/swagger'
;
import
{
Expose
}
from
'class-transformer'
;
export
class
UserBaseDto
{
@
ApiProperty
({
description
:
'用户的id'
,
type
:
'number'
,
example
:
1111
,
})
@
Expose
()
id
:
number
;
@
ApiProperty
({
description
:
'用户的账号'
,
type
:
'string'
,
example
:
'test'
,
})
@
Expose
()
acc
:
string
;
@
ApiProperty
({
description
:
'用户的手机号码'
,
type
:
'string'
,
example
:
'13800138000'
,
})
@
Expose
()
phone
:
string
;
@
ApiProperty
({
description
:
'用户的邮箱地址'
,
type
:
'string'
,
example
:
'test@example.com'
,
})
@
Expose
()
mailAddr
:
string
;
@
ApiProperty
({
description
:
'用户的最后登录时间'
,
type
:
'number'
,
example
:
1627849200
,
})
@
Expose
()
lastLoginTime
:
number
;
@
ApiProperty
({
description
:
'用户的状态'
,
type
:
'number'
,
example
:
1
,
})
@
Expose
()
state
:
number
;
@
ApiProperty
({
description
:
'用户的昵称'
,
type
:
'string'
,
example
:
'test_nickname'
,
required
:
false
,
})
@
Expose
()
nickname
?:
string
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment