Make logic clearer, improve comments

Signed-off-by: Anant Prakash <anantprakashjsr@gmail.com>
This commit is contained in:
Anant Prakash 2018-03-15 00:25:21 +05:30
parent 7ce94121ad
commit ad367e8edb
No known key found for this signature in database
GPG key ID: C5D399F626523045

View file

@ -63,7 +63,7 @@ func VerifyUserFromRequest(
return dev.UserID, nil return dev.UserID, nil
} }
// Try to find Application Service user // Try to find the Application Service user
token, err := extractAccessToken(req) token, err := extractAccessToken(req)
if err != nil { if err != nil {
@ -96,14 +96,8 @@ func VerifyUserFromRequest(
// Verify that the user is registered // Verify that the user is registered
account, accountErr := accountDB.GetAccountByLocalpart(req.Context(), localpart) account, accountErr := accountDB.GetAccountByLocalpart(req.Context(), localpart)
if accountErr != nil { // Verify that account exists & appServiceID matches
return "", &util.JSONResponse{ if accountErr == nil && account.AppServiceID == appService.ID {
Code: http.StatusForbidden,
JSON: jsonerror.Forbidden("Application service has not registered this user"),
}
}
if account.AppServiceID == appService.ID {
return userID, nil return userID, nil
} }