mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-09-08 10:14:35 +08:00
Add logout (#13796)
### What problem does this PR solve? Add command: logout ### Type of change - [x] New Feature (non-breaking change which adds functionality) Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -234,6 +234,35 @@ func (c *RAGFlowClient) loginUser(email, password string) (string, error) {
|
||||
return token, nil
|
||||
}
|
||||
|
||||
func (c *RAGFlowClient) Logout() (ResponseIf, error) {
|
||||
if c.HTTPClient.LoginToken == "" {
|
||||
return nil, fmt.Errorf("not logged in")
|
||||
}
|
||||
|
||||
var path string
|
||||
if c.ServerType == "admin" {
|
||||
path = "/admin/logout"
|
||||
} else {
|
||||
path = "/user/logout"
|
||||
}
|
||||
|
||||
resp, err := c.HTTPClient.Request("GET", path, c.ServerType == "admin", "web", nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result SimpleResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("login failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("login failed: %s", result.Message)
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// readPassword reads password from terminal without echoing
|
||||
func readPassword() (string, error) {
|
||||
// Check if stdin is a terminal by trying to get terminal size
|
||||
@@ -301,6 +330,8 @@ func (c *RAGFlowClient) ExecuteAdminCommand(cmd *Command) (ResponseIf, error) {
|
||||
switch cmd.Type {
|
||||
case "login_user":
|
||||
return nil, c.LoginUser(cmd)
|
||||
case "logout":
|
||||
return c.Logout()
|
||||
case "ping":
|
||||
return c.PingAdmin(cmd)
|
||||
case "benchmark":
|
||||
@@ -350,6 +381,8 @@ func (c *RAGFlowClient) ExecuteUserCommand(cmd *Command) (ResponseIf, error) {
|
||||
return c.RegisterUser(cmd)
|
||||
case "login_user":
|
||||
return nil, c.LoginUser(cmd)
|
||||
case "logout":
|
||||
return c.Logout()
|
||||
case "ping":
|
||||
return c.PingServer(cmd)
|
||||
case "benchmark":
|
||||
|
||||
Reference in New Issue
Block a user