mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-09 00:28:12 +00:00
Update user menu
This commit is contained in:
+22
-18
@@ -33,6 +33,10 @@ type params struct {
|
|||||||
keyLength uint32
|
keyLength uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ADD_USER = "Add a new account login"
|
||||||
|
const REPLACE_USER = "Override current logged in user"
|
||||||
|
const EXIT_USER_MENU = "Exit"
|
||||||
|
|
||||||
// loginCmd represents the login command
|
// loginCmd represents the login command
|
||||||
var loginCmd = &cobra.Command{
|
var loginCmd = &cobra.Command{
|
||||||
Use: "login",
|
Use: "login",
|
||||||
@@ -48,26 +52,26 @@ var loginCmd = &cobra.Command{
|
|||||||
util.HandleError(err)
|
util.HandleError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
addUser := false
|
// addUser := false
|
||||||
if currentLoggedInUserDetails.UserCredentials.Email != "" {
|
// if currentLoggedInUserDetails.UserCredentials.Email != "" {
|
||||||
addUser, err = addNewUserPrompt()
|
// addUser, err = addNewUserPrompt()
|
||||||
|
// if err != nil {
|
||||||
|
// util.HandleError(err)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if !addUser {
|
||||||
|
if currentLoggedInUserDetails.IsUserLoggedIn && !currentLoggedInUserDetails.LoginExpired && len(currentLoggedInUserDetails.UserCredentials.PrivateKey) != 0 {
|
||||||
|
shouldOverride, err := userLoginMenu(currentLoggedInUserDetails.UserCredentials.Email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.HandleError(err)
|
util.HandleError(err)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if !addUser {
|
if !shouldOverride {
|
||||||
if currentLoggedInUserDetails.IsUserLoggedIn && !currentLoggedInUserDetails.LoginExpired && len(currentLoggedInUserDetails.UserCredentials.PrivateKey) != 0 {
|
return
|
||||||
shouldOverride, err := shouldOverrideLoginPrompt(currentLoggedInUserDetails.UserCredentials.Email)
|
|
||||||
if err != nil {
|
|
||||||
util.HandleError(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !shouldOverride {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// }
|
||||||
|
|
||||||
email, password, err := askForLoginCredentials()
|
email, password, err := askForLoginCredentials()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -366,16 +370,16 @@ func addNewUserPrompt() (bool, error) {
|
|||||||
return result == "Yes", err
|
return result == "Yes", err
|
||||||
}
|
}
|
||||||
|
|
||||||
func shouldOverrideLoginPrompt(currentLoggedInUserEmail string) (bool, error) {
|
func userLoginMenu(currentLoggedInUserEmail string) (bool, error) {
|
||||||
prompt := promptui.Select{
|
prompt := promptui.Select{
|
||||||
Label: fmt.Sprintf("There seems to be a user already logged in with the email: %s. Would you like to override that login? Select[Yes/No]", currentLoggedInUserEmail),
|
Label: fmt.Sprintf("Current logged in user email: %s", currentLoggedInUserEmail),
|
||||||
Items: []string{"No", "Yes"},
|
Items: []string{ADD_USER, REPLACE_USER, EXIT_USER_MENU},
|
||||||
}
|
}
|
||||||
_, result, err := prompt.Run()
|
_, result, err := prompt.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
return result == "Yes", err
|
return result != EXIT_USER_MENU, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateFromPassword(password string, salt []byte, p *params) (hash []byte, err error) {
|
func generateFromPassword(password string, salt []byte, p *params) (hash []byte, err error) {
|
||||||
|
|||||||
@@ -31,12 +31,12 @@ func WriteInitalConfig(userCredentials *models.UserCredentials) error {
|
|||||||
return fmt.Errorf("writeInitalConfig: unable to write config file because [err=%s]", err)
|
return fmt.Errorf("writeInitalConfig: unable to write config file because [err=%s]", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//if empty
|
//if empty, initialize
|
||||||
if existingConfigFile.LoggedInUsersEmail == nil {
|
if existingConfigFile.LoggedInUsersEmail == nil {
|
||||||
existingConfigFile.LoggedInUsersEmail = []string{}
|
existingConfigFile.LoggedInUsersEmail = []string{}
|
||||||
}
|
}
|
||||||
|
|
||||||
//if profile exists
|
//if profiles exists
|
||||||
if len(existingConfigFile.LoggedInUsersEmail) > 0 {
|
if len(existingConfigFile.LoggedInUsersEmail) > 0 {
|
||||||
ok := Contains(existingConfigFile.LoggedInUsersEmail, userCredentials.Email)
|
ok := Contains(existingConfigFile.LoggedInUsersEmail, userCredentials.Email)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|||||||
Reference in New Issue
Block a user