Fix examples

This commit is contained in:
Adnan Maolood 2020-10-27 14:17:14 -04:00
parent 9079be9019
commit 860a33f5a2
2 changed files with 7 additions and 7 deletions

View File

@ -76,7 +76,7 @@ func login(w *gmi.ResponseWriter, r *gmi.Request) {
sessions[fingerprint] = &session{ sessions[fingerprint] = &session{
username: username, username: username,
} }
gmi.Redirect(w, r, "/login/password") gmi.Redirect(w, "/login/password")
} }
func loginPassword(w *gmi.ResponseWriter, r *gmi.Request) { func loginPassword(w *gmi.ResponseWriter, r *gmi.Request) {
@ -86,7 +86,7 @@ func loginPassword(w *gmi.ResponseWriter, r *gmi.Request) {
} }
session, ok := getSession(cert) session, ok := getSession(cert)
if !ok { if !ok {
gmi.CertificateNotAuthorized(w, r) w.WriteStatus(gmi.StatusCertificateNotAuthorized)
return return
} }
@ -97,7 +97,7 @@ func loginPassword(w *gmi.ResponseWriter, r *gmi.Request) {
expected := logins[session.username].password expected := logins[session.username].password
if password == expected { if password == expected {
session.authorized = true session.authorized = true
gmi.Redirect(w, r, "/profile") gmi.Redirect(w, "/profile")
} else { } else {
gmi.SensitiveInput(w, r, "Wrong password. Try again") gmi.SensitiveInput(w, r, "Wrong password. Try again")
} }
@ -120,7 +120,7 @@ func profile(w *gmi.ResponseWriter, r *gmi.Request) {
} }
session, ok := getSession(cert) session, ok := getSession(cert)
if !ok { if !ok {
gmi.CertificateNotAuthorized(w, r) w.WriteStatus(gmi.StatusCertificateNotAuthorized)
return return
} }
user := logins[session.username] user := logins[session.username]
@ -136,12 +136,12 @@ func admin(w *gmi.ResponseWriter, r *gmi.Request) {
} }
session, ok := getSession(cert) session, ok := getSession(cert)
if !ok { if !ok {
gmi.CertificateNotAuthorized(w, r) w.WriteStatus(gmi.StatusCertificateNotAuthorized)
return return
} }
user := logins[session.username] user := logins[session.username]
if !user.admin { if !user.admin {
gmi.CertificateNotAuthorized(w, r) w.WriteStatus(gmi.StatusCertificateNotAuthorized)
return return
} }
fmt.Fprintln(w, "Welcome to the admin portal.") fmt.Fprintln(w, "Welcome to the admin portal.")

View File

@ -73,7 +73,7 @@ func sendRequest(req *gmi.Request) error {
} }
// TODO: More fine-grained analysis of the status code. // TODO: More fine-grained analysis of the status code.
switch resp.Status / 10 { switch resp.Status.Class() {
case gmi.StatusClassInput: case gmi.StatusClassInput:
fmt.Printf("%s: ", resp.Meta) fmt.Printf("%s: ", resp.Meta)
scanner.Scan() scanner.Scan()