💾 Archived View for gemini.rmf-dev.com › repo › Vaati › Gemigit › files › 945abbc65661ce421b7723288b… captured on 2023-04-26 at 13:22:03. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-04-19)
-=-=-=-=-=-=-
0 package gmi
1
2 import (
3 "gemigit/auth"
4 "github.com/pitr/gig"
5 )
6
7 func Register(c gig.Context) error {
8 cert := c.Certificate()
9 if cert == nil {
10 return c.NoContent(gig.StatusClientCertificateRequired,
11 "Certificate required")
12 }
13
14 name, err := c.QueryString()
15 if err != nil {
16 return c.NoContent(gig.StatusBadRequest,
17 "Invalid name received")
18 }
19 if name != "" {
20 return c.NoContent(gig.StatusRedirectPermanent,
21 "/register/" + name)
22 }
23
24 return c.NoContent(gig.StatusInput, "Username")
25 }
26
27 func RegisterConfirm(c gig.Context) error {
28 cert := c.Certificate()
29 if cert == nil {
30 return c.NoContent(gig.StatusClientCertificateRequired,
31 "Certificate required")
32 }
33
34 password, err := c.QueryString()
35 if err != nil {
36 return c.NoContent(gig.StatusBadRequest,
37 "Invalid password received")
38 }
39 if password == "" {
40 return c.NoContent(gig.StatusSensitiveInput, "Password")
41 }
42 if err = auth.Register(c.Param("name"), password, c.IP()); err != nil {
43 return c.NoContent(gig.StatusBadRequest, err.Error())
44 }
45 data, err := execTemplate("register_success.gmi", nil)
46 if err != nil {
47 return c.NoContent(gig.StatusBadRequest, err.Error())
48 }
49 return c.Gemini(data)
50 }
51
52 func Login(user, pass, sig string, c gig.Context) (string, error) {
53 err := auth.Connect(user, pass, sig, c.IP())
54
55 if err != nil && err.Error() == "token required" {
56 return "/otp", nil
57 }
58 if err != nil {
59 return "", err
60 }
61 return "/account", nil
62 }
63