(w http.ResponseWriter, r *http.Request)
| 135 | } |
| 136 | |
| 137 | func loginHandler(w http.ResponseWriter, r *http.Request) { |
| 138 | if commonHandler(w, r) { |
| 139 | return |
| 140 | } |
| 141 | |
| 142 | // Pass in PoorMan's auth, IP information if present. |
| 143 | ctx := x.AttachRemoteIP(context.Background(), r) |
| 144 | ctx = x.AttachAuthToken(ctx, r) |
| 145 | |
| 146 | body := readRequest(w, r) |
| 147 | loginReq := api.LoginRequest{} |
| 148 | if err := json.Unmarshal(body, &loginReq); err != nil { |
| 149 | x.SetStatusWithData(w, x.Error, err.Error()) |
| 150 | return |
| 151 | } |
| 152 | |
| 153 | resp, err := (&edgraph.Server{}).Login(ctx, &loginReq) |
| 154 | if err != nil { |
| 155 | x.SetStatusWithData(w, x.ErrorInvalidRequest, err.Error()) |
| 156 | return |
| 157 | } |
| 158 | |
| 159 | jwt := &api.Jwt{} |
| 160 | if err := proto.Unmarshal(resp.Json, jwt); err != nil { |
| 161 | x.SetStatusWithData(w, x.Error, err.Error()) |
| 162 | return |
| 163 | } |
| 164 | |
| 165 | response := map[string]interface{}{} |
| 166 | mp := make(map[string]string) |
| 167 | mp["accessJWT"] = jwt.AccessJwt |
| 168 | mp["refreshJWT"] = jwt.RefreshJwt |
| 169 | response["data"] = mp |
| 170 | |
| 171 | js, err := json.Marshal(response) |
| 172 | if err != nil { |
| 173 | x.SetStatusWithData(w, x.Error, err.Error()) |
| 174 | return |
| 175 | } |
| 176 | |
| 177 | if _, err := x.WriteResponse(w, r, js); err != nil { |
| 178 | glog.Errorf("Error while writing response: %v", err) |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | // This method should just build the request and proxy it to the Query method of dgraph.Server. |
| 183 | // It can then encode the response as appropriate before sending it back to the user. |
nothing calls this directly
no test coverage detected