-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from amands98/login-flow
feat: improve the login flow for the user
- Loading branch information
Showing
4 changed files
with
196 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package login | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/charmbracelet/huh" | ||
) | ||
|
||
type LoginView struct { | ||
Server string | ||
Username string | ||
Password string | ||
Name string | ||
} | ||
|
||
func CreateView(loginView *LoginView) { | ||
theme := huh.ThemeCharm() | ||
err := huh.NewForm( | ||
huh.NewGroup( | ||
huh.NewInput(). | ||
Title("Server"). | ||
Value(&loginView.Server). | ||
Validate(func(str string) error { | ||
if str == "" { | ||
return errors.New("server cannot be empty") | ||
} | ||
return nil | ||
}), | ||
huh.NewInput(). | ||
Title("User Name"). | ||
Value(&loginView.Username). | ||
Validate(func(str string) error { | ||
if str == "" { | ||
return errors.New("username cannot be empty") | ||
} | ||
return nil | ||
}), | ||
huh.NewInput(). | ||
Title("Password"). | ||
Password(true). | ||
Value(&loginView.Password). | ||
Validate(func(str string) error { | ||
if str == "" { | ||
return errors.New("password cannot be empty") | ||
} | ||
return nil | ||
}), | ||
huh.NewInput(). | ||
Title("Name of Credential"). | ||
Value(&loginView.Name). | ||
Validate(func(str string) error { | ||
if str == "" { | ||
return errors.New("credential name cannot be empty") | ||
} | ||
return nil | ||
}), | ||
), | ||
).WithTheme(theme).Run() | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
} |