mirror of
https://git.freecumextremist.com/grumbulon/pomme.git
synced 2024-11-22 10:23:46 +00:00
fix login oppsie, fix zonefile query to check filename and username, and linting
This commit is contained in:
parent
da5bd54b3e
commit
a3230fbc72
3 changed files with 17 additions and 24 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -87,6 +87,7 @@ func NewUser(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue