RedirectToLogin redirects the user to the login page with the `message` and `redirect` query parameters set. If dashboardURL is nil, the redirect will be relative to the current request's host. If it is not nil, the redirect will be absolute with dashboard url as the host.
(rw http.ResponseWriter, r *http.Request, dashboardURL *url.URL, message string)
| 1001 | // request's host. If it is not nil, the redirect will be absolute with dashboard |
| 1002 | // url as the host. |
| 1003 | func RedirectToLogin(rw http.ResponseWriter, r *http.Request, dashboardURL *url.URL, message string) { |
| 1004 | path := r.URL.Path |
| 1005 | if r.URL.RawQuery != "" { |
| 1006 | path += "?" + r.URL.RawQuery |
| 1007 | } |
| 1008 | |
| 1009 | q := url.Values{} |
| 1010 | q.Add("message", message) |
| 1011 | q.Add("redirect", path) |
| 1012 | |
| 1013 | u := &url.URL{ |
| 1014 | Path: "/login", |
| 1015 | RawQuery: q.Encode(), |
| 1016 | } |
| 1017 | // If dashboardURL is provided, we want to redirect to the dashboard |
| 1018 | // login page. |
| 1019 | if dashboardURL != nil { |
| 1020 | cpy := *dashboardURL |
| 1021 | cpy.Path = u.Path |
| 1022 | cpy.RawQuery = u.RawQuery |
| 1023 | u = &cpy |
| 1024 | } |
| 1025 | |
| 1026 | // See other forces a GET request rather than keeping the current method |
| 1027 | // (like temporary redirect does). |
| 1028 | http.Redirect(rw, r, u.String(), http.StatusSeeOther) |
| 1029 | } |
| 1030 | |
| 1031 | // CustomRedirectToLogin redirects the user to the login page with the `message` and |
| 1032 | // `redirect` query parameters set, with a provided code |
no test coverage detected