Backend:Real world movement
This commit is contained in:
@@ -14,11 +14,20 @@ func validateUser(sl validator.StructLevel) {
|
||||
user := sl.Current().Interface().(models.User)
|
||||
|
||||
isSuper := user.RoleID >= constants.Roles.Admin
|
||||
|
||||
if user.RoleID > constants.Roles.Member && user.Password == "" {
|
||||
passwordExists, err := repositories.PasswordExists(&user.ID)
|
||||
if err != nil || !passwordExists {
|
||||
logger.Error.Printf("Error checking password exists for user %v: %v", user.Email, err)
|
||||
sl.ReportError(user.Password, "Password", "password", "required", "")
|
||||
}
|
||||
}
|
||||
// Validate User > 18 years old
|
||||
if !isSuper && user.DateOfBirth.After(time.Now().AddDate(-18, 0, 0)) {
|
||||
sl.ReportError(user.DateOfBirth, "DateOfBirth", "date_of_birth", "age", "")
|
||||
}
|
||||
// validate subscriptionModel
|
||||
logger.Error.Printf("User: %#v", user)
|
||||
if user.Membership.SubscriptionModel.Name == "" {
|
||||
sl.ReportError(user.Membership.SubscriptionModel.Name, "SubscriptionModel.Name", "name", "required", "")
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user