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