👔 Did not block unconfirmed user login, give them no permission instead
This commit is contained in:
parent
09010d5867
commit
e115374589
@ -37,8 +37,6 @@ func doAuthenticate(c *fiber.Ctx) error {
|
|||||||
user, err := services.LookupAccount(data.Username)
|
user, err := services.LookupAccount(data.Username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("account was not found: %v", err.Error()))
|
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("account was not found: %v", err.Error()))
|
||||||
} else if user.ConfirmedAt == nil {
|
|
||||||
return fiber.NewError(fiber.StatusForbidden, "account was not confirmed; check your inbox, there will be an email lead you confirm your registration")
|
|
||||||
} else if user.SuspendedAt != nil {
|
} else if user.SuspendedAt != nil {
|
||||||
return fiber.NewError(fiber.StatusForbidden, "account was suspended")
|
return fiber.NewError(fiber.StatusForbidden, "account was suspended")
|
||||||
}
|
}
|
||||||
|
@ -149,12 +149,8 @@ func CreateAccount(name, nick, email, password string) (models.Account, error) {
|
|||||||
|
|
||||||
if err := database.C.Create(&user).Error; err != nil {
|
if err := database.C.Create(&user).Error; err != nil {
|
||||||
return user, err
|
return user, err
|
||||||
} else if viper.GetInt("default_user_group") > 0 {
|
|
||||||
database.C.Create(&models.AccountGroupMember{
|
|
||||||
AccountID: user.ID,
|
|
||||||
GroupID: uint(viper.GetInt("default_user_group")),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
// Only gave user permission group after they confiremd the registeration
|
||||||
|
|
||||||
if tk, err := NewMagicToken(models.ConfirmMagicToken, &user, nil); err != nil {
|
if tk, err := NewMagicToken(models.ConfirmMagicToken, &user, nil); err != nil {
|
||||||
return user, err
|
return user, err
|
||||||
@ -192,14 +188,17 @@ func ConfirmAccount(code string) error {
|
|||||||
func ForceConfirmAccount(user models.Account) error {
|
func ForceConfirmAccount(user models.Account) error {
|
||||||
user.ConfirmedAt = lo.ToPtr(time.Now())
|
user.ConfirmedAt = lo.ToPtr(time.Now())
|
||||||
|
|
||||||
for k, v := range viper.GetStringMap("permissions.verified") {
|
if viper.GetInt("default_user_group") > 0 {
|
||||||
if val, ok := user.PermNodes[k]; !ok {
|
database.C.Create(&models.AccountGroupMember{
|
||||||
user.PermNodes[k] = v
|
AccountID: user.ID,
|
||||||
} else {
|
GroupID: uint(viper.GetInt("default_user_group")),
|
||||||
user.PermNodes[k] = val
|
})
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_ = database.C.Model(&models.AccountContact{}).Where("account_id = ?", user.ID).Updates(&models.AccountContact{
|
||||||
|
VerifiedAt: lo.ToPtr(time.Now()),
|
||||||
|
})
|
||||||
|
|
||||||
if err := database.C.Save(&user).Error; err != nil {
|
if err := database.C.Save(&user).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user