(tokenExpireTime time.Duration)
| 121 | } |
| 122 | |
| 123 | func loginHandler(tokenExpireTime time.Duration) handleFunc { |
| 124 | return func(w http.ResponseWriter, r *http.Request, d *data) (int, error) { |
| 125 | if r.Body != nil { |
| 126 | r.Body = http.MaxBytesReader(w, r.Body, maxAuthBodySize) |
| 127 | } |
| 128 | |
| 129 | auther, err := d.store.Auth.Get(d.settings.AuthMethod) |
| 130 | if err != nil { |
| 131 | return http.StatusInternalServerError, err |
| 132 | } |
| 133 | |
| 134 | user, err := auther.Auth(r, d.store.Users, d.settings, d.server) |
| 135 | switch { |
| 136 | case errors.Is(err, os.ErrPermission): |
| 137 | return http.StatusForbidden, nil |
| 138 | case err != nil: |
| 139 | return http.StatusInternalServerError, err |
| 140 | } |
| 141 | |
| 142 | return printToken(w, r, d, user, tokenExpireTime) |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | type signupBody struct { |
| 147 | Username string `json:"username"` |
no test coverage detected