Added check if the wants to change its own password
the build failed
Details
the build failed
Details
This commit is contained in:
parent
434856a44f
commit
bcb8b08001
|
@ -15,8 +15,23 @@ type datPassword struct {
|
||||||
// UserChangePassword is the handler to add a user
|
// UserChangePassword is the handler to add a user
|
||||||
func UserChangePassword(c echo.Context) error {
|
func UserChangePassword(c echo.Context) error {
|
||||||
|
|
||||||
// Check if the user is admin
|
// Get the ID
|
||||||
if !models.IsAdmin(c) {
|
user := c.Param("id")
|
||||||
|
|
||||||
|
if user == "" {
|
||||||
|
return c.JSON(http.StatusBadRequest, models.Message{"User ID cannot be empty."})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make int
|
||||||
|
userID, err := strconv.ParseInt(user, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting user infos."})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Check if the user is admin or itself
|
||||||
|
userJWTinfo, err := models.GetCurrentUser(c)
|
||||||
|
if !models.IsAdmin(c) || userJWTinfo.ID == userID {
|
||||||
return echo.ErrUnauthorized
|
return echo.ErrUnauthorized
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,18 +48,6 @@ func UserChangePassword(c echo.Context) error {
|
||||||
datPw.Password = pwFromString
|
datPw.Password = pwFromString
|
||||||
}
|
}
|
||||||
|
|
||||||
user := c.Param("id")
|
|
||||||
|
|
||||||
if user == "" {
|
|
||||||
return c.JSON(http.StatusBadRequest, models.Message{"User ID cannot be empty."})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make int
|
|
||||||
userID, err := strconv.ParseInt(user, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting user infos."})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get User Infos
|
// Get User Infos
|
||||||
_, exists, err := models.GetUserByID(userID)
|
_, exists, err := models.GetUserByID(userID)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue