changed the return result of the confirm api actions
This commit is contained in:
parent
bc519231d9
commit
3d14addfef
|
@ -103,12 +103,12 @@ func (api *adminApi) confirmPasswordReset(c echo.Context) error {
|
||||||
return NewBadRequestError("An error occurred while loading the submitted data.", readErr)
|
return NewBadRequestError("An error occurred while loading the submitted data.", readErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
admin, submitErr := form.Submit()
|
_, submitErr := form.Submit()
|
||||||
if submitErr != nil {
|
if submitErr != nil {
|
||||||
return NewBadRequestError("Failed to set new password.", submitErr)
|
return NewBadRequestError("Failed to set new password.", submitErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
return api.authResponse(c, admin)
|
return c.NoContent(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *adminApi) list(c echo.Context) error {
|
func (api *adminApi) list(c echo.Context) error {
|
||||||
|
|
|
@ -198,15 +198,10 @@ func TestAdminConfirmPasswordReset(t *testing.T) {
|
||||||
"password":"1234567891",
|
"password":"1234567891",
|
||||||
"passwordConfirm":"1234567891"
|
"passwordConfirm":"1234567891"
|
||||||
}`),
|
}`),
|
||||||
ExpectedStatus: 200,
|
ExpectedStatus: 204,
|
||||||
ExpectedContent: []string{
|
|
||||||
`"admin":{"id":"sywbhecnh46rhm0"`,
|
|
||||||
`"token":`,
|
|
||||||
},
|
|
||||||
ExpectedEvents: map[string]int{
|
ExpectedEvents: map[string]int{
|
||||||
"OnModelBeforeUpdate": 1,
|
"OnModelBeforeUpdate": 1,
|
||||||
"OnModelAfterUpdate": 1,
|
"OnModelAfterUpdate": 1,
|
||||||
"OnAdminAuthRequest": 1,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -305,12 +305,12 @@ func (api *recordAuthApi) confirmPasswordReset(c echo.Context) error {
|
||||||
return NewBadRequestError("An error occurred while loading the submitted data.", readErr)
|
return NewBadRequestError("An error occurred while loading the submitted data.", readErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
record, submitErr := form.Submit()
|
_, submitErr := form.Submit()
|
||||||
if submitErr != nil {
|
if submitErr != nil {
|
||||||
return NewBadRequestError("Failed to set new password.", submitErr)
|
return NewBadRequestError("Failed to set new password.", submitErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
return api.authResponse(c, record, nil)
|
return c.NoContent(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *recordAuthApi) requestVerification(c echo.Context) error {
|
func (api *recordAuthApi) requestVerification(c echo.Context) error {
|
||||||
|
@ -350,18 +350,12 @@ func (api *recordAuthApi) confirmVerification(c echo.Context) error {
|
||||||
return NewBadRequestError("An error occurred while loading the submitted data.", readErr)
|
return NewBadRequestError("An error occurred while loading the submitted data.", readErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
record, submitErr := form.Submit()
|
_, submitErr := form.Submit()
|
||||||
if submitErr != nil {
|
if submitErr != nil {
|
||||||
return NewBadRequestError("An error occurred while submitting the form.", submitErr)
|
return NewBadRequestError("An error occurred while submitting the form.", submitErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't return an auth response if the collection doesn't allow email or username authentication
|
return c.NoContent(http.StatusNoContent)
|
||||||
authOptions := collection.AuthOptions()
|
|
||||||
if !authOptions.AllowEmailAuth && !authOptions.AllowUsernameAuth {
|
|
||||||
return c.NoContent(http.StatusNoContent)
|
|
||||||
}
|
|
||||||
|
|
||||||
return api.authResponse(c, record, nil)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *recordAuthApi) requestEmailChange(c echo.Context) error {
|
func (api *recordAuthApi) requestEmailChange(c echo.Context) error {
|
||||||
|
@ -393,12 +387,12 @@ func (api *recordAuthApi) confirmEmailChange(c echo.Context) error {
|
||||||
return NewBadRequestError("An error occurred while loading the submitted data.", readErr)
|
return NewBadRequestError("An error occurred while loading the submitted data.", readErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
record, submitErr := form.Submit()
|
_, submitErr := form.Submit()
|
||||||
if submitErr != nil {
|
if submitErr != nil {
|
||||||
return NewBadRequestError("Failed to confirm email change.", submitErr)
|
return NewBadRequestError("Failed to confirm email change.", submitErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
return api.authResponse(c, record, nil)
|
return c.NoContent(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *recordAuthApi) listExternalAuths(c echo.Context) error {
|
func (api *recordAuthApi) listExternalAuths(c echo.Context) error {
|
||||||
|
|
|
@ -458,27 +458,14 @@ func TestRecordAuthConfirmPasswordReset(t *testing.T) {
|
||||||
{
|
{
|
||||||
Name: "valid token and data",
|
Name: "valid token and data",
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Url: "/api/collections/users/confirm-password-reset?expand=rel,missing",
|
Url: "/api/collections/users/confirm-password-reset",
|
||||||
Body: strings.NewReader(`{
|
Body: strings.NewReader(`{
|
||||||
"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjRxMXhsY2xtZmxva3UzMyIsImVtYWlsIjoidGVzdEBleGFtcGxlLmNvbSIsImNvbGxlY3Rpb25JZCI6Il9wYl91c2Vyc19hdXRoXyIsInR5cGUiOiJhdXRoUmVjb3JkIiwiZXhwIjoyMjA4OTg1MjYxfQ.R_4FOSUHIuJQ5Crl3PpIPCXMsoHzuTaNlccpXg_3FOg",
|
"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjRxMXhsY2xtZmxva3UzMyIsImVtYWlsIjoidGVzdEBleGFtcGxlLmNvbSIsImNvbGxlY3Rpb25JZCI6Il9wYl91c2Vyc19hdXRoXyIsInR5cGUiOiJhdXRoUmVjb3JkIiwiZXhwIjoyMjA4OTg1MjYxfQ.R_4FOSUHIuJQ5Crl3PpIPCXMsoHzuTaNlccpXg_3FOg",
|
||||||
"password":"12345678",
|
"password":"12345678",
|
||||||
"passwordConfirm":"12345678"
|
"passwordConfirm":"12345678"
|
||||||
}`),
|
}`),
|
||||||
ExpectedStatus: 200,
|
ExpectedStatus: 204,
|
||||||
ExpectedContent: []string{
|
|
||||||
`"token":`,
|
|
||||||
`"record":`,
|
|
||||||
`"id":"4q1xlclmfloku33"`,
|
|
||||||
`"email":"test@example.com"`,
|
|
||||||
`"expand":`,
|
|
||||||
`"rel":`,
|
|
||||||
`"id":"llvuca81nly1qls"`,
|
|
||||||
},
|
|
||||||
NotExpectedContent: []string{
|
|
||||||
`"missing":`,
|
|
||||||
},
|
|
||||||
ExpectedEvents: map[string]int{
|
ExpectedEvents: map[string]int{
|
||||||
"OnRecordAuthRequest": 1,
|
|
||||||
"OnModelAfterUpdate": 1,
|
"OnModelAfterUpdate": 1,
|
||||||
"OnModelBeforeUpdate": 1,
|
"OnModelBeforeUpdate": 1,
|
||||||
},
|
},
|
||||||
|
@ -634,26 +621,12 @@ func TestRecordAuthConfirmVerification(t *testing.T) {
|
||||||
{
|
{
|
||||||
Name: "valid token",
|
Name: "valid token",
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Url: "/api/collections/users/confirm-verification?expand=rel,missing",
|
Url: "/api/collections/users/confirm-verification",
|
||||||
Body: strings.NewReader(`{
|
Body: strings.NewReader(`{
|
||||||
"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjRxMXhsY2xtZmxva3UzMyIsImVtYWlsIjoidGVzdEBleGFtcGxlLmNvbSIsImNvbGxlY3Rpb25JZCI6Il9wYl91c2Vyc19hdXRoXyIsInR5cGUiOiJhdXRoUmVjb3JkIiwiZXhwIjoyMjA4OTg1MjYxfQ.hL16TVmStHFdHLc4a860bRqJ3sFfzjv0_NRNzwsvsrc"
|
"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjRxMXhsY2xtZmxva3UzMyIsImVtYWlsIjoidGVzdEBleGFtcGxlLmNvbSIsImNvbGxlY3Rpb25JZCI6Il9wYl91c2Vyc19hdXRoXyIsInR5cGUiOiJhdXRoUmVjb3JkIiwiZXhwIjoyMjA4OTg1MjYxfQ.hL16TVmStHFdHLc4a860bRqJ3sFfzjv0_NRNzwsvsrc"
|
||||||
}`),
|
}`),
|
||||||
ExpectedStatus: 200,
|
ExpectedStatus: 204,
|
||||||
ExpectedContent: []string{
|
|
||||||
`"token":`,
|
|
||||||
`"record":`,
|
|
||||||
`"id":"4q1xlclmfloku33"`,
|
|
||||||
`"email":"test@example.com"`,
|
|
||||||
`"verified":true`,
|
|
||||||
`"expand":`,
|
|
||||||
`"rel":`,
|
|
||||||
`"id":"llvuca81nly1qls"`,
|
|
||||||
},
|
|
||||||
NotExpectedContent: []string{
|
|
||||||
`"missing":`,
|
|
||||||
},
|
|
||||||
ExpectedEvents: map[string]int{
|
ExpectedEvents: map[string]int{
|
||||||
"OnRecordAuthRequest": 1,
|
|
||||||
"OnModelAfterUpdate": 1,
|
"OnModelAfterUpdate": 1,
|
||||||
"OnModelBeforeUpdate": 1,
|
"OnModelBeforeUpdate": 1,
|
||||||
},
|
},
|
||||||
|
@ -661,30 +634,17 @@ func TestRecordAuthConfirmVerification(t *testing.T) {
|
||||||
{
|
{
|
||||||
Name: "valid token (already verified)",
|
Name: "valid token (already verified)",
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Url: "/api/collections/users/confirm-verification?expand=rel,missing",
|
Url: "/api/collections/users/confirm-verification",
|
||||||
Body: strings.NewReader(`{
|
Body: strings.NewReader(`{
|
||||||
"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6Im9hcDY0MGNvdDR5cnUycyIsImVtYWlsIjoidGVzdDJAZXhhbXBsZS5jb20iLCJjb2xsZWN0aW9uSWQiOiJfcGJfdXNlcnNfYXV0aF8iLCJ0eXBlIjoiYXV0aFJlY29yZCIsImV4cCI6MjIwODk4NTI2MX0.PsOABmYUzGbd088g8iIBL4-pf7DUZm0W5Ju6lL5JVRg"
|
"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6Im9hcDY0MGNvdDR5cnUycyIsImVtYWlsIjoidGVzdDJAZXhhbXBsZS5jb20iLCJjb2xsZWN0aW9uSWQiOiJfcGJfdXNlcnNfYXV0aF8iLCJ0eXBlIjoiYXV0aFJlY29yZCIsImV4cCI6MjIwODk4NTI2MX0.PsOABmYUzGbd088g8iIBL4-pf7DUZm0W5Ju6lL5JVRg"
|
||||||
}`),
|
}`),
|
||||||
ExpectedStatus: 200,
|
ExpectedStatus: 204,
|
||||||
ExpectedContent: []string{
|
ExpectedEvents: map[string]int{},
|
||||||
`"token":`,
|
|
||||||
`"record":`,
|
|
||||||
`"id":"oap640cot4yru2s"`,
|
|
||||||
`"email":"test2@example.com"`,
|
|
||||||
`"verified":true`,
|
|
||||||
},
|
|
||||||
NotExpectedContent: []string{
|
|
||||||
`"expand":`, // no rel id attached
|
|
||||||
`"missing":`,
|
|
||||||
},
|
|
||||||
ExpectedEvents: map[string]int{
|
|
||||||
"OnRecordAuthRequest": 1,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "valid verification token from a collection without allowed login",
|
Name: "valid verification token from a collection without allowed login",
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Url: "/api/collections/nologin/confirm-verification?expand=rel,missing",
|
Url: "/api/collections/nologin/confirm-verification",
|
||||||
Body: strings.NewReader(`{
|
Body: strings.NewReader(`{
|
||||||
"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImRjNDlrNmpnZWpuNDBoMyIsImVtYWlsIjoidGVzdEBleGFtcGxlLmNvbSIsImNvbGxlY3Rpb25JZCI6ImtwdjcwOXNrMmxxYnFrOCIsInR5cGUiOiJhdXRoUmVjb3JkIiwiZXhwIjoyMjA4OTg1MjYxfQ.coREjeTDS3_Go7DP1nxHtevIX5rujwHU-_mRB6oOm3w"
|
"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImRjNDlrNmpnZWpuNDBoMyIsImVtYWlsIjoidGVzdEBleGFtcGxlLmNvbSIsImNvbGxlY3Rpb25JZCI6ImtwdjcwOXNrMmxxYnFrOCIsInR5cGUiOiJhdXRoUmVjb3JkIiwiZXhwIjoyMjA4OTg1MjYxfQ.coREjeTDS3_Go7DP1nxHtevIX5rujwHU-_mRB6oOm3w"
|
||||||
}`),
|
}`),
|
||||||
|
@ -871,16 +831,8 @@ func TestRecordAuthConfirmEmailChange(t *testing.T) {
|
||||||
"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjRxMXhsY2xtZmxva3UzMyIsImNvbGxlY3Rpb25JZCI6Il9wYl91c2Vyc19hdXRoXyIsInR5cGUiOiJhdXRoUmVjb3JkIiwiZW1haWwiOiJ0ZXN0QGV4YW1wbGUuY29tIiwibmV3RW1haWwiOiJjaGFuZ2VAZXhhbXBsZS5jb20iLCJleHAiOjIyMDg5ODUyNjF9.1sG6cL708pRXXjiHRZhG-in0X5fnttSf5nNcadKoYRs",
|
"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjRxMXhsY2xtZmxva3UzMyIsImNvbGxlY3Rpb25JZCI6Il9wYl91c2Vyc19hdXRoXyIsInR5cGUiOiJhdXRoUmVjb3JkIiwiZW1haWwiOiJ0ZXN0QGV4YW1wbGUuY29tIiwibmV3RW1haWwiOiJjaGFuZ2VAZXhhbXBsZS5jb20iLCJleHAiOjIyMDg5ODUyNjF9.1sG6cL708pRXXjiHRZhG-in0X5fnttSf5nNcadKoYRs",
|
||||||
"password":"1234567890"
|
"password":"1234567890"
|
||||||
}`),
|
}`),
|
||||||
ExpectedStatus: 200,
|
ExpectedStatus: 204,
|
||||||
ExpectedContent: []string{
|
|
||||||
`"token":`,
|
|
||||||
`"record":`,
|
|
||||||
`"id":"4q1xlclmfloku33"`,
|
|
||||||
`"email":"change@example.com"`,
|
|
||||||
`"verified":true`,
|
|
||||||
},
|
|
||||||
ExpectedEvents: map[string]int{
|
ExpectedEvents: map[string]int{
|
||||||
"OnRecordAuthRequest": 1,
|
|
||||||
"OnModelAfterUpdate": 1,
|
"OnModelAfterUpdate": 1,
|
||||||
"OnModelBeforeUpdate": 1,
|
"OnModelBeforeUpdate": 1,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue