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
You need to sign in or sign up before continuing.
Commit
c9fa7831
authored
Jan 09, 2025
by
mingyard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:swagger
parent
b1dc0400
Show 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
...
@@ -14,7 +14,10 @@ import { ApiResponseInterceptor } from '@/common/interceptor/api.response.interc
import
{
ApiExceptionsFilter
}
from
'@/common/filter/api.exception.filter'
;
import
{
ApiExceptionsFilter
}
from
'@/common/filter/api.exception.filter'
;
import
{
RegisterDto
}
from
'./dto/req/register.dto'
;
import
{
RegisterDto
}
from
'./dto/req/register.dto'
;
import
{
Auth
}
from
'@/common/decorators/auth.decorator'
;
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'
)
@
Controller
(
'auth'
)
@
UseInterceptors
(
ApiResponseInterceptor
)
@
UseInterceptors
(
ApiResponseInterceptor
)
@
UseFilters
(
ApiExceptionsFilter
)
@
UseFilters
(
ApiExceptionsFilter
)
...
@@ -22,8 +25,14 @@ export class AuthController {
...
@@ -22,8 +25,14 @@ export class AuthController {
constructor
(
private
readonly
authService
:
AuthService
)
{}
constructor
(
private
readonly
authService
:
AuthService
)
{}
// 登录接口
// 登录接口
@
ApiOperation
({
summary
:
'用户登录'
})
@
ApiResponse
({
status
:
200
,
description
:
'登录成功'
,
type
:
LoginResDto
})
@
ApiResponse
({
status
:
401
,
description
:
'认证失败'
})
@
Post
(
'login'
)
@
Post
(
'login'
)
async
login
(@
Body
()
loginDto
:
LoginDto
,
@
Req
()
req
:
IRequest
)
{
async
login
(
@
Body
()
loginDto
:
LoginDto
,
@
Req
()
req
:
IRequest
,
):
Promise
<
LoginResDto
>
{
const
record
:
LoginRecordDto
=
{
const
record
:
LoginRecordDto
=
{
userId
:
null
,
userId
:
null
,
ip
:
req
.
ip
,
ip
:
req
.
ip
,
...
@@ -38,15 +47,30 @@ export class AuthController {
...
@@ -38,15 +47,30 @@ export class AuthController {
}
}
// 注册接口
// 注册接口
@
ApiOperation
({
summary
:
'用户注册'
})
@
ApiResponse
({
status
:
201
,
description
:
'注册成功'
,
type
:
LoginResDto
})
@
ApiResponse
({
status
:
400
,
description
:
'请求参数错误'
})
@
Post
(
'register'
)
@
Post
(
'register'
)
async
register
(@
Body
()
registerDto
:
RegisterDto
)
{
async
register
(@
Body
()
registerDto
:
RegisterDto
)
:
Promise
<
LoginResDto
>
{
return
await
this
.
authService
.
register
(
registerDto
);
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
()
@
Auth
()
@
Post
(
'logout'
)
@
Post
(
'logout'
)
async
logout
(@
Req
()
req
:
IRequest
)
{
async
logout
(@
Req
()
req
:
IRequest
)
:
Promise
<
void
>
{
return
await
this
.
authService
.
logout
(
req
.
token
,
req
.
decodedToken
.
exp
);
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
{
IsString
,
IsNotEmpty
,
IsPhoneNumber
}
from
'class-validator'
;
import
{
ApiProperty
}
from
'@nestjs/swagger'
;
export
class
LoginDto
{
export
class
LoginDto
{
@
ApiProperty
({
description
:
'用户的手机号码'
,
type
:
'string'
,
example
:
'13800138000'
,
})
@
IsNotEmpty
()
@
IsNotEmpty
()
@
IsString
()
@
IsString
()
@
IsPhoneNumber
(
'CN'
)
@
IsPhoneNumber
(
'CN'
)
phone
:
string
;
phone
:
string
;
@
ApiProperty
({
description
:
'用户的密码'
,
type
:
'string'
,
example
:
'1234test'
,
})
@
IsNotEmpty
()
@
IsNotEmpty
()
@
IsString
()
@
IsString
()
password
:
string
;
password
:
string
;
...
...
src/controller/auth/dto/req/register.dto.ts
View file @
c9fa7831
import
{
ApiProperty
}
from
'@nestjs/swagger'
;
import
{
import
{
IsString
,
IsString
,
IsNotEmpty
,
IsNotEmpty
,
...
@@ -7,15 +8,30 @@ import {
...
@@ -7,15 +8,30 @@ import {
}
from
'class-validator'
;
}
from
'class-validator'
;
export
class
RegisterDto
{
export
class
RegisterDto
{
@
ApiProperty
({
description
:
'用户的手机号码'
,
type
:
'string'
,
example
:
'13800138000'
,
})
@
IsNotEmpty
()
@
IsNotEmpty
()
@
IsString
()
@
IsString
()
@
IsPhoneNumber
(
'CN'
)
@
IsPhoneNumber
(
'CN'
)
phone
:
string
;
phone
:
string
;
@
ApiProperty
({
description
:
'短信验证码'
,
type
:
'number'
,
example
:
1234
,
})
@
IsNotEmpty
()
@
IsNotEmpty
()
@
IsNumber
()
@
IsNumber
()
code
:
number
;
code
:
number
;
@
ApiProperty
({
description
:
'用户的密码'
,
type
:
'string'
,
example
:
'1234test'
,
})
@
IsNotEmpty
()
@
IsNotEmpty
()
@
IsString
()
@
IsString
()
@
Matches
(
/^
(?=
.*
[
A-Za-z
])(?=
.*
\d)[
A-Za-z
\d]{8,}
$/
,
{
@
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
{
Expose
}
from
'class-transformer'
;
import
{
UserBaseDto
}
from
'../userBase.dto'
;
import
{
UserBaseDto
}
from
'../userBase.dto'
;
import
{
ApiProperty
}
from
'@nestjs/swagger'
;
export
class
LoginResDto
extends
UserBaseDto
{
export
class
LoginResDto
extends
UserBaseDto
{
@
ApiProperty
({
description
:
'用户的登录令牌'
,
type
:
'string'
,
example
:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
,
})
@
Expose
()
@
Expose
()
token
:
string
;
token
:
string
;
}
}
src/controller/auth/dto/userBase.dto.ts
View file @
c9fa7831
import
{
ApiProperty
}
from
'@nestjs/swagger'
;
import
{
Expose
}
from
'class-transformer'
;
import
{
Expose
}
from
'class-transformer'
;
export
class
UserBaseDto
{
export
class
UserBaseDto
{
@
ApiProperty
({
description
:
'用户的id'
,
type
:
'number'
,
example
:
1111
,
})
@
Expose
()
@
Expose
()
id
:
number
;
id
:
number
;
@
ApiProperty
({
description
:
'用户的账号'
,
type
:
'string'
,
example
:
'test'
,
})
@
Expose
()
@
Expose
()
acc
:
string
;
acc
:
string
;
@
ApiProperty
({
description
:
'用户的手机号码'
,
type
:
'string'
,
example
:
'13800138000'
,
})
@
Expose
()
@
Expose
()
phone
:
string
;
phone
:
string
;
@
ApiProperty
({
description
:
'用户的邮箱地址'
,
type
:
'string'
,
example
:
'test@example.com'
,
})
@
Expose
()
@
Expose
()
mailAddr
:
string
;
mailAddr
:
string
;
@
ApiProperty
({
description
:
'用户的最后登录时间'
,
type
:
'number'
,
example
:
1627849200
,
})
@
Expose
()
@
Expose
()
lastLoginTime
:
number
;
lastLoginTime
:
number
;
@
ApiProperty
({
description
:
'用户的状态'
,
type
:
'number'
,
example
:
1
,
})
@
Expose
()
@
Expose
()
state
:
number
;
state
:
number
;
@
ApiProperty
({
description
:
'用户的昵称'
,
type
:
'string'
,
example
:
'test_nickname'
,
required
:
false
,
})
@
Expose
()
@
Expose
()
nickname
?:
string
;
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