Delete Profile API #367
32
app/app.go
32
app/app.go
|
@ -44,7 +44,7 @@ type Application interface {
|
|||
LoadProfiles(password string)
|
||||
CreatePeer(name string, password string)
|
||||
CreateTaggedPeer(name string, password string, tag string)
|
||||
DeletePeer(onion string)
|
||||
DeletePeer(onion string, currentPassword string) bool
|
||||
AddPeerPlugin(onion string, pluginID plugins.PluginID)
|
||||
ChangePeerPassword(onion, oldpass, newpass string)
|
||||
LaunchPeers()
|
||||
|
@ -142,28 +142,32 @@ func (app *application) CreatePeer(name string, password string) {
|
|||
app.CreateTaggedPeer(name, password, "")
|
||||
}
|
||||
|
||||
func (app *application) DeletePeer(onion string) {
|
||||
func (app *application) DeletePeer(onion string, password string) bool {
|
||||
log.Infof("DeletePeer called on %v\n", onion)
|
||||
app.appmutex.Lock()
|
||||
defer app.appmutex.Unlock()
|
||||
|
||||
app.appletPlugins.ShutdownPeer(onion)
|
||||
app.plugins.Delete(onion)
|
||||
if app.storage[onion].CheckPassword(password) {
|
||||
app.appletPlugins.ShutdownPeer(onion)
|
||||
app.plugins.Delete(onion)
|
||||
|
||||
app.peers[onion].Shutdown()
|
||||
delete(app.peers, onion)
|
||||
app.peers[onion].Shutdown()
|
||||
delete(app.peers, onion)
|
||||
|
||||
app.engines[onion].Shutdown()
|
||||
delete(app.engines, onion)
|
||||
app.engines[onion].Shutdown()
|
||||
delete(app.engines, onion)
|
||||
|
||||
app.storage[onion].Shutdown()
|
||||
app.storage[onion].Delete()
|
||||
delete(app.storage, onion)
|
||||
app.storage[onion].Shutdown()
|
||||
app.storage[onion].Delete()
|
||||
delete(app.storage, onion)
|
||||
|
||||
app.eventBuses[onion].Publish(event.NewEventList(event.ShutdownPeer, event.Identity, onion))
|
||||
app.eventBuses[onion].Publish(event.NewEventList(event.ShutdownPeer, event.Identity, onion))
|
||||
|
||||
app.applicationCore.DeletePeer(onion)
|
||||
log.Debugf("Delete peer for %v Done\n", onion)
|
||||
app.applicationCore.DeletePeer(onion)
|
||||
log.Debugf("Delete peer for %v Done\n", onion)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (app *application) ChangePeerPassword(onion, oldpass, newpass string) {
|
||||
|
|
|
@ -112,10 +112,12 @@ func (ac *applicationClient) CreateTaggedPeer(name, password, tag string) {
|
|||
ac.bridge.Write(&message)
|
||||
}
|
||||
|
||||
// DeletePeer messages tehe service to delete a peer
|
||||
func (ac *applicationClient) DeletePeer(onion string) {
|
||||
message := event.IPCMessage{Dest: DestApp, Message: event.NewEvent(event.DeletePeer, map[event.Field]string{event.Identity: onion})}
|
||||
// DeletePeer messages the service to delete a peer
|
||||
func (ac *applicationClient) DeletePeer(onion string, password string) bool {
|
||||
message := event.IPCMessage{Dest: DestApp, Message: event.NewEvent(event.DeletePeer, map[event.Field]string{event.Identity: onion, event.Password: password})}
|
||||
ac.bridge.Write(&message)
|
||||
// This return value is a lie...
|
||||
return true
|
||||
}
|
||||
|
||||
func (ac *applicationClient) ChangePeerPassword(onion, oldpass, newpass string) {
|
||||
|
|
|
@ -22,6 +22,7 @@ type ProfileStore interface {
|
|||
GetProfileCopy(timeline bool) *model.Profile
|
||||
GetNewPeerMessage() *event.Event
|
||||
GetStatusMessages() []*event.Event
|
||||
CheckPassword(string) bool
|
||||
}
|
||||
|
||||
// CreateProfileWriterStore creates a profile store backed by a filestore listening for events and saving them
|
||||
|
|
|
@ -33,6 +33,12 @@ type ProfileStoreV1 struct {
|
|||
writer bool
|
||||
}
|
||||
|
||||
// CheckPassword returns true if the given password produces the same key as the current stored key, otherwise false.
|
||||
func (ps *ProfileStoreV1) CheckPassword(checkpass string) bool {
|
||||
oldkey := CreateKey(checkpass, ps.salt[:])
|
||||
return oldkey == ps.key
|
||||
}
|
||||
|
||||
func initV1Directory(directory, password string) ([32]byte, [128]byte, error) {
|
||||
key, salt, err := CreateKeySalt(password)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue