github.com/merlinepedra/gopphish-attack@v0.9.0/controllers/api/reset.go (about)

     1  package api
     2  
     3  import (
     4  	"net/http"
     5  
     6  	ctx "github.com/gophish/gophish/context"
     7  	"github.com/gophish/gophish/models"
     8  	"github.com/gophish/gophish/util"
     9  )
    10  
    11  // Reset (/api/reset) resets the currently authenticated user's API key
    12  func (as *Server) Reset(w http.ResponseWriter, r *http.Request) {
    13  	switch {
    14  	case r.Method == "POST":
    15  		u := ctx.Get(r, "user").(models.User)
    16  		u.ApiKey = util.GenerateSecureKey()
    17  		err := models.PutUser(&u)
    18  		if err != nil {
    19  			http.Error(w, "Error setting API Key", http.StatusInternalServerError)
    20  		} else {
    21  			JSONResponse(w, models.Response{Success: true, Message: "API Key successfully reset!", Data: u.ApiKey}, http.StatusOK)
    22  		}
    23  	}
    24  }