MCPcopy
hub / github.com/writefreely/writefreely / DoDeleteAccount

Function DoDeleteAccount

app.go:802–845  ·  view source on GitHub ↗

DoDeleteAccount runs the confirmation and account delete process.

(apper Apper, username string)

Source from the content-addressed store, hash-verified

800
801// DoDeleteAccount runs the confirmation and account delete process.
802func DoDeleteAccount(apper Apper, username string) error {
803 // Connect to the database
804 apper.LoadConfig()
805 connectToDatabase(apper.App())
806 defer shutdown(apper.App())
807
808 // check user exists
809 u, err := apper.App().db.GetUserForAuth(username)
810 if err != nil {
811 log.Error("%s", err)
812 os.Exit(1)
813 }
814 userID := u.ID
815
816 // do not delete the admin account
817 // TODO: check for other admins and skip?
818 if u.IsAdmin() {
819 log.Error("Can not delete admin account")
820 os.Exit(1)
821 }
822
823 // confirm deletion, w/ w/out posts
824 prompt := promptui.Prompt{
825 Templates: &promptui.PromptTemplates{
826 Success: "{{ . | bold | faint }}: ",
827 },
828 Label: fmt.Sprintf("Really delete user : %s", username),
829 IsConfirm: true,
830 }
831 _, err = prompt.Run()
832 if err != nil {
833 log.Info("Aborted...")
834 os.Exit(0)
835 }
836
837 log.Info("Deleting...")
838 err = apper.App().db.DeleteAccount(userID)
839 if err != nil {
840 log.Error("%s", err)
841 os.Exit(1)
842 }
843 log.Info("Success.")
844 return nil
845}
846
847func connectToDatabase(app *App) {
848 log.Info("Connecting to %s database...", app.cfg.Database.Type)

Callers 2

delUserActionFunction · 0.92
legacyActionsFunction · 0.92

Calls 7

connectToDatabaseFunction · 0.85
shutdownFunction · 0.85
IsAdminMethod · 0.80
LoadConfigMethod · 0.65
AppMethod · 0.65
GetUserForAuthMethod · 0.65
DeleteAccountMethod · 0.65

Tested by

no test coverage detected