Compare commits
3 Commits
6937ab333c
...
f719a0bbf5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f719a0bbf5 | ||
|
|
05d94ae09c | ||
|
|
ff3106b8be |
@@ -14,6 +14,7 @@ const (
|
||||
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
|
||||
}
|
||||
}
|
||||
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()
|
||||
|
||||
@@ -14,7 +14,7 @@ type User struct {
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
DeletedAt *time.Time `gorm:"index"`
|
||||
DateOfBirth time.Time `gorm:"not null" json:"dateofbirth" binding:"required,safe_content"`
|
||||
DateOfBirth time.Time `gorm:"not null" json:"dateofbirth" binding:"required_unless=RoleID 0,safe_content"`
|
||||
Company string `json:"company" binding:"omitempty,omitnil,safe_content"`
|
||||
Phone string `json:"phone" binding:"omitempty,omitnil,safe_content"`
|
||||
Notes string `json:"notes" binding:"safe_content"`
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ var Responses = struct {
|
||||
UndeliveredVerificationMail: "server.error.undelivered_verification_mail",
|
||||
},
|
||||
Fields: ValidationFields{
|
||||
General: "general",
|
||||
General: "server.general",
|
||||
ParentMemberShipID: "parent_membership_id",
|
||||
SubscriptionModel: "subscription_model",
|
||||
Login: "user.login",
|
||||
|
||||
@@ -70,7 +70,7 @@
|
||||
</div>
|
||||
<div style="text-align: center; padding: 16px 24px 16px 24px">
|
||||
<a
|
||||
href="{{.BASEURL}}/backend/users/verify?token={{.Token}}"
|
||||
href="{{.BASEURL}}/api/users/verify?token={{.Token}}"
|
||||
style="
|
||||
color: #ffffff;
|
||||
font-size: 26px;
|
||||
@@ -122,7 +122,7 @@
|
||||
padding: 4px 24px 16px 24px;
|
||||
"
|
||||
>
|
||||
{{.BASEURL}}/backend/users/verify?token={{.Token}}
|
||||
{{.BASEURL}}/api/users/verify?token={{.Token}}
|
||||
</div>
|
||||
<div style="font-weight: normal; padding: 16px 24px 16px 24px">
|
||||
Nachdem wir Ihre E-Mail Adresse bestätigen konnten, schicken wir
|
||||
|
||||
@@ -8,7 +8,7 @@ noch Ihre Emailadresse indem Sie hier klicken:
|
||||
|
||||
E-Mail Adresse bestätigen
|
||||
|
||||
{{.BASEURL}}/backend/users/verify?token={{.Token}}
|
||||
{{.BASEURL}}/api/users/verify?token={{.Token}}
|
||||
|
||||
Nachdem wir Ihre E-Mail Adresse bestätigen konnten, schicken wir
|
||||
Ihnen alle weiteren Informationen zu. Wir freuen uns auf die
|
||||
|
||||
Reference in New Issue
Block a user