moved util functions in main.go into a seperate file
This commit is contained in:
@ -5,4 +5,4 @@ RBU account system
|
||||
# api
|
||||
use `/login?redirect=someurl` to redirect the user after the login is finnished.
|
||||
Use `api/accountinfo?accountkey=key&password=password` to get information about the user.
|
||||
accountKey is the value of the cookie with the key "session".
|
||||
accountkey is the value of the cookie with the key "session".
|
||||
|
||||
16
src/main.go
16
src/main.go
@ -9,12 +9,10 @@ import (
|
||||
"github.com/zaddok/moodle"
|
||||
"html/template"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"regexp"
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"fmt"
|
||||
"golang.org/x/crypto/argon2"
|
||||
)
|
||||
var discord *discordgo.Session
|
||||
var secret secrets_json
|
||||
@ -86,17 +84,3 @@ func main() {
|
||||
|
||||
http.ListenAndServe(":" + fmt.Sprint(config.Port), nil)
|
||||
}
|
||||
func log(err error) {
|
||||
if err!=nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func hashFunc(password []byte, salt []byte) []byte {
|
||||
return argon2.IDKey(password, salt, 1, 64*1024, 4, 32)
|
||||
}
|
||||
func runTemplate(w http.ResponseWriter, template *template.Template, templateData interface{}) {
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
var err error = template.Execute(w, templateData)
|
||||
log(err)
|
||||
}
|
||||
|
||||
21
src/util.go
Normal file
21
src/util.go
Normal file
@ -0,0 +1,21 @@
|
||||
package main
|
||||
import (
|
||||
"golang.org/x/crypto/argon2"
|
||||
"net/http"
|
||||
"html/template"
|
||||
)
|
||||
|
||||
func log(err error) {
|
||||
if err!=nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func hashFunc(password []byte, salt []byte) []byte {
|
||||
return argon2.IDKey(password, salt, 1, 64*1024, 4, 32)
|
||||
}
|
||||
func runTemplate(w http.ResponseWriter, template *template.Template, templateData interface{}) {
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
var err error = template.Execute(w, templateData)
|
||||
log(err)
|
||||
}
|
||||
Reference in New Issue
Block a user