Merge pull request #160 from alimy/jc/alimy

support custom PhoneBind/Alipay feature just use config file
pull/162/head
Michael Li 2 years ago committed by GitHub
commit 2ac226a4f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -320,9 +320,12 @@ release/paopao-ce --no-default-features --features sqlite3,localoss,loggerfile,r
`LoggerFile` 使用文件写日志(目前状态: 稳定);
`LoggerZinc` 使用[Zinc](https://github.com/zinclabs/zinc)写日志(目前状态: 稳定,推荐使用);
`LoggerMeili` 使用[Meilisearch](https://github.com/meilisearch/meilisearch)写日志(目前状态: 内测阶段);
* 支付: Alipay
* 短信验证码: SmsJuhe(需要开启sms)
`Sms`功能如果没有开启,任意短信验证码都可以绑定手机;
* 支付: Alipay
`Alipay` 开启基于[支付宝开放平台](https://open.alipay.com/)的钱包功能;
* 短信验证码: SmsJuhe(需要开启sms)
`Sms` 开启短信验证码功能,用于手机绑定验证手机是否注册者的;功能如果没有开启,手机绑定时任意短信验证码都可以绑定手机;
* 其他: PhoneBind
`PhoneBind` 开启手机绑定功能;
### 搭建依赖环境
#### [Zinc](https://github.com/zinclabs/zinc) 搜索引擎:

@ -15,7 +15,7 @@ Features:
Develop: ["Base", "MySQL", "BigCacheIndex", "Meili", "Sms", "AliOSS", "LoggerMeili", "Migration"]
Demo: ["Base", "MySQL", "Option", "Zinc", "Sms", "MinIO", "LoggerZinc"]
Slim: ["Base", "Sqlite3", "LocalOSS", "LoggerFile"]
Base: ["Redis", "Alipay"]
Base: ["Redis", "Alipay", "PhoneBind"]
Option: ["SimpleCacheIndex"]
Sms: "SmsJuhe"
SmsJuhe:

@ -2,30 +2,29 @@ package middleware
import (
"github.com/gin-gonic/gin"
"github.com/rocboss/paopao-ce/internal/conf"
"github.com/rocboss/paopao-ce/internal/model"
"github.com/rocboss/paopao-ce/pkg/app"
"github.com/rocboss/paopao-ce/pkg/errcode"
)
func Priv() gin.HandlerFunc {
enablePhoneBind := conf.CfgIf("PhoneBind")
return func(c *gin.Context) {
if user, exist := c.Get("USER"); exist {
if userModel, ok := user.(*model.User); ok {
if userModel.Status == model.UserStatusNormal {
if userModel.Phone == "" {
if enablePhoneBind && userModel.Phone == "" {
response := app.NewResponse(c)
response.ToErrorResponse(errcode.AccountNoPhoneBind)
c.Abort()
return
}
c.Next()
return
}
}
}
response := app.NewResponse(c)
response.ToErrorResponse(errcode.UserHasBeenBanned)
c.Abort()

@ -49,9 +49,6 @@ func NewRouter() *gin.Engine {
// 发送验证码
r.POST("/captcha", api.PostCaptcha)
// 支付宝回调
r.POST("/alipay/notify", api.AlipayNotify)
// 无鉴权路由组
noAuthApi := r.Group("/")
{
@ -108,7 +105,9 @@ func NewRouter() *gin.Engine {
authApi.GET("/user/stars", api.GetUserStars)
// 绑定用户手机号
authApi.POST("/user/phone", api.BindUserPhone)
if conf.CfgIf("PhoneBind") {
authApi.POST("/user/phone", api.BindUserPhone)
}
// 修改密码
authApi.POST("/user/password", api.ChangeUserPassword)
@ -125,15 +124,6 @@ func NewRouter() *gin.Engine {
// 检索标签
authApi.GET("/suggest/tags", api.GetSuggestTags)
// 用户充值
authApi.POST("/user/recharge", api.GetUserRechargeLink)
// 用户充值
authApi.GET("/user/recharge", api.GetUserRechargeResult)
// 获取用户账单
authApi.GET("/user/wallet/bills", api.GetUserWalletBills)
// 上传资源
privApi.POST("/attachment", api.UploadAttachment)
@ -185,6 +175,10 @@ func NewRouter() *gin.Engine {
// 管理·禁言/解封用户
adminApi.POST("/admin/user/status", api.ChangeUserStatus)
}
// 支付宝路由注册
alipayRoute(r, authApi)
// 默认404
e.NoRoute(func(c *gin.Context) {
c.JSON(http.StatusNotFound, gin.H{
@ -192,6 +186,7 @@ func NewRouter() *gin.Engine {
"msg": "Not Found",
})
})
// 默认405
e.NoMethod(func(c *gin.Context) {
c.JSON(http.StatusMethodNotAllowed, gin.H{
@ -199,6 +194,7 @@ func NewRouter() *gin.Engine {
"msg": "Method Not Allowed",
})
})
return e
}
@ -216,3 +212,21 @@ func routeLocalOSS(e *gin.Engine) {
logrus.Infof("register LocalOSS route in /oss on save path: %s", savePath)
}
func alipayRoute(public gin.IRoutes, authApi gin.IRoutes) {
if !conf.CfgIf("Alipay") {
return
}
// 支付宝回调
public.POST("/alipay/notify", api.AlipayNotify)
// 用户充值
authApi.POST("/user/recharge", api.GetUserRechargeLink)
// 获取钱包余额
authApi.GET("/user/recharge", api.GetUserRechargeResult)
// 获取用户账单
authApi.GET("/user/wallet/bills", api.GetUserWalletBills)
}

@ -8,6 +8,7 @@ VITE_ALLOW_TWEET_ATTACHMENT=true
VITE_ALLOW_TWEET_ATTACHMENT_PRICE=true
VITE_ALLOW_TWEET_VIDEO=true
VITE_ALLOW_TWEET_VISIBILITY=true
VITE_ALLOW_PHONE_BIND=true
# 局部参数
VITE_DEFAULT_TWEET_VISIBILITY=public

@ -9,9 +9,10 @@
:src="store.state.userInfo.avatar"
/>
<n-upload
v-if="
v-if="!allowPhoneBind || (
allowPhoneBind &&
store.state.userInfo.phone &&
store.state.userInfo.phone.length > 0
store.state.userInfo.phone.length > 0)
"
ref="avatarRef"
:action="uploadGateway"
@ -48,11 +49,12 @@
round
type="success"
size="small"
v-if="
!showNicknameEdit &&
v-if="!showNicknameEdit && (!allowPhoneBind || (
allowPhoneBind &&
store.state.userInfo.phone &&
store.state.userInfo.phone.length > 0 &&
store.state.userInfo.status == 1
store.state.userInfo.status == 1)
)
"
@click="handleNicknameShow"
>
@ -70,7 +72,9 @@
</div>
</n-card>
<n-card title="手机号" size="small" class="setting-card">
<n-card
v-if="allowPhoneBind"
title="手机号" size="small" class="setting-card">
<div
v-if="
store.state.userInfo.phone &&
@ -270,6 +274,7 @@ import type {
InputInst,
} from 'naive-ui';
const allowPhoneBind= (import.meta.env.VITE_ALLOW_PHONE_BIND.toLocaleLowerCase() === 'true')
const uploadGateway = import.meta.env.VITE_HOST + '/v1/attachment';
const uploadToken = 'Bearer ' + localStorage.getItem('PAOPAO_TOKEN');
const uploadType = ref('public/avatar');

@ -10,6 +10,7 @@ interface ImportMetaEnv {
readonly VITE_ALLOW_TWEET_ATTACHMENT_PRICE: string
readonly VITE_ALLOW_TWEET_VIDEO: string
readonly VITE_ALLOW_TWEET_VISIBILITY: string
readonly VITE_ALLOW_PHONE_BINDING: string
readonly VITE_DEFAULT_TWEET_VISIBILITY: string
}

Loading…
Cancel
Save