/
account_delete.go
78 lines (65 loc) · 1.96 KB
/
account_delete.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
// Copyright 2016 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
// This engine deletes the user's account.
package engine
import (
"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/protocol/keybase1"
)
// AccountDelete is an engine.
type AccountDelete struct {
libkb.Contextified
passphrase *string
}
// NewAccountDelete creates a AccountDelete engine.
func NewAccountDelete(g *libkb.GlobalContext, passphrase *string) *AccountDelete {
return &AccountDelete{
Contextified: libkb.NewContextified(g),
passphrase: passphrase,
}
}
// Name is the unique engine name.
func (e *AccountDelete) Name() string {
return "AccountDelete"
}
// Prereqs returns the engine prereqs.
func (e *AccountDelete) Prereqs() Prereqs {
return Prereqs{
Device: true,
}
}
// RequiredUIs returns the required UIs.
func (e *AccountDelete) RequiredUIs() []libkb.UIKind {
return []libkb.UIKind{}
}
// SubConsumers returns the other UI consumers for this engine.
func (e *AccountDelete) SubConsumers() []libkb.UIConsumer {
return nil
}
// Run starts the engine.
func (e *AccountDelete) Run(m libkb.MetaContext) error {
username := m.G().GetEnv().GetUsername()
passphraseState, err := libkb.LoadPassphraseState(m)
if err != nil {
return err
}
var passphrase *string
if e.passphrase == nil && passphraseState == keybase1.PassphraseState_KNOWN {
// Passphrase is required to create PDPKA, but that's not required for
// randomPW users.
arg := libkb.DefaultPassphrasePromptArg(m, username.String())
res, err := m.UIs().SecretUI.GetPassphrase(arg, nil)
if err != nil {
return err
}
passphrase = &res.Passphrase
} else if passphraseState == keybase1.PassphraseState_KNOWN {
passphrase = e.passphrase
}
err = libkb.DeleteAccount(m, username, passphrase)
if err != nil {
return err
}
m.Debug("account deleted, logging out")
return m.LogoutWithOptions(libkb.LogoutOptions{KeepSecrets: false, Force: true})
}