forked from Deuxfleurs/guichet
simplify invitations
This commit is contained in:
parent
917c10737d
commit
371c46e0ed
4 changed files with 6 additions and 57 deletions
2
go.sum
2
go.sum
|
@ -31,8 +31,6 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
|
||||||
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
|
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
|
||||||
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
|
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
|
||||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||||
git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20230131081355-c965fe7f7dc9 h1:ERg8KCpIKym98EOKa8Gq0NSBxsasD3sqb/R0gg1wOzU=
|
|
||||||
git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20230131081355-c965fe7f7dc9/go.mod h1:TlSL6QVxozmdRaSgP6Akspi0HCJv4HAkkq3Dldru4GM=
|
|
||||||
git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231128153612-8b81fae65e5e h1:h89CAh0qmUcGJykss/utXIw+yRGa3Gr6VyrZ5ZWN0kY=
|
git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231128153612-8b81fae65e5e h1:h89CAh0qmUcGJykss/utXIw+yRGa3Gr6VyrZ5ZWN0kY=
|
||||||
git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231128153612-8b81fae65e5e/go.mod h1:TlSL6QVxozmdRaSgP6Akspi0HCJv4HAkkq3Dldru4GM=
|
git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231128153612-8b81fae65e5e/go.mod h1:TlSL6QVxozmdRaSgP6Akspi0HCJv4HAkkq3Dldru4GM=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
|
|
|
@ -21,7 +21,7 @@ services:
|
||||||
garage:
|
garage:
|
||||||
# sync with deuxfleurs/nixcfg/cluster/prod/app/garage/deploy/garage.hcl
|
# sync with deuxfleurs/nixcfg/cluster/prod/app/garage/deploy/garage.hcl
|
||||||
# to ensure compatibility with prod
|
# to ensure compatibility with prod
|
||||||
image: superboum/garage:v1.0.0-rc1-hotfix-red-ftr-wquorum
|
image: dxflrs/garage:v1.99.1-internal
|
||||||
ports:
|
ports:
|
||||||
- "3900:3900"
|
- "3900:3900"
|
||||||
- "3902:3902"
|
- "3902:3902"
|
||||||
|
|
56
invite.go
56
invite.go
|
@ -1,19 +1,15 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/emersion/go-sasl"
|
|
||||||
"github.com/emersion/go-smtp"
|
|
||||||
"github.com/go-ldap/ldap/v3"
|
"github.com/go-ldap/ldap/v3"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"golang.org/x/crypto/argon2"
|
"golang.org/x/crypto/argon2"
|
||||||
|
@ -251,21 +247,11 @@ func handleInviteSendCode(w http.ResponseWriter, r *http.Request) {
|
||||||
WebBaseAddress: config.WebAddress,
|
WebBaseAddress: config.WebAddress,
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Method == "POST" {
|
tryGenerateInvitation(user, data)
|
||||||
r.ParseForm()
|
|
||||||
|
|
||||||
choice := strings.Join(r.Form["choice"], "")
|
|
||||||
sendto := strings.Join(r.Form["sendto"], "")
|
|
||||||
|
|
||||||
if choice == "display" || choice == "send" {
|
|
||||||
trySendCode(user, choice, sendto, data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
templateInviteSendCode.Execute(w, data)
|
templateInviteSendCode.Execute(w, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func trySendCode(user *LoggedUser, choice string, sendto string, data *SendCodeData) {
|
func tryGenerateInvitation(user *LoggedUser, data *SendCodeData) {
|
||||||
// Generate code
|
// Generate code
|
||||||
code, code_id, code_pw := genCode()
|
code, code_id, code_pw := genCode()
|
||||||
|
|
||||||
|
@ -286,43 +272,9 @@ func trySendCode(user *LoggedUser, choice string, sendto string, data *SendCodeD
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we want to display it, do so
|
|
||||||
if choice == "display" {
|
|
||||||
data.Success = true
|
|
||||||
data.CodeDisplay = code
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, we are sending a mail
|
|
||||||
if !EMAIL_REGEXP.MatchString(sendto) {
|
|
||||||
data.ErrorInvalidEmail = true
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
templateMail := template.Must(template.ParseFiles(templatePath + "/invite_mail.txt"))
|
|
||||||
buf := bytes.NewBuffer([]byte{})
|
|
||||||
templateMail.Execute(buf, &CodeMailFields{
|
|
||||||
To: sendto,
|
|
||||||
From: config.MailFrom,
|
|
||||||
InviteFrom: user.WelcomeName(),
|
|
||||||
Code: code,
|
|
||||||
WebBaseAddress: config.WebAddress,
|
|
||||||
})
|
|
||||||
|
|
||||||
log.Printf("Sending mail to: %s", sendto)
|
|
||||||
var auth sasl.Client = nil
|
|
||||||
if config.SMTPUsername != "" {
|
|
||||||
auth = sasl.NewPlainClient("", config.SMTPUsername, config.SMTPPassword)
|
|
||||||
}
|
|
||||||
err = smtp.SendMail(config.SMTPServer, auth, config.MailFrom, []string{sendto}, buf)
|
|
||||||
if err != nil {
|
|
||||||
data.ErrorMessage = err.Error()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.Printf("Mail sent.")
|
|
||||||
|
|
||||||
data.Success = true
|
data.Success = true
|
||||||
data.CodeSentTo = sendto
|
data.CodeDisplay = code
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func genCode() (code string, code_id string, code_pw string) {
|
func genCode() (code string, code_id string, code_pw string) {
|
||||||
|
|
|
@ -38,8 +38,7 @@
|
||||||
Inviter des gens sur Deuxfleurs
|
Inviter des gens sur Deuxfleurs
|
||||||
</div>
|
</div>
|
||||||
<div class="list-group list-group-flush">
|
<div class="list-group list-group-flush">
|
||||||
<a class="list-group-item list-group-item-action" href="/invite/send_code">Envoyer un code d'invitation</a>
|
<a class="list-group-item list-group-item-action" href="/invite/send_code">Générer un code d'invitation</a>
|
||||||
<a class="list-group-item list-group-item-action" href="/invite/new_account">Créer un nouveau compte directement</a>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
Loading…
Add table
Reference in a new issue