7b1f27bf41
I'm slowly rolling this feature out to the various routes and doing tests. Added the notice system. Added the "You are banned" notice. Added the Sendmail experimental plugin for sending emails without needing a SMTP server. Added the debug flag for tuning down the amount of noise in the console. Converted a system notice over to the notice system. Changed the Activation Function signature to allow it to return errors which abort the process of plugin activation. Plugins can now set tags. These will be visible in the Plugin Manager at a later date to specify a small snippet of additional information. Variadic hooks are now first class citizens of the Plugin API rather than just an experiment. SessionCheck() and the new SimpleSessionCheck() can now halt further processing of a route. Deleted plugins are no longer shown on the Plugin Manager. The registration form no longer allows users with blank names, emails or passwords to register. The registration form now blocks some extremely common passwords. Added the new status CSS to the /forum/ route. Simplified some of the range loops in the templates.
155 lines
4.7 KiB
Go
155 lines
4.7 KiB
Go
package main
|
|
import "fmt"
|
|
import "log"
|
|
import "bytes"
|
|
import "net/http"
|
|
|
|
func InternalError(err error, w http.ResponseWriter, r *http.Request, user User) {
|
|
log.Fatal(err)
|
|
pi := Page{"Internal Server Error","error",user,nList,tList,"A problem has occured in the system."}
|
|
var b bytes.Buffer
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
|
errpage := b.String()
|
|
w.WriteHeader(500)
|
|
fmt.Fprintln(w,errpage)
|
|
}
|
|
|
|
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" {
|
|
pi := Page{"Internal Server Error","error",user,nList,tList,errmsg}
|
|
var b bytes.Buffer
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
|
errpage := b.String()
|
|
w.WriteHeader(500)
|
|
fmt.Fprintln(w,errpage)
|
|
} else {
|
|
http.Error(w,"{'errmsg': '" + errmsg + "'}",500)
|
|
}
|
|
}
|
|
|
|
func LocalError(errmsg string, w http.ResponseWriter, r *http.Request, user User) {
|
|
pi := Page{"Local Error","error",user,nList,tList,errmsg}
|
|
var b bytes.Buffer
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
|
errpage := b.String()
|
|
w.WriteHeader(500)
|
|
fmt.Fprintln(w,errpage)
|
|
}
|
|
|
|
func LoginRequired(w http.ResponseWriter, r *http.Request, user User) {
|
|
pi := Page{"Local Error","error",user,nList,tList,"You need to login to do that."}
|
|
|
|
var b bytes.Buffer
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
|
errpage := b.String()
|
|
w.WriteHeader(401)
|
|
fmt.Fprintln(w,errpage)
|
|
}
|
|
|
|
func LocalErrorJSQ(errmsg string, w http.ResponseWriter, r *http.Request, user User, is_js string) {
|
|
if is_js == "0" {
|
|
pi := Page{"Local Error","error",user,nList,tList,errmsg}
|
|
var b bytes.Buffer
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
|
errpage := b.String()
|
|
w.WriteHeader(500)
|
|
fmt.Fprintln(w,errpage)
|
|
} else {
|
|
http.Error(w,"{'errmsg': '" + errmsg + "'}",500)
|
|
}
|
|
}
|
|
|
|
func NoPermissions(w http.ResponseWriter, r *http.Request, user User) {
|
|
errmsg := "You don't have permission to do that."
|
|
pi := Page{"Local Error","error",user,nList,tList,errmsg}
|
|
var b bytes.Buffer
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
|
errpage := b.String()
|
|
w.WriteHeader(403)
|
|
fmt.Fprintln(w,errpage)
|
|
}
|
|
|
|
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" {
|
|
pi := Page{"Local Error","error",user,nList,tList,errmsg}
|
|
var b bytes.Buffer
|
|
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) {
|
|
pi := Page{"Banned","error",user,nList,tList,"You have been banned from this site."}
|
|
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" {
|
|
pi := Page{"Banned","error",user,nList,tList,"You have been banned from this site."}
|
|
var b bytes.Buffer
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
|
errpage := b.String()
|
|
w.WriteHeader(403)
|
|
fmt.Fprintln(w,errpage)
|
|
} else {
|
|
http.Error(w,"{'errmsg': 'You have been banned from this site.'}",403)
|
|
}
|
|
}
|
|
|
|
func LoginRequiredJSQ(w http.ResponseWriter, r *http.Request, user User, is_js string) {
|
|
if is_js == "0" {
|
|
pi := Page{"Local Error","error",user,nList,tList,"You need to login to do that."}
|
|
var b bytes.Buffer
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
|
errpage := b.String()
|
|
w.WriteHeader(401)
|
|
fmt.Fprintln(w,errpage)
|
|
} else {
|
|
http.Error(w,"{'errmsg': 'You need to login to do that.'}",401)
|
|
}
|
|
}
|
|
|
|
func SecurityError(w http.ResponseWriter, r *http.Request, user User) {
|
|
errmsg := "There was a security issue with your request."
|
|
pi := Page{"Security Error","error",user,nList,tList,errmsg}
|
|
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."
|
|
pi := Page{"Not Found","error",user,nList,tList,errmsg}
|
|
var b bytes.Buffer
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
|
errpage := b.String()
|
|
w.WriteHeader(404)
|
|
fmt.Fprintln(w,errpage)
|
|
}
|
|
|
|
func CustomErrorJSQ(errmsg string, errcode int, errtitle string, w http.ResponseWriter, r *http.Request, user User, is_js string) {
|
|
if is_js == "0" {
|
|
pi := Page{errtitle,"error",user,nList,tList,errmsg}
|
|
var b bytes.Buffer
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
|
errpage := b.String()
|
|
w.WriteHeader(500)
|
|
fmt.Fprintln(w,errpage)
|
|
} else {
|
|
http.Error(w,"{'errmsg': '" + errmsg + "'}",500)
|
|
}
|
|
}
|