Initial message to the past
Signed-off-by: Shin'ya Minazuki <shinyoukai@laidback.moe>
This commit is contained in:
67
cmd/mikuru-login/main.go
Normal file
67
cmd/mikuru-login/main.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/term"
|
||||
"go.yarn.social/client"
|
||||
"git.laidback.moe/shinyoukai/mikuru"
|
||||
)
|
||||
|
||||
var (
|
||||
username string
|
||||
password string
|
||||
)
|
||||
|
||||
func init() {
|
||||
xdg_config_home, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
fmt.Println("Unable to obtain user's configuration directory")
|
||||
os.Exit(1)
|
||||
}
|
||||
configPath := xdg_config_home + "/mikuru.ini"
|
||||
mikuru.Parse(configPath)
|
||||
}
|
||||
|
||||
func main() {
|
||||
cli, err := client.NewClient(client.WithURI(mikuru.Config.Host))
|
||||
if err != nil {
|
||||
fmt.Printf("%s", err)
|
||||
fmt.Println("Error creating client")
|
||||
os.Exit(1)
|
||||
}
|
||||
signin(cli)
|
||||
}
|
||||
func signin(cli *client.Client) {
|
||||
fmt.Printf("Username: ")
|
||||
fmt.Scanln(&username)
|
||||
|
||||
if len(username) == 0 {
|
||||
fmt.Println("No value. Bailing out")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("Password: ")
|
||||
data, err := term.ReadPassword(int(syscall.Stdin))
|
||||
if err != nil {
|
||||
fmt.Printf("Unable to obtain password: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
password := string(data)
|
||||
|
||||
res, err := cli.Login(username, password)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Unable to login")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Println("Login successful")
|
||||
fmt.Println("Place this token in your configuration file for later use")
|
||||
fmt.Println("Do not share it with anyone, it's classified information")
|
||||
fmt.Println("Trim surrounding braces before usage")
|
||||
fmt.Printf("token = %v\n", res)
|
||||
}
|
||||
Reference in New Issue
Block a user