2016-12-02 07:38:54 +00:00
|
|
|
package main
|
2016-12-03 11:06:47 +00:00
|
|
|
import "fmt"
|
2016-12-02 07:38:54 +00:00
|
|
|
import "log"
|
|
|
|
import "bytes"
|
|
|
|
import "net/http"
|
|
|
|
|
|
|
|
func InternalError(err error, w http.ResponseWriter, r *http.Request, user User) {
|
|
|
|
log.Fatal(err)
|
2016-12-16 10:37:42 +00:00
|
|
|
pi := Page{"Internal Server Error","error",user,nList,tList,"A problem has occured in the system."}
|
2016-12-02 07:38:54 +00:00
|
|
|
var b bytes.Buffer
|
|
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
|
|
|
errpage := b.String()
|
2016-12-03 11:06:47 +00:00
|
|
|
w.WriteHeader(500)
|
|
|
|
fmt.Fprintln(w,errpage)
|
2016-12-02 07:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func InternalErrorJSQ(err error, w http.ResponseWriter, r *http.Request, user User, is_js string) {
|
|
|
|
log.Fatal(err)
|
|
|
|
errmsg := "A problem has occured in the system."
|
|
|
|
if is_js == "0" {
|
2016-12-16 10:37:42 +00:00
|
|
|
pi := Page{"Internal Server Error","error",user,nList,tList,errmsg}
|
2016-12-02 07:38:54 +00:00
|
|
|
var b bytes.Buffer
|
|
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
|
|
|
errpage := b.String()
|
2016-12-03 11:06:47 +00:00
|
|
|
w.WriteHeader(500)
|
|
|
|
fmt.Fprintln(w,errpage)
|
2016-12-02 07:38:54 +00:00
|
|
|
} else {
|
|
|
|
http.Error(w,"{'errmsg': '" + errmsg + "'}",500)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func LocalError(errmsg string, w http.ResponseWriter, r *http.Request, user User) {
|
2016-12-16 10:37:42 +00:00
|
|
|
pi := Page{"Local Error","error",user,nList,tList,errmsg}
|
2016-12-02 07:38:54 +00:00
|
|
|
var b bytes.Buffer
|
|
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
|
|
|
errpage := b.String()
|
2016-12-03 11:06:47 +00:00
|
|
|
w.WriteHeader(500)
|
|
|
|
fmt.Fprintln(w,errpage)
|
2016-12-02 07:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func LoginRequired(w http.ResponseWriter, r *http.Request, user User) {
|
2016-12-16 10:37:42 +00:00
|
|
|
pi := Page{"Local Error","error",user,nList,tList,"You need to login to do that."}
|
2016-12-02 07:38:54 +00:00
|
|
|
|
|
|
|
var b bytes.Buffer
|
|
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
|
|
|
errpage := b.String()
|
2016-12-03 11:06:47 +00:00
|
|
|
w.WriteHeader(401)
|
|
|
|
fmt.Fprintln(w,errpage)
|
2016-12-02 07:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func LocalErrorJSQ(errmsg string, w http.ResponseWriter, r *http.Request, user User, is_js string) {
|
|
|
|
if is_js == "0" {
|
2016-12-16 10:37:42 +00:00
|
|
|
pi := Page{"Local Error","error",user,nList,tList,errmsg}
|
2016-12-02 07:38:54 +00:00
|
|
|
var b bytes.Buffer
|
|
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
|
|
|
errpage := b.String()
|
2016-12-03 11:06:47 +00:00
|
|
|
w.WriteHeader(500)
|
|
|
|
fmt.Fprintln(w,errpage)
|
2016-12-02 07:38:54 +00:00
|
|
|
} else {
|
|
|
|
http.Error(w,"{'errmsg': '" + errmsg + "'}",500)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-03 10:25:39 +00:00
|
|
|
func NoPermissions(w http.ResponseWriter, r *http.Request, user User) {
|
|
|
|
errmsg := "You don't have permission to do that."
|
2016-12-16 10:37:42 +00:00
|
|
|
pi := Page{"Local Error","error",user,nList,tList,errmsg}
|
2016-12-03 10:25:39 +00:00
|
|
|
var b bytes.Buffer
|
|
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
|
|
|
errpage := b.String()
|
2016-12-03 11:06:47 +00:00
|
|
|
w.WriteHeader(403)
|
|
|
|
fmt.Fprintln(w,errpage)
|
2016-12-03 10:25:39 +00:00
|
|
|
}
|
|
|
|
|
2016-12-02 07:38:54 +00:00
|
|
|
func NoPermissionsJSQ(w http.ResponseWriter, r *http.Request, user User, is_js string) {
|
|
|
|
errmsg := "You don't have permission to do that."
|
|
|
|
if is_js == "0" {
|
2016-12-16 10:37:42 +00:00
|
|
|
pi := Page{"Local Error","error",user,nList,tList,errmsg}
|
2016-12-02 07:38:54 +00:00
|
|
|
var b bytes.Buffer
|
2016-12-04 10:44:28 +00:00
|
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
|
|
|
errpage := b.String()
|
|
|
|
w.WriteHeader(403)
|
|
|
|
fmt.Fprintln(w,errpage)
|
|
|
|
} else {
|
|
|
|
http.Error(w,"{'errmsg': '" + errmsg + "'}",403)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Banned(w http.ResponseWriter, r *http.Request, user User) {
|
2016-12-16 10:37:42 +00:00
|
|
|
pi := Page{"Banned","error",user,nList,tList,"You have been banned from this site."}
|
2016-12-04 10:44:28 +00:00
|
|
|
var b bytes.Buffer
|
|
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
|
|
|
errpage := b.String()
|
|
|
|
w.WriteHeader(403)
|
|
|
|
fmt.Fprintln(w,errpage)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BannedJSQ(w http.ResponseWriter, r *http.Request, user User, is_js string) {
|
|
|
|
if is_js == "0" {
|
2016-12-16 10:37:42 +00:00
|
|
|
pi := Page{"Banned","error",user,nList,tList,"You have been banned from this site."}
|
2016-12-04 10:44:28 +00:00
|
|
|
var b bytes.Buffer
|
2016-12-02 07:38:54 +00:00
|
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
|
|
|
errpage := b.String()
|
2016-12-03 11:06:47 +00:00
|
|
|
w.WriteHeader(403)
|
|
|
|
fmt.Fprintln(w,errpage)
|
2016-12-02 07:38:54 +00:00
|
|
|
} else {
|
2016-12-05 07:21:17 +00:00
|
|
|
http.Error(w,"{'errmsg': 'You have been banned from this site.'}",403)
|
2016-12-02 07:38:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func LoginRequiredJSQ(w http.ResponseWriter, r *http.Request, user User, is_js string) {
|
|
|
|
if is_js == "0" {
|
2016-12-16 10:37:42 +00:00
|
|
|
pi := Page{"Local Error","error",user,nList,tList,"You need to login to do that."}
|
2016-12-02 07:38:54 +00:00
|
|
|
var b bytes.Buffer
|
|
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
|
|
|
errpage := b.String()
|
2016-12-03 11:06:47 +00:00
|
|
|
w.WriteHeader(401)
|
|
|
|
fmt.Fprintln(w,errpage)
|
2016-12-02 07:38:54 +00:00
|
|
|
} else {
|
2016-12-05 07:21:17 +00:00
|
|
|
http.Error(w,"{'errmsg': 'You need to login to do that.'}",401)
|
2016-12-02 07:38:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-06 10:26:48 +00:00
|
|
|
func SecurityError(w http.ResponseWriter, r *http.Request, user User) {
|
|
|
|
errmsg := "There was a security issue with your request."
|
2016-12-16 10:37:42 +00:00
|
|
|
pi := Page{"Security Error","error",user,nList,tList,errmsg}
|
2016-12-06 10:26:48 +00:00
|
|
|
var b bytes.Buffer
|
|
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
|
|
|
errpage := b.String()
|
|
|
|
w.WriteHeader(403)
|
|
|
|
fmt.Fprintln(w,errpage)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NotFound(w http.ResponseWriter, r *http.Request, user User) {
|
|
|
|
errmsg := "The requested page doesn't exist."
|
2016-12-16 10:37:42 +00:00
|
|
|
pi := Page{"Not Found","error",user,nList,tList,errmsg}
|
2016-12-06 10:26:48 +00:00
|
|
|
var b bytes.Buffer
|
|
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
|
|
|
errpage := b.String()
|
|
|
|
w.WriteHeader(404)
|
|
|
|
fmt.Fprintln(w,errpage)
|
|
|
|
}
|
|
|
|
|
2017-01-03 07:47:31 +00:00
|
|
|
func CustomError(errmsg string, errcode int, errtitle string, w http.ResponseWriter, r *http.Request, user User) {
|
|
|
|
pi := Page{errtitle,"error",user,nList,tList,errmsg}
|
|
|
|
var b bytes.Buffer
|
|
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
|
|
|
errpage := b.String()
|
|
|
|
w.WriteHeader(errcode)
|
|
|
|
fmt.Fprintln(w,errpage)
|
|
|
|
}
|
|
|
|
|
2016-12-02 07:38:54 +00:00
|
|
|
func CustomErrorJSQ(errmsg string, errcode int, errtitle string, w http.ResponseWriter, r *http.Request, user User, is_js string) {
|
|
|
|
if is_js == "0" {
|
2016-12-16 10:37:42 +00:00
|
|
|
pi := Page{errtitle,"error",user,nList,tList,errmsg}
|
2016-12-02 07:38:54 +00:00
|
|
|
var b bytes.Buffer
|
|
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
|
|
|
errpage := b.String()
|
2017-01-03 07:47:31 +00:00
|
|
|
w.WriteHeader(errcode)
|
2016-12-03 11:06:47 +00:00
|
|
|
fmt.Fprintln(w,errpage)
|
2016-12-02 07:38:54 +00:00
|
|
|
} else {
|
2017-01-03 07:47:31 +00:00
|
|
|
http.Error(w,"{'errmsg': '" + errmsg + "'}",errcode)
|
2016-12-02 07:38:54 +00:00
|
|
|
}
|
|
|
|
}
|