backend: fixed wrong error codes
This commit is contained in:
@@ -14,6 +14,7 @@ const (
|
|||||||
MailRegistrationSubject = "Neues Mitglied hat sich registriert"
|
MailRegistrationSubject = "Neues Mitglied hat sich registriert"
|
||||||
MailWelcomeSubject = "Willkommen beim Dörpsmobil Hasloh e.V."
|
MailWelcomeSubject = "Willkommen beim Dörpsmobil Hasloh e.V."
|
||||||
MailContactSubject = "Jemand hat das Kontaktformular gefunden"
|
MailContactSubject = "Jemand hat das Kontaktformular gefunden"
|
||||||
|
SupporterSubscriptionModelName = "Keins"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Licences = struct {
|
var Licences = struct {
|
||||||
|
|||||||
@@ -274,7 +274,11 @@ func (uc *UserController) RegisterUser(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if regData.User.Membership.SubscriptionModel.Name == constants.SupporterSubscriptionModelName {
|
||||||
|
regData.User.RoleID = constants.Roles.Supporter
|
||||||
|
} else {
|
||||||
regData.User.RoleID = constants.Roles.Member
|
regData.User.RoleID = constants.Roles.Member
|
||||||
|
}
|
||||||
|
|
||||||
// Register User
|
// Register User
|
||||||
id, token, err := uc.Service.RegisterUser(®Data.User)
|
id, token, err := uc.Service.RegisterUser(®Data.User)
|
||||||
@@ -288,6 +292,16 @@ func (uc *UserController) RegisterUser(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
regData.User.ID = id
|
regData.User.ID = id
|
||||||
|
|
||||||
|
// if this is a supporter don't send mails and he never did give any consent. So stop here
|
||||||
|
if regData.User.RoleID == constants.Roles.Supporter {
|
||||||
|
|
||||||
|
c.JSON(http.StatusCreated, gin.H{
|
||||||
|
"message": "Supporter Registration successuful",
|
||||||
|
"id": regData.User.ID,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Register Consents
|
// Register Consents
|
||||||
var consents = [2]models.Consent{
|
var consents = [2]models.Consent{
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -316,7 +316,7 @@ func testCurrentUserHandler(t *testing.T, loginEmail string, loginCookie http.Co
|
|||||||
setupCookie: func(req *http.Request) {},
|
setupCookie: func(req *http.Request) {},
|
||||||
expectedStatus: http.StatusUnauthorized,
|
expectedStatus: http.StatusUnauthorized,
|
||||||
expectedErrors: []map[string]string{
|
expectedErrors: []map[string]string{
|
||||||
{"field": "general", "key": "server.error.no_auth_token"},
|
{"field": "server.general", "key": "server.error.no_auth_token"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -326,7 +326,7 @@ func testCurrentUserHandler(t *testing.T, loginEmail string, loginCookie http.Co
|
|||||||
},
|
},
|
||||||
expectedStatus: http.StatusUnauthorized,
|
expectedStatus: http.StatusUnauthorized,
|
||||||
expectedErrors: []map[string]string{
|
expectedErrors: []map[string]string{
|
||||||
{"field": "general", "key": "server.error.no_auth_token"},
|
{"field": "server.general", "key": "server.error.no_auth_token"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -507,7 +507,7 @@ func testUpdateUser(t *testing.T, loginCookie http.Cookie, adminCookie http.Cook
|
|||||||
},
|
},
|
||||||
expectedStatus: http.StatusUnauthorized,
|
expectedStatus: http.StatusUnauthorized,
|
||||||
expectedErrors: []map[string]string{
|
expectedErrors: []map[string]string{
|
||||||
{"field": "general", "key": "server.error.no_auth_token"},
|
{"field": "server.general", "key": "server.error.no_auth_token"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -948,7 +948,7 @@ func verifyMail(verificationURL string) error {
|
|||||||
router := gin.New()
|
router := gin.New()
|
||||||
router.LoadHTMLGlob(filepath.Join(config.Templates.HTMLPath, "*"))
|
router.LoadHTMLGlob(filepath.Join(config.Templates.HTMLPath, "*"))
|
||||||
|
|
||||||
router.GET("/users/verify", Uc.VerifyMailHandler)
|
router.GET("api/users/verify", Uc.VerifyMailHandler)
|
||||||
wv := httptest.NewRecorder()
|
wv := httptest.NewRecorder()
|
||||||
cv, _ := gin.CreateTestContext(wv)
|
cv, _ := gin.CreateTestContext(wv)
|
||||||
var err error
|
var err error
|
||||||
|
|||||||
@@ -91,8 +91,8 @@ func Open(dbPath string, adminMail string) error {
|
|||||||
func createSubscriptionModels() []models.SubscriptionModel {
|
func createSubscriptionModels() []models.SubscriptionModel {
|
||||||
return []models.SubscriptionModel{
|
return []models.SubscriptionModel{
|
||||||
{
|
{
|
||||||
Name: "Keins",
|
Name: constants.SupporterSubscriptionModelName,
|
||||||
Details: "Dieses Modell ist für Vereinsmitglieder, die keinen Wunsch haben, an dem Carhsharing teilzunehmen.",
|
Details: "Dieses Modell ist für Sponsoren und Nichtmitglieder, die keinen Vereinsmitglied sind.",
|
||||||
HourlyRate: 999,
|
HourlyRate: 999,
|
||||||
MonthlyFee: 0,
|
MonthlyFee: 0,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ func AuthMiddleware() gin.HandlerFunc {
|
|||||||
logger.Error.Printf("No Auth token: %v\n", err)
|
logger.Error.Printf("No Auth token: %v\n", err)
|
||||||
c.JSON(http.StatusUnauthorized,
|
c.JSON(http.StatusUnauthorized,
|
||||||
gin.H{"errors": []gin.H{{
|
gin.H{"errors": []gin.H{{
|
||||||
"field": "general",
|
"field": "server.general",
|
||||||
"key": "server.error.no_auth_token",
|
"key": "server.error.no_auth_token",
|
||||||
}}})
|
}}})
|
||||||
c.Abort()
|
c.Abort()
|
||||||
@@ -97,7 +97,7 @@ func AuthMiddleware() gin.HandlerFunc {
|
|||||||
logger.Error.Printf("Token(%v) is invalid: %v\n", tokenString, err)
|
logger.Error.Printf("Token(%v) is invalid: %v\n", tokenString, err)
|
||||||
c.JSON(http.StatusUnauthorized,
|
c.JSON(http.StatusUnauthorized,
|
||||||
gin.H{"errors": []gin.H{{
|
gin.H{"errors": []gin.H{{
|
||||||
"field": "general",
|
"field": "server.general",
|
||||||
"key": "server.error.no_auth_token",
|
"key": "server.error.no_auth_token",
|
||||||
}}})
|
}}})
|
||||||
c.Abort()
|
c.Abort()
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func HandleValidationError(c *gin.Context, err error) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
validationErrors = append(validationErrors, gin.H{
|
validationErrors = append(validationErrors, gin.H{
|
||||||
"field": "general",
|
"field": "server.general",
|
||||||
"key": "server.error.invalid_json",
|
"key": "server.error.invalid_json",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ func ValidateSubscription(sl validator.StructLevel) {
|
|||||||
// This is a nested probably user struct. We are only checking if the model exists
|
// This is a nested probably user struct. We are only checking if the model exists
|
||||||
existingSubscription, err := repositories.GetSubscriptionByName(&subscription.Name)
|
existingSubscription, err := repositories.GetSubscriptionByName(&subscription.Name)
|
||||||
if err != nil || existingSubscription == nil {
|
if err != nil || existingSubscription == nil {
|
||||||
sl.ReportError(subscription.Name, "Subscription_Name", "name", "exists", "")
|
sl.ReportError(subscription.Name, "subscription.name", "name", "duplicate", "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,17 +23,17 @@ func validateUser(sl validator.StructLevel) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Validate User > 18 years old
|
// Validate User > 18 years old
|
||||||
if user.DateOfBirth.After(time.Now().AddDate(-18, 0, 0)) {
|
if user.RoleID > constants.Roles.Supporter && user.DateOfBirth.After(time.Now().AddDate(-18, 0, 0)) {
|
||||||
sl.ReportError(user.DateOfBirth, "DateOfBirth", "dateofbirth", "age", "")
|
sl.ReportError(user.DateOfBirth, "user.user", "user.dateofbirth", "age", "")
|
||||||
}
|
}
|
||||||
// validate subscriptionModel
|
// validate subscriptionModel
|
||||||
if user.Membership.SubscriptionModel.Name == "" {
|
if user.Membership.SubscriptionModel.Name == "" {
|
||||||
sl.ReportError(user.Membership.SubscriptionModel.Name, "SubscriptionModel.Name", "name", "required", "")
|
sl.ReportError(user.Membership.SubscriptionModel.Name, "subscription.name", "name", "required", "")
|
||||||
} else {
|
} else {
|
||||||
selectedModel, err := repositories.GetSubscriptionByName(&user.Membership.SubscriptionModel.Name)
|
selectedModel, err := repositories.GetSubscriptionByName(&user.Membership.SubscriptionModel.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error.Printf("Error finding subscription model for user %v: %v", user.Email, err)
|
logger.Error.Printf("Error finding subscription model for user %v: %v", user.Email, err)
|
||||||
sl.ReportError(user.Membership.SubscriptionModel.Name, "SubscriptionModel.Name", "name", "invalid", "")
|
sl.ReportError(user.Membership.SubscriptionModel.Name, "subscription.name", "name", "invalid", "")
|
||||||
} else {
|
} else {
|
||||||
user.Membership.SubscriptionModel = *selectedModel
|
user.Membership.SubscriptionModel = *selectedModel
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,7 @@ func validateUser(sl validator.StructLevel) {
|
|||||||
validateMembership(sl)
|
validateMembership(sl)
|
||||||
if !isSuper {
|
if !isSuper {
|
||||||
validateBankAccount(sl)
|
validateBankAccount(sl)
|
||||||
if user.Licence != nil {
|
if user.Licence != nil && user.RoleID > constants.Roles.Supporter {
|
||||||
validateDriverslicence(sl)
|
validateDriverslicence(sl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ var Responses = struct {
|
|||||||
UndeliveredVerificationMail: "server.error.undelivered_verification_mail",
|
UndeliveredVerificationMail: "server.error.undelivered_verification_mail",
|
||||||
},
|
},
|
||||||
Fields: ValidationFields{
|
Fields: ValidationFields{
|
||||||
General: "general",
|
General: "server.general",
|
||||||
ParentMemberShipID: "parent_membership_id",
|
ParentMemberShipID: "parent_membership_id",
|
||||||
SubscriptionModel: "subscription_model",
|
SubscriptionModel: "subscription_model",
|
||||||
Login: "user.login",
|
Login: "user.login",
|
||||||
|
|||||||
Reference in New Issue
Block a user