backend: fixed wrong error codes
This commit is contained in:
@@ -9,11 +9,12 @@ const (
|
||||
DelayedPaymentStatus
|
||||
SettledPaymentStatus
|
||||
AwaitingPaymentStatus
|
||||
MailVerificationSubject = "Nur noch ein kleiner Schritt!"
|
||||
MailChangePasswordSubject = "Passwort Änderung angefordert"
|
||||
MailRegistrationSubject = "Neues Mitglied hat sich registriert"
|
||||
MailWelcomeSubject = "Willkommen beim Dörpsmobil Hasloh e.V."
|
||||
MailContactSubject = "Jemand hat das Kontaktformular gefunden"
|
||||
MailVerificationSubject = "Nur noch ein kleiner Schritt!"
|
||||
MailChangePasswordSubject = "Passwort Änderung angefordert"
|
||||
MailRegistrationSubject = "Neues Mitglied hat sich registriert"
|
||||
MailWelcomeSubject = "Willkommen beim Dörpsmobil Hasloh e.V."
|
||||
MailContactSubject = "Jemand hat das Kontaktformular gefunden"
|
||||
SupporterSubscriptionModelName = "Keins"
|
||||
)
|
||||
|
||||
var Licences = struct {
|
||||
|
||||
@@ -274,7 +274,11 @@ func (uc *UserController) RegisterUser(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
}
|
||||
regData.User.RoleID = constants.Roles.Member
|
||||
if regData.User.Membership.SubscriptionModel.Name == constants.SupporterSubscriptionModelName {
|
||||
regData.User.RoleID = constants.Roles.Supporter
|
||||
} else {
|
||||
regData.User.RoleID = constants.Roles.Member
|
||||
}
|
||||
|
||||
// Register User
|
||||
id, token, err := uc.Service.RegisterUser(®Data.User)
|
||||
@@ -288,6 +292,16 @@ func (uc *UserController) RegisterUser(c *gin.Context) {
|
||||
}
|
||||
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
|
||||
var consents = [2]models.Consent{
|
||||
{
|
||||
|
||||
@@ -316,7 +316,7 @@ func testCurrentUserHandler(t *testing.T, loginEmail string, loginCookie http.Co
|
||||
setupCookie: func(req *http.Request) {},
|
||||
expectedStatus: http.StatusUnauthorized,
|
||||
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,
|
||||
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,
|
||||
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.LoadHTMLGlob(filepath.Join(config.Templates.HTMLPath, "*"))
|
||||
|
||||
router.GET("/users/verify", Uc.VerifyMailHandler)
|
||||
router.GET("api/users/verify", Uc.VerifyMailHandler)
|
||||
wv := httptest.NewRecorder()
|
||||
cv, _ := gin.CreateTestContext(wv)
|
||||
var err error
|
||||
|
||||
@@ -91,8 +91,8 @@ func Open(dbPath string, adminMail string) error {
|
||||
func createSubscriptionModels() []models.SubscriptionModel {
|
||||
return []models.SubscriptionModel{
|
||||
{
|
||||
Name: "Keins",
|
||||
Details: "Dieses Modell ist für Vereinsmitglieder, die keinen Wunsch haben, an dem Carhsharing teilzunehmen.",
|
||||
Name: constants.SupporterSubscriptionModelName,
|
||||
Details: "Dieses Modell ist für Sponsoren und Nichtmitglieder, die keinen Vereinsmitglied sind.",
|
||||
HourlyRate: 999,
|
||||
MonthlyFee: 0,
|
||||
},
|
||||
|
||||
@@ -80,7 +80,7 @@ func AuthMiddleware() gin.HandlerFunc {
|
||||
logger.Error.Printf("No Auth token: %v\n", err)
|
||||
c.JSON(http.StatusUnauthorized,
|
||||
gin.H{"errors": []gin.H{{
|
||||
"field": "general",
|
||||
"field": "server.general",
|
||||
"key": "server.error.no_auth_token",
|
||||
}}})
|
||||
c.Abort()
|
||||
@@ -97,7 +97,7 @@ func AuthMiddleware() gin.HandlerFunc {
|
||||
logger.Error.Printf("Token(%v) is invalid: %v\n", tokenString, err)
|
||||
c.JSON(http.StatusUnauthorized,
|
||||
gin.H{"errors": []gin.H{{
|
||||
"field": "general",
|
||||
"field": "server.general",
|
||||
"key": "server.error.no_auth_token",
|
||||
}}})
|
||||
c.Abort()
|
||||
|
||||
@@ -30,7 +30,7 @@ func HandleValidationError(c *gin.Context, err error) {
|
||||
}
|
||||
} else {
|
||||
validationErrors = append(validationErrors, gin.H{
|
||||
"field": "general",
|
||||
"field": "server.general",
|
||||
"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
|
||||
existingSubscription, err := repositories.GetSubscriptionByName(&subscription.Name)
|
||||
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
|
||||
if user.DateOfBirth.After(time.Now().AddDate(-18, 0, 0)) {
|
||||
sl.ReportError(user.DateOfBirth, "DateOfBirth", "dateofbirth", "age", "")
|
||||
if user.RoleID > constants.Roles.Supporter && user.DateOfBirth.After(time.Now().AddDate(-18, 0, 0)) {
|
||||
sl.ReportError(user.DateOfBirth, "user.user", "user.dateofbirth", "age", "")
|
||||
}
|
||||
// validate subscriptionModel
|
||||
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 {
|
||||
selectedModel, err := repositories.GetSubscriptionByName(&user.Membership.SubscriptionModel.Name)
|
||||
if err != nil {
|
||||
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 {
|
||||
user.Membership.SubscriptionModel = *selectedModel
|
||||
}
|
||||
@@ -42,7 +42,7 @@ func validateUser(sl validator.StructLevel) {
|
||||
validateMembership(sl)
|
||||
if !isSuper {
|
||||
validateBankAccount(sl)
|
||||
if user.Licence != nil {
|
||||
if user.Licence != nil && user.RoleID > constants.Roles.Supporter {
|
||||
validateDriverslicence(sl)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user