mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
feat: add system setting to disable password-based login (#2039)
* system setting to disable password login * fix linter warning * fix indentation warning * Prohibit disable-password-login if no identity providers are configured * Warnings and explicit confirmation when en-/disabling password-login - Disabling password login now gives a warning and requires a second confirmation which needs to be explicitly typed. - (Re)Enabling password login now also gives a simple warning. - Removing an identity provider while password-login is disabled now also warns about possible problems. * Fix formatting * Fix code-style --------- Co-authored-by: traumweh <5042134-traumweh@users.noreply.gitlab.com>
This commit is contained in:
@ -37,6 +37,24 @@ func (s *APIV1Service) registerAuthRoutes(g *echo.Group) {
|
||||
g.POST("/auth/signin", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
signin := &SignIn{}
|
||||
|
||||
disablePasswordLoginSystemSetting, err := s.Store.GetSystemSetting(ctx, &store.FindSystemSetting{
|
||||
Name: SystemSettingDisablePasswordLoginName.String(),
|
||||
})
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find system setting").SetInternal(err)
|
||||
}
|
||||
if disablePasswordLoginSystemSetting != nil {
|
||||
disablePasswordLogin := false
|
||||
err = json.Unmarshal([]byte(disablePasswordLoginSystemSetting.Value), &disablePasswordLogin)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to unmarshal system setting").SetInternal(err)
|
||||
}
|
||||
if disablePasswordLogin {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Password login is deactivated")
|
||||
}
|
||||
}
|
||||
|
||||
if err := json.NewDecoder(c.Request().Body).Decode(signin); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted signin request").SetInternal(err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user