Exemplo n.º 1
0
func (e *loginLoadUser) findUsername(ctx *Context) (string, error) {
	if len(e.usernameOrEmail) == 0 {
		if err := e.prompt(ctx); err != nil {
			return "", err
		}
	}

	if len(e.usernameOrEmail) == 0 {
		return "", libkb.NoUsernameError{}
	}

	if libkb.CheckUsername.F(e.usernameOrEmail) {
		return e.usernameOrEmail, nil
	}

	if !libkb.CheckEmail.F(e.usernameOrEmail) {
		return "", libkb.BadNameError(e.usernameOrEmail)
	}

	// looks like an email address
	e.G().Log.Debug("%q looks like an email address, must get login session to get user", e.usernameOrEmail)
	// need to login with it in order to get the username
	var username string
	var afterLogin = func(lctx libkb.LoginContext) error {
		username = lctx.LocalSession().GetUsername().String()
		return nil
	}
	if err := e.G().LoginState().VerifyEmailAddress(e.usernameOrEmail, ctx.SecretUI, afterLogin); err != nil {
		return "", err
	}

	e.G().Log.Debug("VerifyEmailAddress %q => %q", e.usernameOrEmail, username)

	return username, nil
}
Exemplo n.º 2
0
// If emailOrUsername looks like an email address, it will get a
// login session in order to map the email address to a keybase user.
func (e *LoginProvision) checkEmailOrUsername(ctx *Context, emailOrUsername string) error {
	if len(emailOrUsername) == 0 {
		return libkb.NoUsernameError{}
	}
	if libkb.CheckUsername.F(emailOrUsername) {
		e.username = emailOrUsername
		return nil
	}
	if !libkb.CheckEmail.F(emailOrUsername) {
		return libkb.BadNameError(emailOrUsername)
	}

	// emailOrUsername looks like an email address
	e.G().Log.Debug("%q looks like an email address, must get login session to get user", emailOrUsername)
	// need to login with it in order to get the username
	var afterLogin = func(lctx libkb.LoginContext) error {
		e.username = lctx.LocalSession().GetUsername().String()
		return nil
	}
	return e.G().LoginState().VerifyEmailAddress(emailOrUsername, ctx.SecretUI, afterLogin)
}
Exemplo n.º 3
0
	"github.com/keybase/client/go/libkb"
	keybase1 "github.com/keybase/client/go/protocol"
)

type luTest struct {
	name  string
	input string
	err   error
	uid   keybase1.UID
}

var lutests = []luTest{
	{name: "alice", input: "t_alice", uid: "295a7eea607af32040647123732bc819"},
	{name: "bob", input: "t_bob", uid: "afb5eda3154bc13c1df0189ce93ba119"},
	{name: "unknown user", input: "not_a_user", err: libkb.NotFoundError{}},
	{name: "invalid input", input: "spaces aren't allowed", err: libkb.BadNameError("")},
}

func TestLoginLoadUser(t *testing.T) {
	tc := SetupEngineTest(t, "lu")
	defer tc.Cleanup()

	for _, test := range lutests {
		ctx := &Context{
			LoginUI:  &libkb.TestLoginUI{},
			SecretUI: &libkb.TestSecretUI{},
		}
		eng := newLoginLoadUser(tc.G, test.input)
		if err := RunEngine(eng, ctx); err != nil {
			if test.err == nil {
				t.Errorf("%s: run error %s", test.name, err)