-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoptions.go
71 lines (61 loc) · 1.81 KB
/
options.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package maildoor
import "net/http"
// option for the auth
type option func(*maildoor)
// Logo sets the logo url for the login page and the email
// that will be sent to the user.
func Logo(l string) option {
return func(m *maildoor) {
m.logoURL = l
}
}
// ProductName allows to specify the product name used
// in emails and pages.
func ProductName(p string) option {
return func(m *maildoor) {
m.productName = p
}
}
// Prefix sets the prefix for the routes. By default it is /auth/.
func Prefix(p string) option {
return func(m *maildoor) {
m.patternPrefix = p
}
}
func Icon(i string) option {
return func(m *maildoor) {
m.iconURL = i
}
}
// AfterLogin sets the function to be executed after login
// this is useful to set a cookie or a session for the user
// after the login is successful and redirect to secure area.
func AfterLogin(fn func(http.ResponseWriter, *http.Request)) option {
return func(m *maildoor) {
m.afterLogin = fn
}
}
// Logout sets the function to be executed after logout
// this is useful to clear the session or cookie for the user
// and redirect to the login page. By default it redirects to
// the root of the app (/).
func Logout(fn func(http.ResponseWriter, *http.Request)) option {
return func(m *maildoor) {
m.logout = fn
}
}
// EmailValidator sets the function to validate the email
// it can be replaced with a custom function.
func EmailValidator(fn func(email string) error) option {
return func(m *maildoor) {
m.emailValidator = fn
}
}
// EmailSender is the function that will be called after the email
// has been determined to be valid. so the app can send the email to
// the user with the token. Txt and html are the email body in plain text and html format.
func EmailSender(fn func(to, html, txt string) error) option {
return func(m *maildoor) {
m.emailSender = fn
}
}