forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.go
95 lines (83 loc) · 2.73 KB
/
login.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package service
import (
"github.com/keybase/client/go/engine"
"github.com/keybase/client/go/libkb"
keybase1 "github.com/keybase/client/go/protocol"
rpc "github.com/keybase/go-framed-msgpack-rpc"
"golang.org/x/net/context"
)
type LoginHandler struct {
libkb.Contextified
*BaseHandler
identifyUI libkb.IdentifyUI
}
func NewLoginHandler(xp rpc.Transporter, g *libkb.GlobalContext) *LoginHandler {
return &LoginHandler{
BaseHandler: NewBaseHandler(xp),
Contextified: libkb.NewContextified(g),
}
}
func (h *LoginHandler) GetConfiguredAccounts(_ context.Context, sessionID int) ([]keybase1.ConfiguredAccount, error) {
return libkb.GetConfiguredAccounts(h.G())
}
func (h *LoginHandler) Logout(_ context.Context, sessionID int) error {
return h.G().Logout()
}
func (h *LoginHandler) Deprovision(_ context.Context, arg keybase1.DeprovisionArg) error {
eng := engine.NewDeprovisionEngine(h.G(), arg.Username)
ctx := engine.Context{
LogUI: h.getLogUI(arg.SessionID),
SecretUI: h.getSecretUI(arg.SessionID),
}
return engine.RunEngine(eng, &ctx)
}
func (h *LoginHandler) RecoverAccountFromEmailAddress(_ context.Context, email string) error {
res, err := h.G().API.Post(libkb.APIArg{
Endpoint: "send-reset-pw",
NeedSession: false,
Args: libkb.HTTPArgs{
"email_or_username": libkb.S{Val: email},
},
AppStatus: []string{"OK", "BAD_LOGIN_USER_NOT_FOUND"},
})
if err != nil {
return err
}
if res.AppStatus == "BAD_LOGIN_USER_NOT_FOUND" {
return libkb.NotFoundError{}
}
return nil
}
func (h *LoginHandler) ClearStoredSecret(_ context.Context, arg keybase1.ClearStoredSecretArg) error {
return libkb.ClearStoredSecret(h.G(), libkb.NewNormalizedUsername(arg.Username))
}
func (h *LoginHandler) PaperKey(_ context.Context, sessionID int) error {
ctx := &engine.Context{
LogUI: h.getLogUI(sessionID),
LoginUI: h.getLoginUI(sessionID),
SecretUI: h.getSecretUI(sessionID),
}
eng := engine.NewPaperKey(h.G())
return engine.RunEngine(eng, ctx)
}
func (h *LoginHandler) Unlock(_ context.Context, sessionID int) error {
ctx := &engine.Context{
LogUI: h.getLogUI(sessionID),
SecretUI: h.getSecretUI(sessionID),
}
eng := engine.NewUnlock(h.G())
return engine.RunEngine(eng, ctx)
}
func (h *LoginHandler) Login(_ context.Context, arg keybase1.LoginArg) error {
ctx := &engine.Context{
LogUI: h.getLogUI(arg.SessionID),
LoginUI: h.getLoginUI(arg.SessionID),
ProvisionUI: h.getProvisionUI(arg.SessionID),
SecretUI: h.getSecretUI(arg.SessionID),
GPGUI: h.getGPGUI(arg.SessionID),
}
eng := engine.NewLogin(h.G(), arg.DeviceType, arg.Username)
return engine.RunEngine(eng, ctx)
}