mirror of
https://github.com/VaalaCat/frp-panel.git
synced 2026-04-22 23:17:23 +08:00
init repo
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/VaalaCat/frp-panel/biz/master/client"
|
||||
"github.com/VaalaCat/frp-panel/common"
|
||||
"github.com/VaalaCat/frp-panel/dao"
|
||||
"github.com/VaalaCat/frp-panel/models"
|
||||
"github.com/VaalaCat/frp-panel/pb"
|
||||
"github.com/VaalaCat/frp-panel/utils"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func UpdateUserInfoHander(c context.Context, req *pb.UpdateUserInfoRequest) (*pb.UpdateUserInfoResponse, error) {
|
||||
var (
|
||||
userInfo = common.GetUserInfo(c)
|
||||
)
|
||||
|
||||
if !userInfo.Valid() {
|
||||
return &pb.UpdateUserInfoResponse{
|
||||
Status: &pb.Status{Code: pb.RespCode_RESP_CODE_INVALID, Message: "invalid user"},
|
||||
}, nil
|
||||
}
|
||||
newUserEntity := userInfo.(*models.UserEntity)
|
||||
newUserInfo := req.GetUserInfo()
|
||||
|
||||
if newUserInfo.GetEmail() != "" {
|
||||
newUserEntity.Email = newUserInfo.GetEmail()
|
||||
}
|
||||
|
||||
if newUserInfo.GetRawPassword() != "" {
|
||||
hashedPassword, err := utils.HashPassword(newUserInfo.GetRawPassword())
|
||||
if err != nil {
|
||||
logrus.WithError(err).Errorf("cannot hash password")
|
||||
return nil, err
|
||||
}
|
||||
newUserEntity.Password = hashedPassword
|
||||
}
|
||||
|
||||
if newUserInfo.GetUserName() != "" {
|
||||
newUserEntity.UserName = newUserInfo.GetUserName()
|
||||
}
|
||||
|
||||
if newUserInfo.GetToken() != "" {
|
||||
newUserEntity.Token = newUserInfo.GetToken()
|
||||
}
|
||||
|
||||
if err := dao.UpdateUser(userInfo, newUserEntity); err != nil {
|
||||
return &pb.UpdateUserInfoResponse{
|
||||
Status: &pb.Status{Code: pb.RespCode_RESP_CODE_INVALID, Message: err.Error()},
|
||||
}, err
|
||||
}
|
||||
|
||||
go func() {
|
||||
newUser, err := dao.GetUserByUserID(userInfo.GetUserID())
|
||||
if err != nil {
|
||||
logrus.WithError(err).Errorf("cannot get user")
|
||||
return
|
||||
}
|
||||
|
||||
if err := client.SyncTunnel(c, newUser); err != nil {
|
||||
logrus.WithError(err).Errorf("cannot sync tunnel, user need to retry update")
|
||||
}
|
||||
}()
|
||||
|
||||
return &pb.UpdateUserInfoResponse{
|
||||
Status: &pb.Status{Code: pb.RespCode_RESP_CODE_SUCCESS, Message: "ok"},
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user