mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 12:40:07 +00:00
send country code in ws, update profile api (#22)
* send country code in ws * make ddns_profiles optional field * update profile api
This commit is contained in:
@@ -74,6 +74,7 @@ func routers(r *gin.Engine) {
|
||||
auth.GET("/ws/file/:id", commonHandler(fmStream))
|
||||
|
||||
auth.GET("/profile", commonHandler(getProfile))
|
||||
auth.POST("/profile", commonHandler(updateProfile))
|
||||
auth.GET("/user", commonHandler(listUser))
|
||||
auth.POST("/user", commonHandler(createUser))
|
||||
auth.POST("/batch-delete/user", commonHandler(batchDeleteUser))
|
||||
|
||||
@@ -30,6 +30,46 @@ func getProfile(c *gin.Context) (*model.Profile, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Update password for current user
|
||||
// @Summary Update password for current user
|
||||
// @Security BearerAuth
|
||||
// @Schemes
|
||||
// @Description Update password for current user
|
||||
// @Tags auth required
|
||||
// @Accept json
|
||||
// @param request body model.ProfileForm true "password"
|
||||
// @Produce json
|
||||
// @Success 200 {object} model.CommonResponse[any]
|
||||
// @Router /profile [post]
|
||||
func updateProfile(c *gin.Context) (any, error) {
|
||||
var pf model.ProfileForm
|
||||
if err := c.ShouldBindJSON(&pf); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
auth, ok := c.Get(model.CtxKeyAuthorizedUser)
|
||||
if !ok {
|
||||
return nil, singleton.Localizer.ErrorT("unauthorized")
|
||||
}
|
||||
|
||||
user := *auth.(*model.User)
|
||||
if err := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(pf.OriginalPassword)); err != nil {
|
||||
return nil, singleton.Localizer.ErrorT("incorrect password")
|
||||
}
|
||||
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(pf.NewPassword), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
user.Password = string(hash)
|
||||
if err := singleton.DB.Save(&user).Error; err != nil {
|
||||
return nil, newGormError("%v", err)
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// List user
|
||||
// @Summary List user
|
||||
// @Security BearerAuth
|
||||
|
||||
@@ -108,6 +108,10 @@ func getServerStat(c *gin.Context, withPublicNote bool) ([]byte, error) {
|
||||
|
||||
servers := make([]model.StreamServer, 0, len(serverList))
|
||||
for _, server := range serverList {
|
||||
var countryCode string
|
||||
if server.GeoIP != nil {
|
||||
countryCode = server.GeoIP.CountryCode
|
||||
}
|
||||
servers = append(servers, model.StreamServer{
|
||||
ID: server.ID,
|
||||
Name: server.Name,
|
||||
@@ -115,6 +119,7 @@ func getServerStat(c *gin.Context, withPublicNote bool) ([]byte, error) {
|
||||
DisplayIndex: server.DisplayIndex,
|
||||
Host: server.Host,
|
||||
State: server.State,
|
||||
CountryCode: countryCode,
|
||||
LastActive: server.LastActive,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user