mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-11-10 13:24:05 +08:00
feat(auth): add verification hooks (#22049)
This commit is contained in:
4 files changed
+25
-2
No files matched your search
@@ -75,7 +75,7 @@ func (h *SystemHandler) Healthz(c *gin.Context) {
|
||||
// @Success 200 {object} map[string]interface{}
|
||||
// @Router /api/v1/system/config [get]
|
||||
func (h *SystemHandler) GetConfig(c *gin.Context) {
|
||||
config, err := h.systemService.GetConfig()
|
||||
config, err := h.systemService.GetConfig(c.Request.Context())
|
||||
if err != nil {
|
||||
common.Respond(c, http.StatusInternalServerError, 500, nil, "Failed to get system configuration")
|
||||
return
|
||||
|
||||
@@ -28,6 +28,17 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// configExtras is empty in the community edition.
|
||||
type configExtras struct{}
|
||||
|
||||
// loadConfigExtras returns no additional settings in the community edition.
|
||||
func loadConfigExtras(context.Context) (configExtras, error) { return configExtras{}, nil }
|
||||
|
||||
// consumeRegistrationProof is a no-op in the community edition.
|
||||
func consumeRegistrationProof(context.Context, string) (common.ErrorCode, error) {
|
||||
return common.CodeSuccess, nil
|
||||
}
|
||||
|
||||
// InitHTTPClientEE is a no-op in the community edition.
|
||||
func (h *AdminClient) InitHTTPClientEE() error { return nil }
|
||||
|
||||
|
||||
@@ -43,14 +43,20 @@ func NewSystemService() *SystemService {
|
||||
type ConfigResponse struct {
|
||||
EnableRegister bool `json:"registerEnabled"`
|
||||
DisablePasswordLogin bool `json:"disablePasswordLogin"`
|
||||
configExtras
|
||||
}
|
||||
|
||||
// GetConfig get system configuration
|
||||
func (s *SystemService) GetConfig() (*ConfigResponse, error) {
|
||||
func (s *SystemService) GetConfig(ctx context.Context) (*ConfigResponse, error) {
|
||||
cfg := server.GetConfig()
|
||||
extras, err := loadConfigExtras(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ConfigResponse{
|
||||
EnableRegister: cfg.EnableRegister(),
|
||||
DisablePasswordLogin: cfg.DisablePasswordLogin(),
|
||||
configExtras: extras,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -136,6 +136,12 @@ func (s *UserService) Register(ctx context.Context, req *RegisterRequest) (*enti
|
||||
if err != nil {
|
||||
return nil, common.CodeExceptionError, err
|
||||
}
|
||||
// Admission policies are checked by middleware before this service runs.
|
||||
// This hook may consume a single-use proof, so reject duplicate accounts
|
||||
// and invalid encrypted passwords before calling it.
|
||||
if code, err := consumeRegistrationProof(ctx, req.Email); err != nil {
|
||||
return nil, code, err
|
||||
}
|
||||
|
||||
var hashedPassword string
|
||||
hashedPassword, err = common.GenerateWerkzeugPasswordHash(decryptedPassword)
|
||||
|
||||
Reference in new issue
Block a user