mirror of
https://github.com/mattermost/focalboard.git
synced 2024-12-24 13:43:12 +02:00
417de9f837
- structured, asynchronous logging - supports discreet log levels, including custom levels - supports output to console, files, and all common log aggregators. - supports JSON, plain text and GELF formats - lazy formatting and writing
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/gorilla/mux"
|
|
"github.com/mattermost/focalboard/server/services/mlog"
|
|
)
|
|
|
|
type AdminSetPasswordData struct {
|
|
Password string `json:"password"`
|
|
}
|
|
|
|
func (a *API) handleAdminSetPassword(w http.ResponseWriter, r *http.Request) {
|
|
vars := mux.Vars(r)
|
|
username := vars["username"]
|
|
|
|
requestBody, err := ioutil.ReadAll(r.Body)
|
|
if err != nil {
|
|
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
|
return
|
|
}
|
|
|
|
var requestData AdminSetPasswordData
|
|
err = json.Unmarshal(requestBody, &requestData)
|
|
if err != nil {
|
|
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
|
return
|
|
}
|
|
|
|
if !strings.Contains(requestData.Password, "") {
|
|
a.errorResponse(w, http.StatusBadRequest, "password is required", err)
|
|
return
|
|
}
|
|
|
|
err = a.app().UpdateUserPassword(username, requestData.Password)
|
|
if err != nil {
|
|
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
|
return
|
|
}
|
|
|
|
a.logger.Debug("AdminSetPassword, username: %s", mlog.String("username", username))
|
|
|
|
jsonStringResponse(w, http.StatusOK, "{}")
|
|
}
|