()
| 85 | } |
| 86 | |
| 87 | func (h *handler) getUserFromSessionRequestBody() (auth.User, error) { |
| 88 | |
| 89 | var params struct { |
| 90 | Name string `json:"name"` |
| 91 | Password string `json:"password"` |
| 92 | } |
| 93 | err := h.readJSONInto(¶ms) |
| 94 | if err != nil { |
| 95 | return nil, err |
| 96 | } |
| 97 | |
| 98 | var user auth.User |
| 99 | user, err = h.db.Authenticator(h.ctx()).GetUser(params.Name) |
| 100 | if err != nil { |
| 101 | return nil, err |
| 102 | } |
| 103 | |
| 104 | if user == nil { |
| 105 | base.InfofCtx(h.ctx(), base.KeyAuth, "Couldn't create session for user %q: not found", base.UD(params.Name)) |
| 106 | return nil, nil |
| 107 | } |
| 108 | |
| 109 | authenticated, reason := user.AuthenticateWithReason(params.Password) |
| 110 | if !authenticated { |
| 111 | base.InfofCtx(h.ctx(), base.KeyAuth, "Couldn't create session for user %q: %s", base.UD(params.Name), reason) |
| 112 | return nil, nil |
| 113 | } |
| 114 | |
| 115 | return user, nil |
| 116 | } |
| 117 | |
| 118 | // DELETE /_session logs out the current session |
| 119 | func (h *handler) handleSessionDELETE() error { |
no test coverage detected