Added request rejection page
This commit is contained in:
parent
a46fd988f5
commit
e30cc95b08
|
@ -0,0 +1,17 @@
|
||||||
|
{{ template "base.html" . }}
|
||||||
|
|
||||||
|
{{ define "content" }}
|
||||||
|
<div class="description">
|
||||||
|
<p>
|
||||||
|
<span class="big">Hi there, {{ if .User }}{{ .User.Name }}{{ else }}visitor{{ end }}!</span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<span class="big">Your request was rejected for the following reason:</span><br />
|
||||||
|
<p class="b">{{ .RejectReason }}</p>
|
||||||
|
<p>
|
||||||
|
<a href="javascript:history.back();">Go back</a>
|
||||||
|
</p>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
{{ end }}
|
||||||
|
|
|
@ -142,13 +142,11 @@ func PodcastEditSubmit(c *RequestContext) ResponseData {
|
||||||
|
|
||||||
title := c.Req.Form.Get("title")
|
title := c.Req.Form.Get("title")
|
||||||
if len(strings.TrimSpace(title)) == 0 {
|
if len(strings.TrimSpace(title)) == 0 {
|
||||||
// TODO(asaf): Report this back to the user
|
return RejectRequest(c, "Podcast title is empty")
|
||||||
return ErrorResponse(http.StatusInternalServerError, oops.New(nil, "Missing title"))
|
|
||||||
}
|
}
|
||||||
description := c.Req.Form.Get("description")
|
description := c.Req.Form.Get("description")
|
||||||
if len(strings.TrimSpace(description)) == 0 {
|
if len(strings.TrimSpace(description)) == 0 {
|
||||||
// TODO(asaf): Report this back to the user
|
return RejectRequest(c, "Podcast description is empty")
|
||||||
return ErrorResponse(http.StatusInternalServerError, oops.New(nil, "Missing description"))
|
|
||||||
}
|
}
|
||||||
podcastImage, header, err := c.Req.FormFile("podcast_image")
|
podcastImage, header, err := c.Req.FormFile("podcast_image")
|
||||||
imageFilename := ""
|
imageFilename := ""
|
||||||
|
@ -159,21 +157,18 @@ func PodcastEditSubmit(c *RequestContext) ResponseData {
|
||||||
}
|
}
|
||||||
if header != nil {
|
if header != nil {
|
||||||
if header.Size > maxFileSize {
|
if header.Size > maxFileSize {
|
||||||
// TODO(asaf): Report this back to the user
|
return RejectRequest(c, fmt.Sprintf("Image filesize too big. Max size: %d bytes", maxFileSize))
|
||||||
return ErrorResponse(http.StatusInternalServerError, oops.New(nil, "Filesize too big"))
|
|
||||||
} else {
|
} else {
|
||||||
c.Perf.StartBlock("PODCAST", "Decoding image")
|
c.Perf.StartBlock("PODCAST", "Decoding image")
|
||||||
config, format, err := image.DecodeConfig(podcastImage)
|
config, format, err := image.DecodeConfig(podcastImage)
|
||||||
c.Perf.EndBlock()
|
c.Perf.EndBlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO(asaf): Report this back to the user
|
return RejectRequest(c, "Image type not supported")
|
||||||
return ErrorResponse(http.StatusInternalServerError, oops.New(err, "Can't parse podcast logo"))
|
|
||||||
}
|
}
|
||||||
imageWidth = config.Width
|
imageWidth = config.Width
|
||||||
imageHeight = config.Height
|
imageHeight = config.Height
|
||||||
if imageWidth == 0 || imageHeight == 0 {
|
if imageWidth == 0 || imageHeight == 0 {
|
||||||
// TODO(asaf): Report this back to the user
|
return RejectRequest(c, "Image has zero size")
|
||||||
return ErrorResponse(http.StatusInternalServerError, oops.New(err, "Invalid image size"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
imageFilename = fmt.Sprintf("podcast/%s/logo%d.%s", c.CurrentProject.Slug, time.Now().UTC().Unix(), format)
|
imageFilename = fmt.Sprintf("podcast/%s/logo%d.%s", c.CurrentProject.Slug, time.Now().UTC().Unix(), format)
|
||||||
|
@ -435,11 +430,17 @@ func PodcastEpisodeSubmit(c *RequestContext) ResponseData {
|
||||||
|
|
||||||
c.Req.ParseForm()
|
c.Req.ParseForm()
|
||||||
title := c.Req.Form.Get("title")
|
title := c.Req.Form.Get("title")
|
||||||
|
if len(strings.TrimSpace(title)) == 0 {
|
||||||
|
return RejectRequest(c, "Episode title is empty")
|
||||||
|
}
|
||||||
description := c.Req.Form.Get("description")
|
description := c.Req.Form.Get("description")
|
||||||
|
if len(strings.TrimSpace(description)) == 0 {
|
||||||
|
return RejectRequest(c, "Episode description is empty")
|
||||||
|
}
|
||||||
episodeNumberStr := c.Req.Form.Get("episode_number")
|
episodeNumberStr := c.Req.Form.Get("episode_number")
|
||||||
episodeNumber, err := strconv.Atoi(episodeNumberStr)
|
episodeNumber, err := strconv.Atoi(episodeNumberStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ErrorResponse(http.StatusInternalServerError, oops.New(err, "Failed to parse episode number"))
|
return RejectRequest(c, "Episode number can't be parsed")
|
||||||
}
|
}
|
||||||
episodeFile := c.Req.Form.Get("episode_file")
|
episodeFile := c.Req.Form.Get("episode_file")
|
||||||
found = false
|
found = false
|
||||||
|
@ -451,7 +452,7 @@ func PodcastEpisodeSubmit(c *RequestContext) ResponseData {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !found {
|
if !found {
|
||||||
return ErrorResponse(http.StatusInternalServerError, oops.New(err, "User-provided episode filename doesn't match existing files"))
|
return RejectRequest(c, "Requested episode file not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Perf.StartBlock("MP3", "Parsing mp3 file for duration")
|
c.Perf.StartBlock("MP3", "Parsing mp3 file for duration")
|
||||||
|
|
|
@ -318,6 +318,23 @@ func FourOhFour(c *RequestContext) ResponseData {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RejectData struct {
|
||||||
|
templates.BaseData
|
||||||
|
RejectReason string
|
||||||
|
}
|
||||||
|
|
||||||
|
func RejectRequest(c *RequestContext, reason string) ResponseData {
|
||||||
|
var res ResponseData
|
||||||
|
err := res.WriteTemplate("reject.html", RejectData{
|
||||||
|
BaseData: getBaseData(c),
|
||||||
|
RejectReason: reason,
|
||||||
|
}, c.Perf)
|
||||||
|
if err != nil {
|
||||||
|
return ErrorResponse(http.StatusInternalServerError, oops.New(err, "Failed to render reject template"))
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
func LoadCommonWebsiteData(c *RequestContext) (bool, ResponseData) {
|
func LoadCommonWebsiteData(c *RequestContext) (bool, ResponseData) {
|
||||||
c.Perf.StartBlock("MIDDLEWARE", "Load common website data")
|
c.Perf.StartBlock("MIDDLEWARE", "Load common website data")
|
||||||
defer c.Perf.EndBlock()
|
defer c.Perf.EndBlock()
|
||||||
|
|
Loading…
Reference in New Issue