diff --git a/model/system_model/verify_information.go b/model/system_model/verify_information.go index 6187985..fc2cd9b 100644 --- a/model/system_model/verify_information.go +++ b/model/system_model/verify_information.go @@ -2,7 +2,7 @@ * @Author: LinkLeong link@icewhale.com * @Date: 2022-06-15 11:30:47 * @LastEditors: LinkLeong - * @LastEditTime: 2022-06-15 15:10:10 + * @LastEditTime: 2022-06-15 17:25:48 * @FilePath: /CasaOS/model/system_model/verify_information.go * @Description: * @Website: https://www.casaos.io @@ -11,7 +11,7 @@ package system_model type VerifyInformation struct { - RefreshToken string `json:"refresh"` + RefreshToken string `json:"refresh_token"` AccessToken string `json:"access_token"` ExpiresAt string `json:"expires_at"` } diff --git a/route/route.go b/route/route.go index 08e53fc..a438372 100644 --- a/route/route.go +++ b/route/route.go @@ -31,15 +31,17 @@ func InitRouter() *gin.Engine { if swagHandler != nil { r.GET("/swagger/*any", swagHandler) } + + r.POST("/v1/user/register", v1.PostUserRegister) r.POST("/v1/user/login", v1.Login) + r.POST("/v1/user/all/name", v1.GetUserAllUserName) r.GET("/v1/guide/check", v1.GetGuideCheck) r.GET("/v1/debug", v1.GetSystemConfigDebug) - r.POST("/v1/user/register", v1.PostUserRegister) //get user info - r.GET("/v1/user/info", v1.GetUserInfo) + //get user info r.GET("/v1/person/shareid", v1.GetPersonShareId) r.GET("/v1/sys/socket/port", v1.GetSystemSocketPort) @@ -53,18 +55,20 @@ func InitRouter() *gin.Engine { { //chang head - v1UserGroup.POST("/head", v1.PostUserHead) + //v1UserGroup.POST("/head", v1.PostUserHead) //chang user name - v1UserGroup.PUT("/username", v1.PutUserName) + v1UserGroup.PUT("/username:/id", v1.PutUserName) //chang pwd - v1UserGroup.PUT("/password", v1.PutUserPwd) + v1UserGroup.PUT("/password/:id", v1.PutUserPwd) //edit user info - v1UserGroup.POST("/info", v1.PostUserChangeInfo) - v1UserGroup.PUT("/nick", v1.PutUserChangeNick) - v1UserGroup.PUT("/desc", v1.PutUserChangeDesc) - v1UserGroup.POST("/person/info", v1.PostUserPersonInfo) + //v1UserGroup.POST("/info", v1.PostUserChangeInfo) + v1UserGroup.PUT("/nick:/id", v1.PutUserNick) + v1UserGroup.PUT("/desc/:id", v1.PutUserDesc) + v1UserGroup.GET("/v1/user/info/:id", v1.GetUserInfo) + //v1UserGroup.POST("/person/info", v1.PostUserPersonInfo) v1UserGroup.GET("/shareid", v1.GetUserShareID) + v1UserGroup.GET("/custom/:name") v1UserGroup.POST("/custom/:name") } @@ -133,7 +137,6 @@ func InitRouter() *gin.Engine { v1SysGroup.GET("/mem", v1.GetSystemMemInfo) v1SysGroup.GET("/disk", v1.GetSystemDiskInfo) v1SysGroup.GET("/network", v1.GetSystemNetInfo) - v1SysGroup.POST("/refresh/token", v1.GetSystemRefreshToken) } v1FileGroup := v1Group.Group("/file") diff --git a/route/v1/system.go b/route/v1/system.go index 9943907..fc2f01e 100644 --- a/route/v1/system.go +++ b/route/v1/system.go @@ -537,7 +537,7 @@ func GetSystemNetInfo(c *gin.Context) { func PostSystemRefreshToken(c *gin.Context) { json := make(map[string]string) c.BindJSON(&json) - refresh := json["refresh"] + refresh := json["refresh_token"] claims, err := jwt.ParseToken(refresh) if err != nil { c.JSON(http.StatusOK, model.Result{Success: common_err.ERROR, Message: common_err.GetMsg(common_err.VERIFICATION_FAILURE), Data: err.Error()}) diff --git a/route/v1/user.go b/route/v1/user.go index f75fd89..67ebacf 100644 --- a/route/v1/user.go +++ b/route/v1/user.go @@ -55,6 +55,7 @@ func PostUserRegister(c *gin.Context) { c.JSON(http.StatusOK, model.Result{Success: common_err.ERROR, Message: common_err.GetMsg(common_err.ERROR)}) return } + //TODO:创建文件夹 c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS)}) } @@ -266,62 +267,67 @@ func PutUserNick(c *gin.Context) { // @Security ApiKeyAuth // @Success 200 {string} string "ok" // @Router /user/desc [put] -func PutUserChangeDesc(c *gin.Context) { - desc := c.PostForm("description") +func PutUserDesc(c *gin.Context) { + id := c.Param("id") + json := make(map[string]string) + c.BindJSON(&json) + desc := json["description"] if len(desc) == 0 { c.JSON(http.StatusOK, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)}) return } - user_service.SetUser("", "", "", "", desc, "") - data := make(map[string]string, 1) - data["description"] = config.UserInfo.Description - go service.MyService.Casa().PushUserInfo() - c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: data}) -} - -// @Summary Modify user person information (Initialization use) -// @Produce application/json -// @Accept multipart/form-data -// @Tags user -// @Param nick_name formData string false "user nick name" -// @Param description formData string false "Description" -// @Security ApiKeyAuth -// @Success 200 {string} string "ok" -// @Router /user/person/info [post] -func PostUserPersonInfo(c *gin.Context) { - desc := c.PostForm("description") - nickName := c.PostForm("nick_name") - if len(desc) == 0 || len(nickName) == 0 { - c.JSON(http.StatusOK, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)}) + user := service.MyService.User().GetUserInfoById(id) + if user.Id == 0 { + c.JSON(http.StatusOK, + model.Result{Success: common_err.USER_NOT_EXIST, Message: common_err.GetMsg(common_err.USER_NOT_EXIST)}) return } - user_service.SetUser("", "", "", "", desc, nickName) - data := make(map[string]string, 2) - data["description"] = config.UserInfo.Description - data["nick_name"] = config.UserInfo.NickName - go service.MyService.Casa().PushUserInfo() - c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: data}) + user.Description = desc + + service.MyService.User().UpdateUser(user) + + c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: user}) } +// // @Summary Modify user person information (Initialization use) +// // @Produce application/json +// // @Accept multipart/form-data +// // @Tags user +// // @Param nick_name formData string false "user nick name" +// // @Param description formData string false "Description" +// // @Security ApiKeyAuth +// // @Success 200 {string} string "ok" +// // @Router /user/person/info [post] +// func PostUserPersonInfo(c *gin.Context) { +// desc := c.PostForm("description") +// nickName := c.PostForm("nick_name") +// if len(desc) == 0 || len(nickName) == 0 { +// c.JSON(http.StatusOK, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)}) +// return +// } +// user_service.SetUser("", "", "", "", desc, nickName) +// data := make(map[string]string, 2) +// data["description"] = config.UserInfo.Description +// data["nick_name"] = config.UserInfo.NickName +// go service.MyService.Casa().PushUserInfo() +// c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: data}) +// } + // @Summary get user info // @Produce application/json -// @Accept mapplication/json +// @Accept application/json // @Tags user // @Success 200 {string} string "ok" -// @Router /user/info [get] +// @Router /user/info/:id [get] func GetUserInfo(c *gin.Context) { - var u = make(map[string]string, 5) - u["user_name"] = config.UserInfo.UserName - u["head"] = config.UserInfo.Head - u["email"] = config.UserInfo.Email - u["description"] = config.UserInfo.Description - u["nick_name"] = config.UserInfo.NickName + id := c.Param("id") + user := service.MyService.User().GetUserInfoById(id) c.JSON(http.StatusOK, model.Result{ Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), - Data: u, + Data: user, }) } @@ -335,3 +341,21 @@ func GetUserInfo(c *gin.Context) { func GetUserShareID(c *gin.Context) { c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: config.ServerInfo.Token}) } + +// @Summary get user info +// @Produce application/json +// @Accept application/json +// @Tags user +func GetUserAllUserName(c *gin.Context) { + users := service.MyService.User().GetAllUserName() + names := []string{} + for _, v := range users { + names = append(names, v.UserName) + } + c.JSON(http.StatusOK, + model.Result{ + Success: common_err.SUCCESS, + Message: common_err.GetMsg(common_err.SUCCESS), + Data: names, + }) +} diff --git a/service/model/o_user.go b/service/model/o_user.go index 3e4dfc4..d1aa61d 100644 --- a/service/model/o_user.go +++ b/service/model/o_user.go @@ -2,7 +2,7 @@ * @Author: LinkLeong link@icewhale.com * @Date: 2022-05-13 18:15:46 * @LastEditors: LinkLeong - * @LastEditTime: 2022-06-14 14:29:30 + * @LastEditTime: 2022-06-15 16:53:00 * @FilePath: /CasaOS/service/model/o_user.go * @Description: * @Website: https://www.casaos.io @@ -12,13 +12,14 @@ package model //Soon to be removed type UserDBModel struct { - Id int `gorm:"column:id;primary_key" json:"id"` - UserName string `json:"user_name"` - Password string `json:"password omitempty"` - Role string `json:"role"` - Email string `json:"email"` - Avatar string `json:"avatar"` - NickName string `json:"nick_name"` + Id int `gorm:"column:id;primary_key" json:"id"` + UserName string `json:"user_name"` + Password string `json:"password omitempty"` + Role string `json:"role"` + Email string `json:"email"` + Avatar string `json:"avatar"` + NickName string `json:"nick_name"` + Description string `json:"description"` } func (p *UserDBModel) UserDBModel() string { diff --git a/service/user.go b/service/user.go index 068af4d..9abc8b1 100644 --- a/service/user.go +++ b/service/user.go @@ -2,7 +2,7 @@ * @Author: LinkLeong link@icewhale.com * @Date: 2022-03-18 11:40:55 * @LastEditors: LinkLeong - * @LastEditTime: 2022-06-14 14:04:53 + * @LastEditTime: 2022-06-15 17:09:20 * @FilePath: /CasaOS/service/user.go * @Description: * @Website: https://www.casaos.io @@ -28,12 +28,17 @@ type UserService interface { UpdateUser(m model.UserDBModel) GetUserInfoById(id string) (m model.UserDBModel) GetUserInfoByUserName(userName string) (m model.UserDBModel) + GetAllUserName() (list []model.UserDBModel) } type userService struct { db *gorm.DB } +func (u *userService) GetAllUserName() (list []model.UserDBModel) { + u.db.Select("user_name").Find(&list) + return +} func (u *userService) CreateUser(m model.UserDBModel) model.UserDBModel { u.db.Create(&m) return m