mirror of https://github.com/gophish/gophish
25 lines
666 B
Go
25 lines
666 B
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
ctx "github.com/gophish/gophish/context"
|
|
"github.com/gophish/gophish/models"
|
|
"github.com/gophish/gophish/util"
|
|
)
|
|
|
|
// Reset (/api/reset) resets the currently authenticated user's API key
|
|
func (as *Server) Reset(w http.ResponseWriter, r *http.Request) {
|
|
switch {
|
|
case r.Method == "POST":
|
|
u := ctx.Get(r, "user").(models.User)
|
|
u.ApiKey = util.GenerateSecureKey()
|
|
err := models.PutUser(&u)
|
|
if err != nil {
|
|
http.Error(w, "Error setting API Key", http.StatusInternalServerError)
|
|
} else {
|
|
JSONResponse(w, models.Response{Success: true, Message: "API Key successfully reset!", Data: u.ApiKey}, http.StatusOK)
|
|
}
|
|
}
|
|
}
|