|
@@ -1,225 +1,281 @@
|
|
|
package v1
|
|
|
|
|
|
import (
|
|
|
- "fmt"
|
|
|
+ json2 "encoding/json"
|
|
|
+ "io/ioutil"
|
|
|
"net/http"
|
|
|
+ url2 "net/url"
|
|
|
+ "os"
|
|
|
+ "path"
|
|
|
+ "path/filepath"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
|
|
|
"github.com/IceWhaleTech/CasaOS/model"
|
|
|
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
|
|
- jwt2 "github.com/IceWhaleTech/CasaOS/pkg/utils/jwt"
|
|
|
- oasis_err2 "github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err"
|
|
|
- "github.com/IceWhaleTech/CasaOS/service"
|
|
|
+ "github.com/IceWhaleTech/CasaOS/pkg/utils/common_err"
|
|
|
+ "github.com/IceWhaleTech/CasaOS/pkg/utils/encryption"
|
|
|
+ "github.com/IceWhaleTech/CasaOS/pkg/utils/file"
|
|
|
+ "github.com/IceWhaleTech/CasaOS/pkg/utils/jwt"
|
|
|
+ model2 "github.com/IceWhaleTech/CasaOS/service/model"
|
|
|
"github.com/IceWhaleTech/CasaOS/types"
|
|
|
+ "github.com/tidwall/gjson"
|
|
|
+
|
|
|
+ "github.com/IceWhaleTech/CasaOS/service"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
)
|
|
|
|
|
|
-var user_service service.UserService
|
|
|
-
|
|
|
-func init() {
|
|
|
- user_service = service.NewUserService()
|
|
|
-}
|
|
|
+// @Summary register user
|
|
|
+// @Router /user/register/ [post]
|
|
|
+func PostUserRegister(c *gin.Context) {
|
|
|
+ json := make(map[string]string)
|
|
|
+ c.BindJSON(&json)
|
|
|
+ username := json["user_name"]
|
|
|
+ pwd := json["password"]
|
|
|
+ key := c.Param("key")
|
|
|
+ if _, ok := service.UserRegisterHash[key]; !ok {
|
|
|
+ c.JSON(http.StatusOK,
|
|
|
+ model.Result{Success: common_err.KEY_NOT_EXIST, Message: common_err.GetMsg(common_err.KEY_NOT_EXIST)})
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
-// @Summary 设置用户名和密码
|
|
|
-// @Produce application/json
|
|
|
-// @Accept multipart/form-data
|
|
|
-// @Tags user
|
|
|
-// @Param username formData string true "User name"
|
|
|
-// @Param pwd formData string true "password"
|
|
|
-// @Security ApiKeyAuth
|
|
|
-// @Success 200 {string} string "ok"
|
|
|
-// @Router /user/setusernamepwd [post]
|
|
|
-func Set_Name_Pwd(c *gin.Context) {
|
|
|
- //json := make(map[string]string)
|
|
|
- //c.BindJSON(&json)
|
|
|
- username := c.PostForm("username")
|
|
|
- pwd := c.PostForm("pwd")
|
|
|
- //老用户名是否存在即新用户名和密码的验证
|
|
|
- if config.UserInfo.Initialized || len(username) == 0 || len(pwd) == 0 {
|
|
|
+ if len(username) == 0 || len(pwd) == 0 {
|
|
|
c.JSON(http.StatusOK,
|
|
|
- model.Result{Success: oasis_err2.ERROR, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
|
|
|
+ model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
|
|
|
return
|
|
|
}
|
|
|
- //开始设置
|
|
|
- err := user_service.SetUser(username, pwd, "", "", "", "")
|
|
|
- if err != nil {
|
|
|
- c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: fmt.Sprintf("%v", err)})
|
|
|
+ if len(pwd) < 6 {
|
|
|
+ c.JSON(http.StatusOK,
|
|
|
+ model.Result{Success: common_err.PWD_IS_TOO_SIMPLE, Message: common_err.GetMsg(common_err.PWD_IS_TOO_SIMPLE)})
|
|
|
return
|
|
|
- } else {
|
|
|
- c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)})
|
|
|
+ }
|
|
|
+ oldUser := service.MyService.User().GetUserInfoByUserName(username)
|
|
|
+ if oldUser.Id > 0 {
|
|
|
+ c.JSON(http.StatusOK,
|
|
|
+ model.Result{Success: common_err.USER_EXIST, Message: common_err.GetMsg(common_err.USER_EXIST)})
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+ user := model2.UserDBModel{}
|
|
|
+ user.UserName = username
|
|
|
+ user.Password = encryption.GetMD5ByStr(config.UserInfo.PWD)
|
|
|
+ user.Role = "admin"
|
|
|
+
|
|
|
+ user = service.MyService.User().CreateUser(user)
|
|
|
+ if user.Id == 0 {
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.ERROR, Message: common_err.GetMsg(common_err.ERROR)})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ file.MkDir(config.AppInfo.UserDataPath + "/" + strconv.Itoa(user.Id))
|
|
|
+ delete(service.UserRegisterHash, key)
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS)})
|
|
|
+
|
|
|
}
|
|
|
|
|
|
-// @Summary 登录
|
|
|
+// @Summary login
|
|
|
// @Produce application/json
|
|
|
-// @Accept multipart/form-data
|
|
|
+// @Accept application/json
|
|
|
// @Tags user
|
|
|
-// @Param username formData string true "User name"
|
|
|
-// @Param pwd formData string true "password"
|
|
|
+// @Param user_name query string true "User name"
|
|
|
+// @Param pwd query string true "password"
|
|
|
// @Success 200 {string} string "ok"
|
|
|
// @Router /user/login [post]
|
|
|
-func Login(c *gin.Context) {
|
|
|
- username := c.PostForm("username")
|
|
|
- pwd := c.PostForm("pwd")
|
|
|
- //检查参数是否正确
|
|
|
+func PostUserLogin(c *gin.Context) {
|
|
|
+ json := make(map[string]string)
|
|
|
+ c.BindJSON(&json)
|
|
|
+
|
|
|
+ username := json["username"]
|
|
|
+ pwd := json["pwd"]
|
|
|
+ //check params is empty
|
|
|
if len(username) == 0 || len(pwd) == 0 {
|
|
|
c.JSON(http.StatusOK,
|
|
|
model.Result{
|
|
|
- Success: oasis_err2.ERROR,
|
|
|
- Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS),
|
|
|
+ Success: common_err.ERROR,
|
|
|
+ Message: common_err.GetMsg(common_err.INVALID_PARAMS),
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
- if config.UserInfo.UserName == username && config.UserInfo.PWD == pwd {
|
|
|
- //if username == "admin" && pwd == "admin" {
|
|
|
-
|
|
|
- data := make(map[string]string, 2)
|
|
|
- data["token"] = jwt2.GetToken(username, pwd)
|
|
|
- data["version"] = types.CURRENTVERSION
|
|
|
- //user_service.SetUser("", "", token, "", "")
|
|
|
+ user := service.MyService.User().GetUserAllInfoByName(username)
|
|
|
+ if user.Id == 0 {
|
|
|
c.JSON(http.StatusOK,
|
|
|
- model.Result{
|
|
|
- Success: oasis_err2.SUCCESS,
|
|
|
- Message: oasis_err2.GetMsg(oasis_err2.SUCCESS),
|
|
|
- Data: data,
|
|
|
- })
|
|
|
+ model.Result{Success: common_err.USER_NOT_EXIST, Message: common_err.GetMsg(common_err.USER_NOT_EXIST)})
|
|
|
return
|
|
|
}
|
|
|
+ if user.Password != encryption.GetMD5ByStr(pwd) {
|
|
|
+ c.JSON(http.StatusOK,
|
|
|
+ model.Result{Success: common_err.PWD_INVALID, Message: common_err.GetMsg(common_err.PWD_INVALID)})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ user.Password = ""
|
|
|
+ // token := system_model.VerifyInformation{}
|
|
|
+ // token.AccessToken = jwt.GetAccessToken(user.UserName, user.Password, user.Id)
|
|
|
+ // token.RefreshToken = jwt.GetRefreshToken(user.UserName, user.Password, user.Id)
|
|
|
+ // token.ExpiresAt = time.Now().Add(3 * time.Hour * time.Duration(1)).Unix()
|
|
|
+ // data := make(map[string]interface{}, 2)
|
|
|
+ // data["token"] = token
|
|
|
+ // data["user"] = user
|
|
|
+ data := make(map[string]interface{}, 3)
|
|
|
+ data["token"] = jwt.GetToken(username, pwd)
|
|
|
+ data["version"] = types.CURRENTVERSION
|
|
|
+ data["user"] = user
|
|
|
+
|
|
|
c.JSON(http.StatusOK,
|
|
|
model.Result{
|
|
|
- Success: oasis_err2.ERROR,
|
|
|
- Message: oasis_err2.GetMsg(oasis_err2.ERROR),
|
|
|
+ Success: common_err.SUCCESS,
|
|
|
+ Message: common_err.GetMsg(common_err.SUCCESS),
|
|
|
+ Data: data,
|
|
|
})
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-// @Summary 修改头像
|
|
|
+// @Summary edit user head
|
|
|
// @Produce application/json
|
|
|
// @Accept multipart/form-data
|
|
|
// @Tags user
|
|
|
// @Param file formData file true "用户头像"
|
|
|
// @Security ApiKeyAuth
|
|
|
// @Success 200 {string} string "ok"
|
|
|
-// @Router /user/changhead [post]
|
|
|
-func PostUserHead(c *gin.Context) {
|
|
|
- file, _, _ := c.Request.FormFile("file")
|
|
|
- user_service.UpLoadFile(file, config.UserInfo.Head)
|
|
|
+// @Router /user/avatar [put]
|
|
|
+func PutUserAvatar(c *gin.Context) {
|
|
|
+ id := c.GetHeader("user_id")
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ f, err := c.FormFile("file")
|
|
|
+ if err != nil {
|
|
|
+ c.JSON(http.StatusOK,
|
|
|
+ model.Result{Success: common_err.ERROR, Message: common_err.GetMsg(common_err.ERROR), Data: err.Error()})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(user.Avatar) > 0 {
|
|
|
+ os.RemoveAll(config.AppInfo.UserDataPath + "/" + id + "/" + user.Avatar)
|
|
|
+ }
|
|
|
+ ext := filepath.Ext(f.Filename)
|
|
|
+ avatarPath := config.AppInfo.UserDataPath + "/" + id + "/avatar" + ext
|
|
|
+ c.SaveUploadedFile(f, avatarPath)
|
|
|
+ user.Avatar = avatarPath
|
|
|
+ service.MyService.User().UpdateUser(user)
|
|
|
c.JSON(http.StatusOK,
|
|
|
model.Result{
|
|
|
- Success: oasis_err2.SUCCESS,
|
|
|
- Message: oasis_err2.GetMsg(oasis_err2.SUCCESS),
|
|
|
- Data: config.UserInfo.Head,
|
|
|
+ Success: common_err.SUCCESS,
|
|
|
+ Message: common_err.GetMsg(common_err.SUCCESS),
|
|
|
+ Data: user,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-// @Summary 修改用户名
|
|
|
+/**
|
|
|
+ * @description: get user avatar by user id
|
|
|
+ * @param {query} id string user id
|
|
|
+ * @method: GET
|
|
|
+ */
|
|
|
+func GetUserAvatar(c *gin.Context) {
|
|
|
+ id := c.Param("id")
|
|
|
+ user := service.MyService.User().GetUserInfoById(id)
|
|
|
+
|
|
|
+ path := "default.png"
|
|
|
+ if user.Id > 0 {
|
|
|
+ path = user.Avatar
|
|
|
+ }
|
|
|
+ c.File(path)
|
|
|
+}
|
|
|
+
|
|
|
+// @Summary edit user name
|
|
|
// @Produce application/json
|
|
|
-// @Accept multipart/form-data
|
|
|
+// @Accept application/json
|
|
|
// @Tags user
|
|
|
-// @Param username formData string true "User name"
|
|
|
-// @Param oldname formData string true "Old user name"
|
|
|
+// @Param old_name query string true "Old user name"
|
|
|
// @Security ApiKeyAuth
|
|
|
// @Success 200 {string} string "ok"
|
|
|
-// @Router /user/username [put]
|
|
|
+// @Router /user/name/:id [put]
|
|
|
func PutUserName(c *gin.Context) {
|
|
|
- if config.ServerInfo.LockAccount {
|
|
|
- c.JSON(http.StatusOK, model.Result{Success: oasis_err2.ACCOUNT_LOCK, Message: oasis_err2.GetMsg(oasis_err2.ACCOUNT_LOCK)})
|
|
|
+ //id := c.GetHeader("user_id")
|
|
|
+ json := make(map[string]string)
|
|
|
+ c.BindJSON(&json)
|
|
|
+ //userName := json["user_name"]
|
|
|
+ username := json["username"]
|
|
|
+ id := json["id"]
|
|
|
+ if len(username) == 0 {
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.ERROR, Message: common_err.GetMsg(common_err.ERROR)})
|
|
|
return
|
|
|
}
|
|
|
- oldname := c.PostForm("oldname")
|
|
|
- username := c.PostForm("username")
|
|
|
- if len(username) == 0 || config.UserInfo.UserName != oldname {
|
|
|
- c.JSON(http.StatusOK, model.Result{Success: oasis_err2.ERROR, Message: oasis_err2.GetMsg(oasis_err2.ERROR)})
|
|
|
+ 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(username, "", "", "", "", "")
|
|
|
- c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)})
|
|
|
+ user.UserName = username
|
|
|
+ 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 修改密码
|
|
|
+// @Summary edit user password
|
|
|
// @Produce application/json
|
|
|
-// @Accept multipart/form-data
|
|
|
+// @Accept application/json
|
|
|
// @Tags user
|
|
|
-// @Param pwd formData string true "Password"
|
|
|
-// @Param old_pwd formData string true "Old password"
|
|
|
// @Security ApiKeyAuth
|
|
|
// @Success 200 {string} string "ok"
|
|
|
-// @Router /user/password [put]
|
|
|
+// @Router /user/password/:id [put]
|
|
|
func PutUserPwd(c *gin.Context) {
|
|
|
- oldPwd := c.PostForm("old_pwd")
|
|
|
- pwd := c.PostForm("pwd")
|
|
|
- if config.UserInfo.PWD != oldPwd {
|
|
|
- c.JSON(http.StatusOK, model.Result{Success: oasis_err2.PWD_INVALID_OLD, Message: oasis_err2.GetMsg(oasis_err2.PWD_INVALID_OLD)})
|
|
|
+ //id := c.GetHeader("user_id")
|
|
|
+ json := make(map[string]string)
|
|
|
+ c.BindJSON(&json)
|
|
|
+ oldPwd := json["old_pwd"]
|
|
|
+ pwd := json["pwd"]
|
|
|
+ id := json["id"]
|
|
|
+ if len(oldPwd) == 0 || len(pwd) == 0 {
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
|
|
|
return
|
|
|
}
|
|
|
- if config.ServerInfo.LockAccount {
|
|
|
- c.JSON(http.StatusOK, model.Result{Success: oasis_err2.ACCOUNT_LOCK, Message: oasis_err2.GetMsg(oasis_err2.ACCOUNT_LOCK)})
|
|
|
+ user := service.MyService.User().GetUserAllInfoById(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
|
|
|
}
|
|
|
- if len(pwd) == 0 {
|
|
|
- c.JSON(http.StatusOK, model.Result{Success: oasis_err2.PWD_IS_EMPTY, Message: oasis_err2.GetMsg(oasis_err2.PWD_IS_EMPTY)})
|
|
|
+ if user.Password != encryption.GetMD5ByStr(oldPwd) {
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.PWD_INVALID_OLD, Message: common_err.GetMsg(common_err.PWD_INVALID_OLD)})
|
|
|
return
|
|
|
}
|
|
|
- user_service.SetUser("", pwd, "", "", "", "")
|
|
|
- c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)})
|
|
|
-}
|
|
|
-
|
|
|
-// @Summary edit user info
|
|
|
-// @Produce application/json
|
|
|
-// @Accept multipart/form-data
|
|
|
-// @Tags user
|
|
|
-// @Param user_name formData string false "User Name"
|
|
|
-// @Param email formData string false "Email"
|
|
|
-// @Param description formData string false "Description"
|
|
|
-// @Param pwd formData string false "Password"
|
|
|
-// @Param old_pwd formData string false "Old password"
|
|
|
-// @Param nick_name formData string false "nick name"
|
|
|
-// @Security ApiKeyAuth
|
|
|
-// @Success 200 {string} string "ok"
|
|
|
-// @Router /user/info [post]
|
|
|
-func PostUserChangeInfo(c *gin.Context) {
|
|
|
- username := c.PostForm("user_name")
|
|
|
- email := c.PostForm("email")
|
|
|
- description := c.PostForm("description")
|
|
|
- nickName := c.PostForm("nick_name")
|
|
|
- oldpwd := c.PostForm("old_pwd")
|
|
|
- pwd := c.PostForm("pwd")
|
|
|
- if len(pwd) > 0 && config.UserInfo.PWD != oldpwd {
|
|
|
- c.JSON(http.StatusOK, model.Result{Success: oasis_err2.PWD_INVALID, Message: oasis_err2.GetMsg(oasis_err2.PWD_INVALID)})
|
|
|
- return
|
|
|
- }
|
|
|
- user_service.SetUser(username, pwd, "", email, description, nickName)
|
|
|
- data := make(map[string]string, 4)
|
|
|
-
|
|
|
- data["token"] = jwt2.GetToken(username, pwd)
|
|
|
- data["user_name"] = username
|
|
|
- data["head"] = config.UserInfo.Head
|
|
|
- data["nick_name"] = config.UserInfo.NickName
|
|
|
- c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS), Data: data})
|
|
|
+ user.Password = encryption.GetMD5ByStr(pwd)
|
|
|
+ service.MyService.User().UpdateUserPassword(user)
|
|
|
+ user.Password = ""
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: user})
|
|
|
}
|
|
|
|
|
|
// @Summary edit user nick
|
|
|
// @Produce application/json
|
|
|
-// @Accept multipart/form-data
|
|
|
+// @Accept application/json
|
|
|
// @Tags user
|
|
|
-// @Param nick_name formData string false "nick name"
|
|
|
+// @Param nick_name query string false "nick name"
|
|
|
// @Security ApiKeyAuth
|
|
|
// @Success 200 {string} string "ok"
|
|
|
// @Router /user/nick [put]
|
|
|
-func PutUserChangeNick(c *gin.Context) {
|
|
|
-
|
|
|
- nickName := c.PostForm("nick_name")
|
|
|
+func PutUserNick(c *gin.Context) {
|
|
|
|
|
|
+ //id := c.GetHeader("user_id")
|
|
|
+ json := make(map[string]string)
|
|
|
+ c.BindJSON(&json)
|
|
|
+ nickName := json["nick_name"]
|
|
|
+ id := json["id"]
|
|
|
if len(nickName) == 0 {
|
|
|
- c.JSON(http.StatusOK, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
|
|
|
return
|
|
|
}
|
|
|
- user_service.SetUser("", "", "", "", "", nickName)
|
|
|
- data := make(map[string]string, 1)
|
|
|
- data["nick_name"] = config.UserInfo.NickName
|
|
|
+ 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.NickName = nickName
|
|
|
+ service.MyService.User().UpdateUser(user)
|
|
|
+ //TODO:person remove together
|
|
|
go service.MyService.Casa().PushUserInfo()
|
|
|
- c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS), Data: data})
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: user})
|
|
|
}
|
|
|
|
|
|
// @Summary edit user description
|
|
@@ -230,18 +286,27 @@ func PutUserChangeNick(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.GetHeader("user_id")
|
|
|
+ json := make(map[string]string)
|
|
|
+ c.BindJSON(&json)
|
|
|
+ id := json["id"]
|
|
|
+ desc := json["description"]
|
|
|
if len(desc) == 0 {
|
|
|
- c.JSON(http.StatusOK, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
|
|
|
+ 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: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS), Data: data})
|
|
|
+ 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.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)
|
|
@@ -257,38 +322,76 @@ 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: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
|
|
|
+ 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)
|
|
|
+ //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: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS), Data: data})
|
|
|
+ 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) {
|
|
|
+ //id := c.GetHeader("user_id")
|
|
|
+ id := c.Param("id")
|
|
|
+ user := service.MyService.User().GetUserInfoById(id)
|
|
|
+
|
|
|
+ //*****
|
|
|
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
|
|
|
+ u["user_name"] = user.UserName
|
|
|
+ u["head"] = user.Avatar
|
|
|
+ u["email"] = user.Email
|
|
|
+ u["description"] = user.NickName
|
|
|
+ u["nick_name"] = user.NickName
|
|
|
+ u["id"] = strconv.Itoa(user.Id)
|
|
|
+
|
|
|
+ //**
|
|
|
+
|
|
|
c.JSON(http.StatusOK,
|
|
|
model.Result{
|
|
|
- Success: oasis_err2.SUCCESS,
|
|
|
- Message: oasis_err2.GetMsg(oasis_err2.SUCCESS),
|
|
|
+ Success: common_err.SUCCESS,
|
|
|
+ Message: common_err.GetMsg(common_err.SUCCESS),
|
|
|
Data: u,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+// @Summary get user info
|
|
|
+// @Produce application/json
|
|
|
+// @Accept application/json
|
|
|
+// @Tags user
|
|
|
+// @Success 200 {string} string "ok"
|
|
|
+// @Router /user/info [get]
|
|
|
+func GetUserInfoByUserName(c *gin.Context) {
|
|
|
+ json := make(map[string]string)
|
|
|
+ c.BindJSON(&json)
|
|
|
+ userName := json["user_name"]
|
|
|
+ if len(userName) == 0 {
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ user := service.MyService.User().GetUserInfoByUserName(userName)
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ //**
|
|
|
+
|
|
|
+ c.JSON(http.StatusOK,
|
|
|
+ model.Result{
|
|
|
+ Success: common_err.SUCCESS,
|
|
|
+ Message: common_err.GetMsg(common_err.SUCCESS),
|
|
|
+ Data: user,
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
// @Summary Get my shareId
|
|
|
// @Produce application/json
|
|
|
// @Accept application/json
|
|
@@ -297,5 +400,327 @@ func GetUserInfo(c *gin.Context) {
|
|
|
// @Success 200 {string} string "ok"
|
|
|
// @Router /user/shareid [get]
|
|
|
func GetUserShareID(c *gin.Context) {
|
|
|
- c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS), Data: config.ServerInfo.Token})
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: config.ServerInfo.Token})
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description: get all user name
|
|
|
+ * @method:GET
|
|
|
+ * @router:/user/all/name
|
|
|
+ */
|
|
|
+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,
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description:get custom file by user
|
|
|
+ * @param {path} name string "file name"
|
|
|
+ * @method: GET
|
|
|
+ * @router: /user/custom/:key
|
|
|
+ */
|
|
|
+func GetUserCustomConf(c *gin.Context) {
|
|
|
+ name := c.Param("key")
|
|
|
+ if len(name) == 0 {
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //id := c.GetHeader("user_id")
|
|
|
+ id := c.Param("id")
|
|
|
+ user := service.MyService.User().GetUserInfoById(id)
|
|
|
+ // user := service.MyService.User().GetUserInfoByUserName(userName)
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ filePath := config.AppInfo.UserDataPath + "/" + id + "/" + name + ".json"
|
|
|
+ data := file.ReadFullFile(filePath)
|
|
|
+ if !gjson.ValidBytes(data) {
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: string(data)})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: json2.RawMessage(string(data))})
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description:create or update custom conf by user
|
|
|
+ * @param {path} name string "file name"
|
|
|
+ * @method:POST
|
|
|
+ * @router:/user/custom/:key
|
|
|
+ */
|
|
|
+func PostUserCustomConf(c *gin.Context) {
|
|
|
+ name := c.Param("key")
|
|
|
+ if len(name) == 0 {
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //id := c.GetHeader("user_id")
|
|
|
+ id := c.Param("id")
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ data, _ := ioutil.ReadAll(c.Request.Body)
|
|
|
+ filePath := config.AppInfo.UserDataPath + "/" + strconv.Itoa(user.Id)
|
|
|
+
|
|
|
+ file.WriteToPath(data, filePath, name+".json")
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: json2.RawMessage(string(data))})
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description: delete user custom config
|
|
|
+ * @param {path} key string
|
|
|
+ * @method:delete
|
|
|
+ * @router:/user/custom/:key
|
|
|
+ */
|
|
|
+func DeleteUserCustomConf(c *gin.Context) {
|
|
|
+ name := c.Param("key")
|
|
|
+ if len(name) == 0 {
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //id := c.GetHeader("user_id")
|
|
|
+ id := c.Param("id")
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ filePath := config.AppInfo.UserDataPath + "/" + strconv.Itoa(user.Id) + "/" + name + ".json"
|
|
|
+ os.Remove(filePath)
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS)})
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description:
|
|
|
+ * @param {path} id string "user id"
|
|
|
+ * @method:DELETE
|
|
|
+ * @router:/user/delete/:id
|
|
|
+ */
|
|
|
+func DeleteUser(c *gin.Context) {
|
|
|
+ id := c.Param("id")
|
|
|
+ service.MyService.User().DeleteUserById(id)
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: id})
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description:update user image
|
|
|
+ * @method:POST
|
|
|
+ * @router:/user/file/image/:key
|
|
|
+ */
|
|
|
+func PostUserFileImage(c *gin.Context) {
|
|
|
+ //id := c.GetHeader("user_id")
|
|
|
+ id := c.Param("id")
|
|
|
+ json := make(map[string]string)
|
|
|
+ c.BindJSON(&json)
|
|
|
+
|
|
|
+ path := json["path"]
|
|
|
+ key := c.Param("key")
|
|
|
+ if len(path) == 0 || len(key) == 0 {
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if !file.Exists(path) {
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.FILE_DOES_NOT_EXIST, Message: common_err.GetMsg(common_err.FILE_DOES_NOT_EXIST)})
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ _, err := file.GetImageExt(path)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.NOT_IMAGE, Message: common_err.GetMsg(common_err.NOT_IMAGE)})
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ fstat, _ := os.Stat(path)
|
|
|
+ if fstat.Size() > 10<<20 {
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.IMAGE_TOO_LARGE, Message: common_err.GetMsg(common_err.IMAGE_TOO_LARGE)})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ext := file.GetExt(path)
|
|
|
+ filePath := config.AppInfo.UserDataPath + "/" + strconv.Itoa(user.Id) + "/" + key + ext
|
|
|
+ file.CopySingleFile(path, filePath, "overwrite")
|
|
|
+
|
|
|
+ data := make(map[string]string, 3)
|
|
|
+ data["path"] = filePath
|
|
|
+ data["file_name"] = key + ext
|
|
|
+ data["online_path"] = "/v1/user/image?path=" + filePath
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: data})
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description:create or update user's custom image
|
|
|
+ * @param {formData} file file "a file to be uploaded"
|
|
|
+ * @param {path} key string "file name"
|
|
|
+ * @method:POST
|
|
|
+ * @router:/user/upload/image/:key
|
|
|
+ */
|
|
|
+func PostUserUploadImage(c *gin.Context) {
|
|
|
+ //id := c.GetHeader("user_id")
|
|
|
+ id := c.Param("id")
|
|
|
+ f, err := c.FormFile("file")
|
|
|
+ key := c.Param("key")
|
|
|
+ if len(key) == 0 {
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if err != nil {
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.ERROR, Message: common_err.GetMsg(common_err.ERROR), Data: err.Error()})
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ _, err = file.GetImageExtByName(f.Filename)
|
|
|
+ if err != nil {
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.NOT_IMAGE, Message: common_err.GetMsg(common_err.NOT_IMAGE)})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ext := filepath.Ext(f.Filename)
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ path := config.AppInfo.UserDataPath + "/" + strconv.Itoa(user.Id) + "/" + key + ext
|
|
|
+ c.SaveUploadedFile(f, path)
|
|
|
+ data := make(map[string]string, 3)
|
|
|
+ data["path"] = path
|
|
|
+ data["file_name"] = key + ext
|
|
|
+ data["online_path"] = "/v1/user/image?path=" + path
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: data})
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description: get current user's image
|
|
|
+ * @method:GET
|
|
|
+ * @router:/user/image/:id
|
|
|
+ */
|
|
|
+func GetUserImage(c *gin.Context) {
|
|
|
+ filePath := c.Query("path")
|
|
|
+ if len(filePath) == 0 {
|
|
|
+ c.JSON(http.StatusNotFound, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if !file.Exists(filePath) {
|
|
|
+ c.JSON(http.StatusNotFound, model.Result{Success: common_err.FILE_DOES_NOT_EXIST, Message: common_err.GetMsg(common_err.FILE_DOES_NOT_EXIST)})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if !strings.Contains(filePath, config.AppInfo.UserDataPath) {
|
|
|
+ c.JSON(http.StatusNotFound, model.Result{Success: common_err.INSUFFICIENT_PERMISSIONS, Message: common_err.GetMsg(common_err.INSUFFICIENT_PERMISSIONS)})
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ fileTmp, _ := os.Open(filePath)
|
|
|
+ defer fileTmp.Close()
|
|
|
+
|
|
|
+ fileName := path.Base(filePath)
|
|
|
+ c.Header("Content-Disposition", "attachment; filename*=utf-8''"+url2.PathEscape(fileName))
|
|
|
+ c.File(filePath)
|
|
|
+}
|
|
|
+func DeleteUserImage(c *gin.Context) {
|
|
|
+ // id := c.GetHeader("user_id")
|
|
|
+ id := c.Param("id")
|
|
|
+ path := c.Query("path")
|
|
|
+ if len(path) == 0 {
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ if !file.Exists(path) {
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.FILE_DOES_NOT_EXIST, Message: common_err.GetMsg(common_err.FILE_DOES_NOT_EXIST)})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if !strings.Contains(path, config.AppInfo.UserDataPath+"/"+strconv.Itoa(user.Id)) {
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.INSUFFICIENT_PERMISSIONS, Message: common_err.GetMsg(common_err.INSUFFICIENT_PERMISSIONS)})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ os.Remove(path)
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS)})
|
|
|
+}
|
|
|
+
|
|
|
+////refresh token
|
|
|
+// func PostUserRefreshToken(c *gin.Context) {
|
|
|
+// json := make(map[string]string)
|
|
|
+// c.BindJSON(&json)
|
|
|
+// 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()})
|
|
|
+// return
|
|
|
+// }
|
|
|
+// if claims.VerifyExpiresAt(time.Now(), true) || claims.VerifyIssuer("refresh", true) {
|
|
|
+// c.JSON(http.StatusOK, model.Result{Success: common_err.VERIFICATION_FAILURE, Message: common_err.GetMsg(common_err.VERIFICATION_FAILURE)})
|
|
|
+// return
|
|
|
+// }
|
|
|
+// newToken := jwt.GetAccessToken(claims.UserName, claims.PassWord, claims.Id)
|
|
|
+// if err != nil {
|
|
|
+// c.JSON(http.StatusOK, model.Result{Success: common_err.ERROR, Message: common_err.GetMsg(common_err.ERROR), Data: err.Error()})
|
|
|
+// return
|
|
|
+// }
|
|
|
+// verifyInfo := system_model.VerifyInformation{}
|
|
|
+// verifyInfo.AccessToken = newToken
|
|
|
+// verifyInfo.RefreshToken = jwt.GetRefreshToken(claims.UserName, claims.PassWord, claims.Id)
|
|
|
+// verifyInfo.ExpiresAt = time.Now().Add(3 * time.Hour * time.Duration(1)).Unix()
|
|
|
+
|
|
|
+// c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: verifyInfo})
|
|
|
+
|
|
|
+// }
|
|
|
+
|
|
|
+//******** soon to be removed ********
|
|
|
+
|
|
|
+// @Summary 设置用户名和密码
|
|
|
+// @Produce application/json
|
|
|
+// @Accept multipart/form-data
|
|
|
+// @Tags user
|
|
|
+// @Param username formData string true "User name"
|
|
|
+// @Param pwd formData string true "password"
|
|
|
+// @Security ApiKeyAuth
|
|
|
+// @Success 200 {string} string "ok"
|
|
|
+// @Router /user/setusernamepwd [post]
|
|
|
+func Set_Name_Pwd(c *gin.Context) {
|
|
|
+ json := make(map[string]string)
|
|
|
+ c.BindJSON(&json)
|
|
|
+ username := json["username"]
|
|
|
+ pwd := json["pwd"]
|
|
|
+ if service.MyService.User().GetUserCount() > 0 || len(username) == 0 || len(pwd) == 0 {
|
|
|
+ c.JSON(http.StatusOK,
|
|
|
+ model.Result{Success: common_err.ERROR, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ user := model2.UserDBModel{}
|
|
|
+ user.UserName = username
|
|
|
+ user.Password = encryption.GetMD5ByStr(config.UserInfo.PWD)
|
|
|
+ user.Role = "admin"
|
|
|
+
|
|
|
+ user = service.MyService.User().CreateUser(user)
|
|
|
+ if user.Id == 0 {
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.ERROR, Message: common_err.GetMsg(common_err.ERROR)})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ file.MkDir(config.AppInfo.UserDataPath + "/" + strconv.Itoa(user.Id))
|
|
|
+
|
|
|
+ c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: user})
|
|
|
+
|
|
|
}
|