error page
This commit is contained in:
parent
04969f7532
commit
c1373242bb
@ -3,9 +3,7 @@ package manage
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/TicketsBot/GoPanel/config"
|
||||
"github.com/TicketsBot/GoPanel/database"
|
||||
"github.com/TicketsBot/GoPanel/rpc/cache"
|
||||
"github.com/TicketsBot/GoPanel/utils"
|
||||
"github.com/TicketsBot/archiverclient"
|
||||
"github.com/TicketsBot/common/permission"
|
||||
@ -27,50 +25,39 @@ func ModmailLogViewHandler(ctx *gin.Context) {
|
||||
// Verify the guild exists
|
||||
guildId, err := strconv.ParseUint(ctx.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 404 Page
|
||||
utils.ErrorPage(ctx, 404, "Couldn't find a server with the ID provided")
|
||||
return
|
||||
}
|
||||
|
||||
// Get object for selected guild
|
||||
guild, _ := cache.Instance.GetGuild(guildId, false)
|
||||
|
||||
// get ticket UUID
|
||||
archiveUuid, err := uuid.FromString(ctx.Param("uuid"))
|
||||
if err != nil {
|
||||
// TODO: 404 error page
|
||||
ctx.AbortWithStatusJSON(404, gin.H{
|
||||
"success": false,
|
||||
"error": "Modmail archive not found",
|
||||
})
|
||||
utils.ErrorPage(ctx, 404, "Modmail archive with provided UUID not found")
|
||||
return
|
||||
}
|
||||
|
||||
// get ticket object
|
||||
archive, err := database.Client.ModmailArchive.Get(archiveUuid)
|
||||
if err != nil {
|
||||
// TODO: 500 error page
|
||||
ctx.AbortWithStatusJSON(500, gin.H{
|
||||
"success": false,
|
||||
"error": err.Error(),
|
||||
})
|
||||
utils.ErrorPage(ctx, 500, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// Verify this is a valid ticket and it is closed
|
||||
if archive.Uuid == uuid.Nil{
|
||||
ctx.Redirect(302, fmt.Sprintf("/manage/%d/logs/modmail", guild.Id))
|
||||
if archive.Uuid == uuid.Nil {
|
||||
utils.ErrorPage(ctx, 404, "Modmail archive with provided UUID not found")
|
||||
return
|
||||
}
|
||||
|
||||
// Verify this modmail ticket was for this guild
|
||||
if archive.GuildId != guildId {
|
||||
ctx.Redirect(302, fmt.Sprintf("/manage/%d/logs/modmail", guild.Id))
|
||||
utils.ErrorPage(ctx, 403, "Modmail archive does not belong to this server")
|
||||
return
|
||||
}
|
||||
|
||||
// Verify the user has permissions to be here
|
||||
if utils.GetPermissionLevel(guildId, userId) < permission.Support && archive.UserId != userId {
|
||||
ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page
|
||||
utils.ErrorPage(ctx, 403, "You do not have permission to view this archive")
|
||||
return
|
||||
}
|
||||
|
||||
@ -78,18 +65,18 @@ func ModmailLogViewHandler(ctx *gin.Context) {
|
||||
messages, err := Archiver.GetModmail(guildId, archiveUuid.String())
|
||||
if err != nil {
|
||||
if errors.Is(err, archiverclient.ErrExpired) {
|
||||
ctx.String(200, "Archives expired: Purchase premium for permanent log storage") // TODO: Actual error page
|
||||
return
|
||||
utils.ErrorPage(ctx, 404, "Archive expired - purchase premium for permanent log storage")
|
||||
} else {
|
||||
utils.ErrorPage(ctx, 500, err.Error())
|
||||
}
|
||||
|
||||
ctx.String(500, fmt.Sprintf("Failed to retrieve archive - please contact the developers: %s", err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
// format to html
|
||||
html, err := Archiver.Encode(messages, fmt.Sprintf("modmail-%s", archiveUuid))
|
||||
if err != nil {
|
||||
ctx.String(500, fmt.Sprintf("Failed to retrieve archive - please contact the developers: %s", err.Error()))
|
||||
utils.ErrorPage(ctx, 500, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -50,13 +50,14 @@ func CallbackHandler(ctx *gin.Context) {
|
||||
|
||||
code, ok := ctx.GetQuery("code")
|
||||
if !ok {
|
||||
ctx.String(400, "Discord provided an invalid Oauth2 code")
|
||||
utils.ErrorPage(ctx, 400, "Discord provided invalid Oauth2 code")
|
||||
return
|
||||
}
|
||||
|
||||
res, err := discord.AccessToken(code)
|
||||
if err != nil {
|
||||
ctx.String(500, err.Error())
|
||||
utils.ErrorPage(ctx, 500, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
store.Set("access_token", res.AccessToken)
|
||||
|
@ -17,14 +17,15 @@ func AuthenticateGuild(isApiMethod bool) gin.HandlerFunc {
|
||||
parsed, err := strconv.ParseUint(guildId, 10, 64)
|
||||
if err != nil {
|
||||
if isApiMethod {
|
||||
ctx.AbortWithStatusJSON(400, gin.H{
|
||||
ctx.JSON(400, gin.H{
|
||||
"success": false,
|
||||
"error": "Invalid guild ID",
|
||||
})
|
||||
} else {
|
||||
ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 404 Page
|
||||
utils.ErrorPage(ctx, 400, "Invalid server ID")
|
||||
ctx.Abort()
|
||||
}
|
||||
ctx.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
@ -35,7 +36,7 @@ func AuthenticateGuild(isApiMethod bool) gin.HandlerFunc {
|
||||
if isApiMethod {
|
||||
ctx.Redirect(302, fmt.Sprintf("https://invite.ticketsbot.net/?guild_id=%d&disable_guild_select=true&response_type=code&scope=bot%%20identify&redirect_uri=%s", parsed, config.Conf.Server.BaseUrl))
|
||||
} else {
|
||||
ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 404 Page
|
||||
utils.ErrorPage(ctx, 404, "Couldn't find server with the provided ID")
|
||||
}
|
||||
ctx.Abort()
|
||||
return
|
||||
@ -52,20 +53,20 @@ func AuthenticateGuild(isApiMethod bool) gin.HandlerFunc {
|
||||
"error": "Unauthorized",
|
||||
})
|
||||
} else {
|
||||
ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 403 Page
|
||||
utils.ErrorPage(ctx, 403, "You don't have permission to be here - make sure the server owner has added you as an admin with t!addadmin")
|
||||
ctx.Abort()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if isApiMethod {
|
||||
ctx.AbortWithStatusJSON(400, gin.H{
|
||||
ctx.JSON(400, gin.H{
|
||||
"success": false,
|
||||
"error": "Invalid guild ID",
|
||||
})
|
||||
} else {
|
||||
ctx.Redirect(302, config.Conf.Server.BaseUrl) // TODO: 404 Page
|
||||
ctx.Abort()
|
||||
utils.ErrorPage(ctx, 400, "Invalid server ID")
|
||||
}
|
||||
ctx.Abort()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -149,6 +149,8 @@ func createRenderer() multitemplate.Renderer {
|
||||
r = addManageTemplate(r, "panels", "./public/templates/includes/substitutionmodal.tmpl", "./public/templates/includes/paneleditmodal.tmpl")
|
||||
r = addManageTemplate(r, "tags")
|
||||
|
||||
r = addErrorTemplate(r)
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
@ -183,6 +185,16 @@ func addManageTemplate(renderer multitemplate.Renderer, name string, extra ...st
|
||||
return renderer
|
||||
}
|
||||
|
||||
func addErrorTemplate(renderer multitemplate.Renderer) multitemplate.Renderer {
|
||||
files := []string{
|
||||
"./public/templates/layouts/error.tmpl",
|
||||
"./public/templates/includes/head.tmpl",
|
||||
}
|
||||
|
||||
renderer.AddFromFiles("error", files...)
|
||||
return renderer
|
||||
}
|
||||
|
||||
func createLimiter(limit int64, period time.Duration) func(*gin.Context) {
|
||||
store := memory.NewStore()
|
||||
rate := limiter.Rate{
|
||||
|
@ -1,5 +1,12 @@
|
||||
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans&display=swap');
|
||||
|
||||
body, h1, .h1, h2, .h2, h3, .h3, h4, .h4, h5, .h5, h6, .h6, p, .navbar, .brand, .btn-simple, .alert, a, .td-name, td, button.close {
|
||||
font-family: 'Noto Sans', sans-serif !important;
|
||||
|
||||
font-weight: 400 !important;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Open Sans',sans-serif !important;
|
||||
font-size: 1rem;
|
||||
font-weight: 400;
|
||||
line-height: 1.5;
|
||||
|
@ -18,6 +18,10 @@ async function getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
function clearLocalStorage() {
|
||||
window.localStorage.clear();
|
||||
}
|
||||
|
||||
async function setDefaultHeader() {
|
||||
const token = await getToken();
|
||||
axios.defaults.headers.common['Authorization'] = token;
|
||||
|
@ -28,7 +28,7 @@
|
||||
<a class="nav-link" href="/"><i class="fas fa-server icon"></i>Servers</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/logout"><i class="fas fa-sign-out-alt icon"></i>Logout</a>
|
||||
<a class="nav-link" href="/logout" onclick="clearLocalStorage();"><i class="fas fa-sign-out-alt icon"></i>Logout</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">{{.name}}<img class="avatar" src="{{.avatar}}?size=256" alt="Avatar"/></a>
|
||||
|
@ -16,7 +16,7 @@
|
||||
</li>
|
||||
|
||||
<li class="nav-item sidebar-bottom" style="bottom: 60px">
|
||||
<a href="/logout">
|
||||
<a href="/logout" onclick="clearLocalStorage();">
|
||||
<i class="fas fa-sign-out-alt"></i>
|
||||
<p>Logout</p>
|
||||
</a>
|
||||
|
47
public/templates/layouts/error.tmpl
Normal file
47
public/templates/layouts/error.tmpl
Normal file
@ -0,0 +1,47 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
{{template "head" .}}
|
||||
</head>
|
||||
<body>
|
||||
<div class="wrapper">
|
||||
<div class="main-panel" style="width: 100% !important;">
|
||||
<div class="container-fluid" style="height: 100%;">
|
||||
<div class="row" style="padding-top: 10%">
|
||||
<div class="col-md-6 offset-md-3">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h4 class="card-title">Error {{.status}}</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="white">{{.error}}</p>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-md-2 offset-md-8">
|
||||
<button type="button" class="btn btn-info btn-fill" onclick="back();" style="width: 100%">Back</button>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<button type="button" class="btn btn-primary btn-fill" onclick="home()" style="width: 100%">Home</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
function back() {
|
||||
window.history.back();
|
||||
}
|
||||
|
||||
function home() {
|
||||
window.location.href = '/'
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
10
utils/errorpage.go
Normal file
10
utils/errorpage.go
Normal file
@ -0,0 +1,10 @@
|
||||
package utils
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func ErrorPage(ctx *gin.Context, statusCode int, error string) {
|
||||
ctx.HTML(statusCode, "error", gin.H{
|
||||
"status": statusCode,
|
||||
"error": error,
|
||||
})
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user