mirror of
				https://gitea.com/gitea/tea.git
				synced 2025-10-31 01:05:26 +01:00 
			
		
		
		
	Improve tea logout (#213)
				
					
				
			fix message fix lint Impruve logout Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/213 Reviewed-by: Norwin <noerw@noreply.gitea.io> Reviewed-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
		| @@ -7,7 +7,6 @@ package cmd | ||||
| import ( | ||||
| 	"errors" | ||||
| 	"log" | ||||
| 	"os" | ||||
|  | ||||
| 	"code.gitea.io/tea/modules/config" | ||||
|  | ||||
| @@ -30,34 +29,22 @@ var CmdLogout = cli.Command{ | ||||
| } | ||||
|  | ||||
| func runLogout(ctx *cli.Context) error { | ||||
| 	var name string | ||||
| 	if len(os.Args) == 3 { | ||||
| 		name = os.Args[2] | ||||
| 	} else if ctx.IsSet("name") { | ||||
| 		name = ctx.String("name") | ||||
| 	} else { | ||||
| 		return errors.New("Please specify a login name") | ||||
| 	} | ||||
|  | ||||
| 	err := config.LoadConfig() | ||||
| 	if err != nil { | ||||
| 		log.Fatal(err) | ||||
| 	} | ||||
|  | ||||
| 	var idx = -1 | ||||
| 	for i, l := range config.Config.Logins { | ||||
| 		if l.Name == name { | ||||
| 			idx = i | ||||
| 			break | ||||
| 		} | ||||
| 	} | ||||
| 	if idx > -1 { | ||||
| 		config.Config.Logins = append(config.Config.Logins[:idx], config.Config.Logins[idx+1:]...) | ||||
| 		err = config.SaveConfig() | ||||
| 		if err != nil { | ||||
| 			log.Fatal(err) | ||||
| 		} | ||||
| 	var name string | ||||
|  | ||||
| 	if ctx.IsSet("name") { | ||||
| 		name = ctx.String("name") | ||||
| 	} else if len(ctx.Args().First()) != 0 { | ||||
| 		name = ctx.Args().First() | ||||
| 	} else if len(config.Config.Logins) == 1 { | ||||
| 		name = config.Config.Logins[0].Name | ||||
| 	} else { | ||||
| 		return errors.New("Please specify a login name") | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
| 	return config.DeleteLogin(name) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 6543
					6543