mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-06-29 15:31:05 +08:00
Go CLI: fix register user (#14665)
### What problem does this PR solve? 1. Update API URL 2. Add password encryption ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -305,6 +305,12 @@ func (c *RAGFlowClient) RegisterUser(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("no password")
|
||||
}
|
||||
|
||||
// Encrypt password using RSA
|
||||
encryptedPassword, err := EncryptPassword(password)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to encrypt password: %w", err)
|
||||
}
|
||||
|
||||
var nickname string
|
||||
nickname, ok = cmd.Params["nickname"].(string)
|
||||
if !ok {
|
||||
@@ -313,11 +319,11 @@ func (c *RAGFlowClient) RegisterUser(cmd *Command) (ResponseIf, error) {
|
||||
|
||||
payload := map[string]interface{}{
|
||||
"email": email,
|
||||
"password": password,
|
||||
"password": encryptedPassword,
|
||||
"nickname": nickname,
|
||||
}
|
||||
|
||||
resp, err := c.HTTPClient.Request("POST", "/user/register", "admin", nil, payload)
|
||||
resp, err := c.HTTPClient.Request("POST", "/users", "web", nil, payload)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to register user: %w", err)
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ func NewUserHandler(userService *service.UserService) *UserHandler {
|
||||
// @Produce json
|
||||
// @Param request body service.RegisterRequest true "registration info"
|
||||
// @Success 200 {object} map[string]interface{}
|
||||
// @Router /v1/user/register [post]
|
||||
// @Router /api/v1/users [post]
|
||||
func (h *UserHandler) Register(c *gin.Context) {
|
||||
var req service.RegisterRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
|
||||
@@ -90,7 +90,7 @@ func (r *Router) Setup(engine *gin.Engine) {
|
||||
|
||||
// System endpoints
|
||||
engine.GET("/v1/system/configs", r.systemHandler.GetConfigs)
|
||||
engine.POST("/v1/user/register", r.userHandler.Register)
|
||||
//engine.POST("/v1/user/register", r.userHandler.Register)
|
||||
|
||||
// User logout endpoint
|
||||
engine.GET("/v1/user/logout", r.userHandler.Logout)
|
||||
@@ -135,7 +135,7 @@ func (r *Router) Setup(engine *gin.Engine) {
|
||||
auth := v1.Group("/auth")
|
||||
{
|
||||
// User logout endpoint
|
||||
auth.GET("/logout", r.userHandler.Logout)
|
||||
auth.POST("/logout", r.userHandler.Logout)
|
||||
}
|
||||
|
||||
// Users routes
|
||||
|
||||
@@ -320,16 +320,16 @@ func (s *UserService) Login(req *LoginRequest) (*entity.User, common.ErrorCode,
|
||||
func (s *UserService) LoginByEmail(req *EmailLoginRequest) (*entity.User, common.ErrorCode, error) {
|
||||
user, err := s.userDAO.GetByEmail(req.Email)
|
||||
if err != nil {
|
||||
return nil, common.CodeAuthenticationError, fmt.Errorf("Email: %s is not registered!", req.Email)
|
||||
return nil, common.CodeAuthenticationError, fmt.Errorf("email: %s is not registered!", req.Email)
|
||||
}
|
||||
|
||||
decryptedPassword, err := s.decryptPassword(req.Password)
|
||||
if err != nil {
|
||||
return nil, common.CodeServerError, fmt.Errorf("Fail to crypt password")
|
||||
return nil, common.CodeServerError, fmt.Errorf("fail to crypt password")
|
||||
}
|
||||
|
||||
if user.Password == nil || !s.VerifyPassword(*user.Password, decryptedPassword) {
|
||||
return nil, common.CodeAuthenticationError, fmt.Errorf("Email and password do not match!")
|
||||
return nil, common.CodeAuthenticationError, fmt.Errorf("email and password do not match!")
|
||||
}
|
||||
|
||||
if user.IsActive == "0" {
|
||||
|
||||
@@ -97,7 +97,7 @@ export default defineConfig(({ mode }) => {
|
||||
changeOrigin: true,
|
||||
ws: true,
|
||||
},
|
||||
'^(/api/v1/auth/login)|^(/api/v1/users/me)|^(/api/v1/system/config)|^(/api/v1/system/version)|^(/api/v1/tenants)|^(/api/v1/chats)|^(/api/v1/searches)|^(/api/v1/files)':
|
||||
'^(/api/v1/users)|^(/api/v1/auth)|^(/api/v1/users/me)|^(/api/v1/system/config)|^(/api/v1/system/version)|^(/api/v1/tenants)|^(/api/v1/chats)|^(/api/v1/searches)|^(/api/v1/files)':
|
||||
{
|
||||
target: 'http://127.0.0.1:9384/',
|
||||
changeOrigin: true,
|
||||
|
||||
Reference in New Issue
Block a user