fix login oppsie, fix zonefile query to check filename and username, and linting

This commit is contained in:
grumbulon 2023-01-07 00:05:20 -05:00 committed by Gitea
parent da5bd54b3e
commit a3230fbc72
3 changed files with 17 additions and 24 deletions

View file

@ -20,20 +20,7 @@ func Login(w http.ResponseWriter, r *http.Request) {
return
}
w.Header().Set("Content-Type", "application/json")
err := json.NewEncoder(w).Encode(
internal.Response{
Message: "Successfully logged in",
HTTPResponse: 200,
})
if err != nil {
http.Error(w, "internal server error", http.StatusInternalServerError)
return
}
err = r.ParseForm()
err := r.ParseForm()
if err != nil {
http.Error(w, "Unable to parse request", http.StatusInternalServerError)
@ -91,7 +78,6 @@ func Login(w http.ResponseWriter, r *http.Request) {
Name: "jwt", // Must be named "jwt" or else the token cannot be searched for by jwtauth.Verifier.
Value: token,
})
w.Header().Set("Content-Type", "application/json")
err = json.NewEncoder(w).Encode(
internal.Response{
@ -126,7 +112,6 @@ func Logout(w http.ResponseWriter, r *http.Request) {
Message: "Successfully logged out",
HTTPResponse: 200,
})
if err != nil {
http.Error(w, "internal server error", http.StatusInternalServerError)

View file

@ -87,6 +87,7 @@ func NewUser(w http.ResponseWriter, r *http.Request) {
return
}
http.Redirect(w, r, "/", http.StatusSeeOther)
}

View file

@ -69,17 +69,20 @@ func RecieveFile(w http.ResponseWriter, r *http.Request) {
}
db.Create(
&ZoneRequest{User: claims["username"].(string),
&ZoneRequest{
User: claims["username"].(string),
Zone: &Zone{
FileName: fmt.Sprintf("tmpfile-%s-%s", name[0], claims["username"].(string)),
RawFileName: name[0],
}})
},
})
buf.Reset()
}
func ZoneFiles(w http.ResponseWriter, r *http.Request) {
var result internal.ZoneRequest
_, claims, _ := jwtauth.FromContext(r.Context())
err := r.ParseForm()
@ -104,22 +107,26 @@ func ZoneFiles(w http.ResponseWriter, r *http.Request) {
return
}
db.Where("raw_file_name = ?", filename).First(&result)
log.Println(result.RawFileName)
if result.RawFileName == "" {
db.Where(ZoneRequest{
Zone: &Zone{
RawFileName: filename,
},
User: claims["username"].(string),
}).First(&result)
if result == (internal.ZoneRequest{}) {
http.Error(w, "Internal server error", http.StatusInternalServerError)
return
}
zoneFile := newZoneRequest(result.RawFileName, claims["username"].(string))
log.Println(zoneFile.FileName)
if err := zoneFile.Parse(); err != nil {
http.Error(w, "Unable to parse zonefile", http.StatusInternalServerError)
return
}
}
func newZoneRequest(filename string, user string) *ZoneRequest {
@ -141,7 +148,7 @@ func newZoneRequest(filename string, user string) *ZoneRequest {
// Parse will be used to parse zonefiles.
func (zone *ZoneRequest) Parse() error {
zp := dns.NewZoneParser(strings.NewReader(zone.Body), "", "")
log.Println(zone.Body)
for rr, ok := zp.Next(); ok; rr, ok = zp.Next() {
log.Println(rr)
}