42 lines
977 B
Go
42 lines
977 B
Go
package controllers
|
|
|
|
import (
|
|
"encoding/json"
|
|
log "github.com/sirupsen/logrus"
|
|
"io"
|
|
"net/http"
|
|
"pmail/dto"
|
|
"pmail/dto/response"
|
|
"pmail/i18n"
|
|
"pmail/mysql"
|
|
)
|
|
|
|
type modifyPasswordRequest struct {
|
|
Password string `json:"password"`
|
|
}
|
|
|
|
func ModifyPassword(ctx *dto.Context, w http.ResponseWriter, req *http.Request) {
|
|
reqBytes, err := io.ReadAll(req.Body)
|
|
if err != nil {
|
|
log.Errorf("%+v", err)
|
|
}
|
|
var retData modifyPasswordRequest
|
|
err = json.Unmarshal(reqBytes, &retData)
|
|
if err != nil {
|
|
log.Errorf("%+v", err)
|
|
}
|
|
|
|
if retData.Password != "" {
|
|
encodePwd := md5Encode(md5Encode(retData.Password+"pmail") + "pmail2023")
|
|
|
|
_, err := mysql.Instance.Exec(mysql.WithContext(ctx, "update user set password = ? where id =?"), encodePwd, ctx.UserInfo.ID)
|
|
if err != nil {
|
|
response.NewErrorResponse(response.ServerError, i18n.GetText(ctx.Lang, "unknowError"), "").FPrint(w)
|
|
return
|
|
}
|
|
|
|
}
|
|
|
|
response.NewSuccessResponse(i18n.GetText(ctx.Lang, "succ")).FPrint(w)
|
|
}
|