示例#1
0
文件: signup.go 项目: yannski/cli
func SignUp() error {
	fmt.Print("Email: ")

	var email string
	_, err := fmt.Scanln(&email)
	if err != nil {
		return errgo.Mask(err)
	}

	password, err := term.Password("Password: "******"Password validation: ")
	if err != nil {
		return errgo.Mask(err)
	}

	if password != password_confirmation {
		return errgo.New("passwords don't match")
	}

	err = api.SignUp(email, password)
	if err != nil {
		return errgo.Mask(err)
	}

	fmt.Println("A confirmation email has been sent to", email)
	return nil
}
示例#2
0
文件: auth.go 项目: Zyko0/cli
func tryAuth() (*users.User, error) {
	var login string
	var err error

	for login == "" {
		fmt.Print("Username or email: ")
		_, err := fmt.Scanln(&login)
		if err != nil {
			if strings.Contains(err.Error(), "unexpected newline") {
				continue
			}
			return nil, errgo.Mask(err, errgo.Any)
		}
		login = strings.TrimRight(login, "\n")
	}

	password, err := term.Password("Password: ")
	if err != nil {
		return nil, errgo.Mask(err, errgo.Any)
	}

	user, err := scalingo.AuthUser(login, password)
	if err != nil {
		return nil, errgo.Mask(err, errgo.Any)
	}

	return user, nil
}