-
-
Notifications
You must be signed in to change notification settings - Fork 617
/
invite.go
50 lines (42 loc) · 1.4 KB
/
invite.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package handlers
import (
"strings"
"github.com/getfider/fider/app"
"github.com/getfider/fider/app/actions"
"github.com/getfider/fider/app/pkg/email"
"github.com/getfider/fider/app/pkg/markdown"
"github.com/getfider/fider/app/pkg/web"
"github.com/getfider/fider/app/tasks"
)
// SendSampleInvite to current user's email
func SendSampleInvite() web.HandlerFunc {
return func(c web.Context) error {
input := &actions.InviteUsers{IsSampleInvite: true}
if result := c.BindTo(input); !result.Ok {
return c.HandleValidation(result)
}
if c.User().Email != "" {
input.Model.Message = strings.Replace(input.Model.Message, app.InvitePlaceholder, "*the link to accept invitation will be here*", -1)
to := email.NewRecipient(c.User().Name, c.User().Email, email.Params{
"subject": input.Model.Subject,
"message": markdown.Parse(input.Model.Message),
})
err := c.Services().Emailer.Send(c.Tenant(), "invite_email", email.Params{}, c.Tenant().Name, to)
if err != nil {
return c.Failure(err)
}
}
return c.Ok(web.Map{})
}
}
// SendInvites sends an email to each recipient
func SendInvites() web.HandlerFunc {
return func(c web.Context) error {
input := new(actions.InviteUsers)
if result := c.BindTo(input); !result.Ok {
return c.HandleValidation(result)
}
c.Enqueue(tasks.SendInvites(input.Model.Subject, input.Model.Message, input.Invitations))
return c.Ok(web.Map{})
}
}