-
Notifications
You must be signed in to change notification settings - Fork 11
/
utils.go
44 lines (37 loc) · 1.14 KB
/
utils.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
package main
import (
"io"
"net/url"
"github.com/labstack/echo"
)
func ValidateService(c echo.Context) *url.URL {
service, err := url.Parse(c.QueryParam("service"))
// TODO: add service validation if needed
if err != nil {
service = nil
}
return service
}
func NewTemplateGlobal() *TemplateGlobal {
templateGlobal := new(TemplateGlobal)
templateGlobal.CASLogin = GetCasLoginUrl("http://" + *OSFHost + "/dashboard")
templateGlobal.OSFCreateAccount = GetOsfUrl("/register")
templateGlobal.OSFDomain = GetOsfUrl("/")
templateGlobal.OSFForgotPassword = GetOsfUrl("/forgotpassword")
templateGlobal.OSFInstitutionLogin = GetOsfUrl("/login?campaign=institution")
templateGlobal.OSFResendConfirmation = GetOsfUrl("/resend")
return templateGlobal
}
func GetOsfUrl(path string) string {
osfUrl, err := url.Parse("http://" + *OSFHost + path)
if err != nil {
panic(err)
}
return osfUrl.String()
}
func GetCasLoginUrl(service string) string {
return "/login?service=" + url.QueryEscape(service)
}
func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
return t.templates.ExecuteTemplate(w, name, data)
}