feat: now user are able to configure channels
This commit is contained in:
@@ -22,6 +22,10 @@ func GetPushMessage(c *gin.Context) {
|
||||
// Keep compatible with ServerChan
|
||||
message.Description = c.Query("desp")
|
||||
}
|
||||
if message.Channel == "" {
|
||||
// Keep compatible with old version
|
||||
message.Channel = c.Query("type")
|
||||
}
|
||||
pushMessageHelper(c, &message)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"message-pusher/common"
|
||||
"message-pusher/model"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetStatus(c *gin.Context) {
|
||||
@@ -167,3 +171,23 @@ func ResetPassword(c *gin.Context) {
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func WeChatTestAccountVerification(c *gin.Context) {
|
||||
user := model.User{Username: c.Param("username")}
|
||||
user.FillUserByUsername()
|
||||
// https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Access_Overview.html
|
||||
signature := c.Query("signature")
|
||||
timestamp := c.Query("timestamp")
|
||||
nonce := c.Query("nonce")
|
||||
echoStr := c.Query("echostr")
|
||||
arr := []string{user.WeChatTestAccountVerificationToken, timestamp, nonce}
|
||||
sort.Strings(arr)
|
||||
str := strings.Join(arr, "")
|
||||
hash := sha1.Sum([]byte(str))
|
||||
hexStr := hex.EncodeToString(hash[:])
|
||||
if signature == hexStr {
|
||||
c.String(http.StatusOK, echoStr)
|
||||
} else {
|
||||
c.Status(http.StatusForbidden)
|
||||
}
|
||||
}
|
||||
|
||||
+13
-3
@@ -342,8 +342,15 @@ func UpdateUser(c *gin.Context) {
|
||||
if updatedUser.Password == "$I_LOVE_U" {
|
||||
updatedUser.Password = "" // rollback to what it should be
|
||||
}
|
||||
updatePassword := updatedUser.Password != ""
|
||||
if err := updatedUser.Update(updatePassword); err != nil {
|
||||
// We only allow admin change those fields.
|
||||
cleanUser := model.User{
|
||||
Id: updatedUser.Id,
|
||||
Username: updatedUser.Username,
|
||||
Password: updatedUser.Password,
|
||||
DisplayName: updatedUser.DisplayName,
|
||||
}
|
||||
updatePassword := cleanUser.Password != ""
|
||||
if err := cleanUser.Update(updatePassword); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": err.Error(),
|
||||
@@ -389,13 +396,16 @@ func UpdateSelf(c *gin.Context) {
|
||||
Id: c.GetInt("id"),
|
||||
Username: user.Username,
|
||||
Password: user.Password,
|
||||
DisplayName: user.DisplayName,
|
||||
Token: user.Token,
|
||||
Channel: user.Channel,
|
||||
WeChatTestAccountId: user.WeChatTestAccountId,
|
||||
WeChatTestAccountSecret: user.WeChatTestAccountSecret,
|
||||
WeChatTestAccountTemplateId: user.WeChatTestAccountTemplateId,
|
||||
WeChatTestAccountOpenId: user.WeChatTestAccountOpenId,
|
||||
WeChatTestAccountVerificationToken: user.WeChatTestAccountVerificationToken,
|
||||
WeChatCorpAccountId: user.WeChatCorpAccountId,
|
||||
WeChatCorpAccountSecret: user.WeChatCorpAccountSecret,
|
||||
WeChatCorpAccountAgentSecret: user.WeChatCorpAccountAgentSecret,
|
||||
WeChatCorpAccountAgentId: user.WeChatCorpAccountAgentId,
|
||||
WeChatCorpAccountUserId: user.WeChatCorpAccountUserId,
|
||||
WeChatCorpAccountClientType: user.WeChatCorpAccountClientType,
|
||||
|
||||
Reference in New Issue
Block a user