aboutsummaryrefslogtreecommitdiff
path: root/invite.go
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2023-09-25 15:35:54 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2023-09-25 15:35:54 +0200
commitc06f52837e5b4aab5335e5a66885c48c24a148a2 (patch)
treed519f4e53c08e9de2fc3c30606031960c53429fe /invite.go
parentd0ed765be72f80034fa530ba037e488c35abdd9e (diff)
downloadguichet-c06f52837e5b4aab5335e5a66885c48c24a148a2.tar.gz
guichet-c06f52837e5b4aab5335e5a66885c48c24a148a2.zip
WIP refactor (broken templates)
Diffstat (limited to 'invite.go')
-rw-r--r--invite.go36
1 files changed, 18 insertions, 18 deletions
diff --git a/invite.go b/invite.go
index 1384d70..0a0e836 100644
--- a/invite.go
+++ b/invite.go
@@ -21,29 +21,29 @@ import (
var EMAIL_REGEXP = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
-func checkInviterLogin(w http.ResponseWriter, r *http.Request) *LoginStatus {
- login := checkLogin(w, r)
- if login == nil {
+func checkInviterLogin(w http.ResponseWriter, r *http.Request) *LoggedUser {
+ user := RequireUserHtml(w, r)
+ if user == nil {
return nil
}
- if !login.CanInvite {
+ if !user.Capabilities.CanInvite {
http.Error(w, "Not authorized to invite new users.", http.StatusUnauthorized)
return nil
}
- return login
+ return user
}
// New account creation directly from interface
func handleInviteNewAccount(w http.ResponseWriter, r *http.Request) {
- login := checkInviterLogin(w, r)
- if login == nil {
+ user := checkInviterLogin(w, r)
+ if user == nil {
return
}
- handleNewAccount(w, r, login.conn, login.Info.DN)
+ handleNewAccount(w, r, user.Login.conn, user.Login.Info.DN())
}
// New account creation using code
@@ -52,13 +52,13 @@ func handleInvitationCode(w http.ResponseWriter, r *http.Request) {
code := mux.Vars(r)["code"]
code_id, code_pw := readCode(code)
- l := ldapOpen(w)
- if l == nil {
- return
+ l, err := NewLdapCon()
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
}
inviteDn := config.InvitationNameAttr + "=" + code_id + "," + config.InvitationBaseDN
- err := l.Bind(inviteDn, code_pw)
+ err = l.Bind(inviteDn, code_pw)
if err != nil {
templateInviteInvalidCode := getTemplate("invite_invalid_code.html")
templateInviteInvalidCode.Execute(w, nil)
@@ -241,8 +241,8 @@ type CodeMailFields struct {
func handleInviteSendCode(w http.ResponseWriter, r *http.Request) {
templateInviteSendCode := getTemplate("invite_send_code.html")
- login := checkInviterLogin(w, r)
- if login == nil {
+ user := checkInviterLogin(w, r)
+ if user == nil {
return
}
@@ -257,14 +257,14 @@ func handleInviteSendCode(w http.ResponseWriter, r *http.Request) {
sendto := strings.Join(r.Form["sendto"], "")
if choice == "display" || choice == "send" {
- trySendCode(login, choice, sendto, data)
+ trySendCode(user, choice, sendto, data)
}
}
templateInviteSendCode.Execute(w, data)
}
-func trySendCode(login *LoginStatus, choice string, sendto string, data *SendCodeData) {
+func trySendCode(user *LoggedUser, choice string, sendto string, data *SendCodeData) {
// Generate code
code, code_id, code_pw := genCode()
@@ -279,7 +279,7 @@ func trySendCode(login *LoginStatus, choice string, sendto string, data *SendCod
req.Attribute("userpassword", []string{pw})
req.Attribute("objectclass", []string{"top", "invitationCode"})
- err = login.conn.Add(req)
+ err = user.Login.conn.Add(req)
if err != nil {
data.ErrorMessage = err.Error()
return
@@ -303,7 +303,7 @@ func trySendCode(login *LoginStatus, choice string, sendto string, data *SendCod
templateMail.Execute(buf, &CodeMailFields{
To: sendto,
From: config.MailFrom,
- InviteFrom: login.WelcomeName(),
+ InviteFrom: user.WelcomeName(),
Code: code,
WebBaseAddress: config.WebAddress,
})