未验证 提交 6ba8dce7 编写于 作者: A Avi Aryan

add logout command #52

上级 0b0999b8
package logout
import (
"github.com/appbaseio/abc/appbase/session"
"os"
)
// UserLogout log outs a user
func UserLogout() error {
err := session.DeleteUserSession()
if err != nil {
return err
}
// remove env var
os.Unsetenv("ABC_TOKEN")
return nil
}
......@@ -72,6 +72,19 @@ func SaveUserSession(data string) error {
return err
}
// DeleteUserSession deletes user session
func DeleteUserSession() error {
sessionFile, err := getSessionFilePath()
if err != nil {
return err
}
err = os.Remove(sessionFile)
if err != nil {
return err
}
return nil
}
// attachCookiesToRequest attaches cookies to a request
func attachCookiesToRequest(req *http.Request) error {
cookies, err := LoadUserSessionAsCookie()
......
......@@ -17,6 +17,7 @@ func usageAppbase() {
fmt.Fprintf(os.Stderr, " app display app details\n")
fmt.Fprintf(os.Stderr, " create create app\n")
fmt.Fprintf(os.Stderr, " delete delete app\n")
fmt.Fprintf(os.Stderr, " logout logout session\n")
if imports.IsPrivate {
fmt.Fprintf(os.Stderr, " import import data to appbase app\n")
}
......@@ -39,6 +40,8 @@ func provisionAppbaseCLI(command string) func([]string) error {
run = runCreate
case "delete":
run = runDelete
case "logout":
run = runLogout
default:
usage()
os.Exit(1)
......
......@@ -34,6 +34,6 @@ func isLoggedIn() bool {
if login.IsUserAuthenticated() {
return true
}
fmt.Println("Not logged in.")
fmt.Println("Not logged in")
return false
}
package main
import (
"fmt"
"github.com/appbaseio/abc/appbase/logout"
)
// runLogout runs the logout command
func runLogout(args []string) error {
flagset := baseFlagSet("logout")
flagset.Usage = usageFor(flagset, "abc logout")
if err := flagset.Parse(args); err != nil {
return err
}
args = flagset.Args()
switch len(args) {
case 0:
if isLoggedIn() {
return logout.UserLogout()
}
default:
fmt.Println("Wrong number of parameters. See help (--help).")
}
return nil
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册