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