github.com/vchain-us/vcn@v0.9.11-0.20210921212052-a2484d23c0b3/internal/assert/user.go (about) 1 /* 2 * Copyright (c) 2018-2020 vChain, Inc. All Rights Reserved. 3 * This software is released under GPL3. 4 * The full license information can be found under: 5 * https://www.gnu.org/licenses/gpl-3.0.en.html 6 * 7 */ 8 9 package assert 10 11 import ( 12 "fmt" 13 14 "github.com/vchain-us/vcn/pkg/cmd/login" 15 16 "github.com/inconshreveable/mousetrap" 17 "github.com/vchain-us/vcn/pkg/api" 18 "github.com/vchain-us/vcn/pkg/store" 19 ) 20 21 const vcnLoginMsg = "Proceed by authenticating yourself using <vcn login>" 22 const loginMsg = "You need to be logged in" 23 24 func UserLogin() error { 25 // check for token 26 hasAuth, err := api.NewUser(store.Config().CurrentContext.Email).IsAuthenticated() 27 if err != nil { 28 return err 29 } 30 31 if !hasAuth { 32 // Windows only - when trying to sign an asset with right click 33 // and user has not logged in, prompt the login action directly 34 // without having to open a new cmd line and log in there 35 if mousetrap.StartedByExplorer() { 36 fmt.Println(loginMsg) 37 if err := login.Execute(); err != nil { 38 return err 39 } 40 } else { 41 return fmt.Errorf("%s.\n%s", loginMsg, vcnLoginMsg) 42 } 43 } 44 45 return nil 46 }