Skip to content

Commit 816fc49

Browse files
author
JojiiOfficial
committed
add logout func
1 parent 70d2169 commit 816fc49

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

Command.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ func runCommand(parsed string, commandData *commands.CommandData) {
130130
case loginCmd.FullCommand():
131131
commands.LoginCommand(commandData, *loginCmdUser)
132132

133+
case logoutCmd.FullCommand():
134+
commandData.Logout(*logoutCmdUser)
135+
133136
// Register
134137
case registerCmd:
135138
commands.RegisterCommand(commandData)

commands/User.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/JojiiOfficial/configService"
1212
"github.com/JojiiOfficial/gaw"
13+
"github.com/zalando/go-keyring"
1314

1415
"github.com/fatih/color"
1516
"golang.org/x/crypto/ssh/terminal"
@@ -74,6 +75,16 @@ func RegisterCommand(cData *CommandData) {
7475
}
7576
}
7677

78+
// Logout Logs out the user
79+
func (cData *CommandData) Logout(username string) {
80+
err := cData.Config.ClearKeyring(username)
81+
if err == nil || err == keyring.ErrNotFound {
82+
printSuccess("logged out")
83+
} else {
84+
fmt.Println(err)
85+
}
86+
}
87+
7788
func credentials(bUser string, repeat bool, index uint8) (string, string) {
7889
if index >= 3 {
7990
return "", ""

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ replace github.com/gosuri/uiprogress v0.0.1 => github.com/JojiiOfficial/uiprogre
66

77
require (
88
github.com/DataManager-Go/libdatamanager v1.2.1
9-
github.com/DataManager-Go/libdatamanager/config v0.0.0-20200418001729-691c701da199
9+
github.com/DataManager-Go/libdatamanager/config v0.0.0-20200418113028-b95e60ce986e
1010
github.com/JojiiOfficial/configService v0.0.0-20200219132202-6e71512e2e28
1111
github.com/JojiiOfficial/gaw v1.2.1
1212
github.com/JojiiOfficial/shred v1.2.1
@@ -21,6 +21,7 @@ require (
2121
github.com/mattn/go-sqlite3 v2.0.3+incompatible
2222
github.com/pkg/errors v0.9.1
2323
github.com/sbani/go-humanizer v0.3.1
24+
github.com/zalando/go-keyring v0.0.0-20200121091418-667557018717
2425
golang.org/x/crypto v0.0.0-20200414173820-0848c9571904
2526
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4 // indirect
2627
gopkg.in/alecthomas/kingpin.v2 v2.2.6

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ github.com/DataManager-Go/libdatamanager/config v0.0.0-20200417223247-afbf5204a7
1515
github.com/DataManager-Go/libdatamanager/config v0.0.0-20200417223247-afbf5204a71a/go.mod h1:RfoOPe8dQgubuBUmtqEYu1Ny0fT+htZH/ArrEl0dcHQ=
1616
github.com/DataManager-Go/libdatamanager/config v0.0.0-20200418001729-691c701da199 h1:hSeYQSfMC6yT1/nNK6Bpkn9MQiw2ED1hEqO9JJFhZTA=
1717
github.com/DataManager-Go/libdatamanager/config v0.0.0-20200418001729-691c701da199/go.mod h1:RfoOPe8dQgubuBUmtqEYu1Ny0fT+htZH/ArrEl0dcHQ=
18+
github.com/DataManager-Go/libdatamanager/config v0.0.0-20200418113028-b95e60ce986e h1:GpLHBsAGkVgfEiL8ycKZb37yWsufEvZXo392+G5RjYU=
19+
github.com/DataManager-Go/libdatamanager/config v0.0.0-20200418113028-b95e60ce986e/go.mod h1:RfoOPe8dQgubuBUmtqEYu1Ny0fT+htZH/ArrEl0dcHQ=
1820
github.com/JojiiOfficial/configService v0.0.0-20200219132202-6e71512e2e28 h1:nYoIExG+Z/gSLS9Jbpu6lnrh+m6e9gTxQfGhanTsExE=
1921
github.com/JojiiOfficial/configService v0.0.0-20200219132202-6e71512e2e28/go.mod h1:j1kHFoYWAbLRPE5nyAAtODwUc0xwd2+ifPZ3uCAgv/g=
2022
github.com/JojiiOfficial/gaw v1.2.0 h1:qIu6xVtCvd4yhAfI0MGGr5CPus0hpY+eFUDUGqc/sYQ=

main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ var (
8181
// -- Login
8282
loginCmd = app.Command("login", "Login")
8383
loginCmdUser = loginCmd.Flag("username", "Your username").String()
84+
// -- Logout
85+
logoutCmd = app.Command("logout", "logout from a session")
86+
logoutCmdUser = logoutCmd.Arg("username", "Delete sessiondata assigned to a different username than the current one").String()
8487
// -- Register
8588
registerCmd = app.Command("register", "Create an account").FullCommand()
8689
// -- Setup

0 commit comments

Comments
 (0)