From 709b0d55416ae90c3eb979f1e0f8a592000993a6 Mon Sep 17 00:00:00 2001 From: Azareal Date: Sun, 5 Apr 2020 13:18:36 +1000 Subject: [PATCH] save bytes --- common/auth.go | 30 ++++++------- public/panel_menu_items.js | 22 +++++----- templates/panel_themes_widgets_widget.html | 14 +++--- templates/profile.html | 48 ++++++++++----------- templates/profile_comments_row.html | 6 +-- templates/register.html | 16 +++---- templates/topic_alt_mini.html | 2 +- templates/topic_alt_quick_reply.html | 28 ++++++------ templates/topic_c_poll_input.html | 2 +- templates/topic_mini.html | 2 +- templates/topics.html | 6 +-- themes/nox/overrides/login.html | 4 +- themes/nox/overrides/panel_before_head.html | 2 +- 13 files changed, 91 insertions(+), 91 deletions(-) diff --git a/common/auth.go b/common/auth.go index 3c5b8e2a..fcec795c 100644 --- a/common/auth.go +++ b/common/auth.go @@ -17,7 +17,7 @@ import ( "strings" "github.com/Azareal/Gosora/common/gauth" - "github.com/Azareal/Gosora/query_gen" + qgen "github.com/Azareal/Gosora/query_gen" //"golang.org/x/crypto/argon2" "golang.org/x/crypto/bcrypt" @@ -66,16 +66,16 @@ var HashPrefixes = map[string]string{ // AuthInt is the main authentication interface. type AuthInt interface { - Authenticate(username string, password string) (uid int, err error, requiresExtraAuth bool) + Authenticate(name, password string) (uid int, err error, requiresExtraAuth bool) ValidateMFAToken(mfaToken string, uid int) error Logout(w http.ResponseWriter, uid int) ForceLogout(uid int) error SetCookies(w http.ResponseWriter, uid int, session string) - SetProvisionalCookies(w http.ResponseWriter, uid int, session string, signedSession string) // To avoid logging someone in until they've passed the MFA check + SetProvisionalCookies(w http.ResponseWriter, uid int, session, signedSession string) // To avoid logging someone in until they've passed the MFA check GetCookies(r *http.Request) (uid int, session string, err error) - SessionCheck(w http.ResponseWriter, r *http.Request) (user *User, halt bool) + SessionCheck(w http.ResponseWriter, r *http.Request) (u *User, halt bool) CreateSession(uid int) (session string, err error) - CreateProvisionalSession(uid int) (provSession string, signedSession string, err error) // To avoid logging someone in until they've passed the MFA check + CreateProvisionalSession(uid int) (provSession, signedSession string, err error) // To avoid logging someone in until they've passed the MFA check } // DefaultAuth is the default authenticator used by Gosora, may be swapped with an alternate authenticator in some situations. E.g. To support LDAP. @@ -98,9 +98,9 @@ func NewDefaultAuth() (*DefaultAuth, error) { // Authenticate checks if a specific username and password is valid and returns the UID for the corresponding user, if so. Otherwise, a user safe error. // IF MFA is enabled, then pass it back a flag telling the caller that authentication isn't complete yet // TODO: Find a better way of handling errors we don't want to reach the user -func (auth *DefaultAuth) Authenticate(username string, password string) (uid int, err error, requiresExtraAuth bool) { +func (auth *DefaultAuth) Authenticate(name string, password string) (uid int, err error, requiresExtraAuth bool) { var realPassword, salt string - err = auth.login.QueryRow(username).Scan(&uid, &realPassword, &salt) + err = auth.login.QueryRow(name).Scan(&uid, &realPassword, &salt) if err == ErrNoRows { return 0, ErrNoUserByName, false } else if err != nil { @@ -145,7 +145,7 @@ func (auth *DefaultAuth) ValidateMFAToken(mfaToken string, uid int) error { if ok { return nil } - + for i, scratch := range mfaItem.Scratch { if subtle.ConstantTimeCompare([]byte(scratch), []byte(mfaToken)) == 1 { err = mfaItem.BurnScratch(i) @@ -295,7 +295,7 @@ func (auth *DefaultAuth) CreateProvisionalSession(uid int) (provSession string, return provSession, hex.EncodeToString(h.Sum(nil)), nil } -func CheckPassword(realPassword string, password string, salt string) (err error) { +func CheckPassword(realPassword, password, salt string) (err error) { blasted := strings.Split(realPassword, "$") prefix := blasted[0] if len(blasted) > 1 { @@ -309,7 +309,7 @@ func CheckPassword(realPassword string, password string, salt string) (err error return checker(realPassword, password, salt) } -func GeneratePassword(password string) (hash string, salt string, err error) { +func GeneratePassword(password string) (hash, salt string, err error) { gen, ok := GeneratePasswordFuncs[DefaultHashAlgo] if !ok { return "", "", ErrHashNotExist @@ -317,12 +317,12 @@ func GeneratePassword(password string) (hash string, salt string, err error) { return gen(password) } -func BcryptCheckPassword(realPassword string, password string, salt string) (err error) { +func BcryptCheckPassword(realPassword, password, salt string) (err error) { return bcrypt.CompareHashAndPassword([]byte(realPassword), []byte(password+salt)) } // Note: The salt is in the hash, therefore the salt parameter is blank -func BcryptGeneratePassword(password string) (hash string, salt string, err error) { +func BcryptGeneratePassword(password string) (hash, salt string, err error) { hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost) if err != nil { return "", "", err @@ -337,7 +337,7 @@ func BcryptGeneratePassword(password string) (hash string, salt string, err erro argon2KeyLen uint32 = 32 ) -func Argon2CheckPassword(realPassword string, password string, salt string) (err error) { +func Argon2CheckPassword(realPassword, password, salt string) (err error) { split := strings.Split(realPassword, "$") // TODO: Better validation if len(split) < 5 { @@ -355,7 +355,7 @@ func Argon2CheckPassword(realPassword string, password string, salt string) (err return nil } -func Argon2GeneratePassword(password string) (hash string, salt string, err error) { +func Argon2GeneratePassword(password string) (hash, salt string, err error) { sbytes := make([]byte, SaltLength) _, err = rand.Read(sbytes) if err != nil { @@ -380,7 +380,7 @@ func FriendlyGAuthSecret(secret string) (out string) { func GenerateGAuthSecret() (string, error) { return GenerateStd32SafeString(14) } -func VerifyGAuthToken(secret string, token string) (bool, error) { +func VerifyGAuthToken(secret, token string) (bool, error) { trueToken, err := gauth.GetTOTPToken(secret) return subtle.ConstantTimeCompare([]byte(trueToken), []byte(token)) == 1, err } diff --git a/public/panel_menu_items.js b/public/panel_menu_items.js index e2bbd944..abf1a849 100644 --- a/public/panel_menu_items.js +++ b/public/panel_menu_items.js @@ -4,19 +4,19 @@ // TODO: Move this into a JS file to reduce the number of possible problems var menuItems = {}; let items = document.getElementsByClassName("panel_menu_item"); -for(let i = 0; item = items[i]; i++) menuItems[i] = item.getAttribute("data-miid"); +for(let i=0; item=items[i]; i++) menuItems[i] = item.getAttribute("data-miid"); Sortable.create(document.getElementById("panel_menu_item_holder"), { sort: true, - onEnd: (evt) => { - console.log("pre menuItems", menuItems) - console.log("evt", evt) + onEnd: evt => { + console.log("pre menuItems",menuItems) + console.log("evt",evt) let oldMiid = menuItems[evt.newIndex]; menuItems[evt.oldIndex] = oldMiid; let newMiid = evt.item.getAttribute("data-miid"); - console.log("newMiid", newMiid); + console.log("newMiid",newMiid); menuItems[evt.newIndex] = newMiid; - console.log("post menuItems", menuItems); + console.log("post menuItems",menuItems); } }); @@ -32,22 +32,22 @@ document.getElementById("panel_menu_items_order_button").addEventListener("click // TODO: Signal the error with a notice if(req.status===200) { let resp = JSON.parse(req.responseText); - console.log("resp", resp); + console.log("resp",resp); // TODO: Should we move other notices into TmplPhrases like this one? pushNotice(phraseBox["panel"]["panel.themes_menus_items_order_updated"]); if(resp.success==1) return; } - } catch(ex) { - console.error("ex", ex) + } catch(e) { + console.error("e",e) } console.trace(); } // ? - Is encodeURIComponent the right function for this? let spl = document.location.pathname.split("/"); - req.open("POST","/panel/themes/menus/item/order/edit/submit/"+parseInt(spl[spl.length-1],10)+"?s=" + encodeURIComponent(me.User.S)); + req.open("POST","/panel/themes/menus/item/order/edit/submit/"+parseInt(spl[spl.length-1],10)+"?s="+encodeURIComponent(me.User.S)); req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); let items = ""; - for(let i = 0; item = menuItems[i];i++) items += item+","; + for(let i=0; item=menuItems[i];i++) items += item+","; if(items.length > 0) items = items.slice(0,-1); req.send("js=1&items={"+items+"}"); }); diff --git a/templates/panel_themes_widgets_widget.html b/templates/panel_themes_widgets_widget.html index 9230b321..1742a047 100644 --- a/templates/panel_themes_widgets_widget.html +++ b/templates/panel_themes_widgets_widget.html @@ -2,11 +2,11 @@
{{lang "panel_themes_widgets_type"}}
@@ -47,9 +47,9 @@
- + - +
\ No newline at end of file diff --git a/templates/profile.html b/templates/profile.html index 04abd694..b32b1f8e 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -1,14 +1,14 @@ {{template "header.html" . }} -
+
-
-
+
+
- {{.ProfileOwner.Name}}{{if .ProfileOwner.Tag}}{{.ProfileOwner.Tag}}{{end}} + {{.ProfileOwner.Name}}{{if .ProfileOwner.Tag}}{{.ProfileOwner.Tag}}{{end}}
@@ -17,7 +17,7 @@ -
+
{{.CurrentScore}} / {{.NextScore}}
@@ -36,25 +36,25 @@ {{if (.CurrentUser.IsSuperMod) and not (.ProfileOwner.IsSuperMod)}}
{{if .ProfileOwner.IsBanned}}{{lang "profile.unban"}} - {{else}}{{lang "profile.ban"}}{{end}} + {{else}}{{lang "profile.ban"}}{{end}}
{{end}}
- {{if .Blocked}}{{lang "profile.unblock"}}{{else}}{{lang "profile.block"}}{{end}} + {{if .Blocked}}{{lang "profile.unblock"}}{{else}}{{lang "profile.block"}}{{end}}
- +
{{end}}
-
+
{{if .CurrentUser.Loggedin}} {{if .CurrentUser.Perms.BanUsers}} @@ -69,19 +69,19 @@
@@ -93,16 +93,16 @@
{{/****/}}
-
+
- @@ -118,27 +118,27 @@ {{end}} {{end}} -
+ -
{{template "profile_comments_row.html" . }}
+
{{template "profile_comments_row.html" . }}
{{if .CurrentUser.Loggedin}} {{if .CanComment}} - + -
+
-
+
-
+
{{end}} {{else}} -
+
{{lang "profile.comments_form_guest"}}
{{end}} diff --git a/templates/profile_comments_row.html b/templates/profile_comments_row.html index 33e311ac..343a3c19 100644 --- a/templates/profile_comments_row.html +++ b/templates/profile_comments_row.html @@ -6,11 +6,11 @@ {{.CreatedByName}}   - {{if $.CurrentUser.IsMod}} + {{if $.CurrentUser.IsMod}} - {{end}} + {{end}} - + {{if .Tag}}{{.Tag}}{{end}} diff --git a/templates/register.html b/templates/register.html index e5525c8a..e615da23 100644 --- a/templates/register.html +++ b/templates/register.html @@ -7,31 +7,31 @@
{{/** This is not a TOS, that text is there to fool the spambots **/}} -
+
-
+
- +
diff --git a/templates/topic_alt_mini.html b/templates/topic_alt_mini.html index 8f4b1be7..0bbeb176 100644 --- a/templates/topic_alt_mini.html +++ b/templates/topic_alt_mini.html @@ -1,4 +1,4 @@ -
+
{{range .Header.NoticeList}}{{template "notice.html" . }}{{end}}
{{template "topic_alt_inner.html" . }} diff --git a/templates/topic_alt_quick_reply.html b/templates/topic_alt_quick_reply.html index 0e1ad1c4..e67ef6ed 100644 --- a/templates/topic_alt_quick_reply.html +++ b/templates/topic_alt_quick_reply.html @@ -1,8 +1,8 @@
-
+
Avatar
- +
{{if .CurrentUser.Tag}}{{else}}{{end}} @@ -10,31 +10,31 @@
-
-
- - +
+
+ +
- +
-
- +
+ - +
- - + + {{if .CurrentUser.Perms.UploadFiles}} - - + +
{{end}}
diff --git a/templates/topic_c_poll_input.html b/templates/topic_c_poll_input.html index f6fa2041..f4e1ab96 100644 --- a/templates/topic_c_poll_input.html +++ b/templates/topic_c_poll_input.html @@ -1,5 +1,5 @@
- +
\ No newline at end of file diff --git a/templates/topic_mini.html b/templates/topic_mini.html index 4d6c2039..a5ff7f8a 100644 --- a/templates/topic_mini.html +++ b/templates/topic_mini.html @@ -1,4 +1,4 @@ -
+
{{range .Header.NoticeList}}{{template "notice.html" . }}{{end}}
{{template "topic_inner.html" . }} diff --git a/templates/topics.html b/templates/topics.html index 2780b88b..8d222039 100644 --- a/templates/topics.html +++ b/templates/topics.html @@ -1,6 +1,6 @@ {{template "header.html" . }}
-{{if not .CurrentUser.Loggedin}}{{end}} +{{if not .CurrentUser.Loggedin}}{{end}}

{{.Title}}

@@ -59,7 +59,7 @@
@@ -76,7 +76,7 @@
-
+
{{range .TopicList}}{{template "topics_topic.html" . }}{{else}}
{{lang "topics_no_topics"}}{{if .CurrentUser.Loggedin}}{{if .CurrentUser.Perms.CreateTopic}} {{lang "topics_start_one"}}{{end}}{{end}}
{{end}}
diff --git a/themes/nox/overrides/login.html b/themes/nox/overrides/login.html index 33c32a3d..065870ac 100644 --- a/themes/nox/overrides/login.html +++ b/themes/nox/overrides/login.html @@ -7,11 +7,11 @@