MCPcopy
hub / github.com/writefreely/writefreely / ResetPassword

Function ResetPassword

app.go:763–799  ·  view source on GitHub ↗

ResetPassword runs the interactive password reset process.

(apper Apper, username string)

Source from the content-addressed store, hash-verified

761
762// ResetPassword runs the interactive password reset process.
763func ResetPassword(apper Apper, username string) error {
764 // Connect to the database
765 apper.LoadConfig()
766 connectToDatabase(apper.App())
767 defer shutdown(apper.App())
768
769 // Fetch user
770 u, err := apper.App().db.GetUserForAuth(username)
771 if err != nil {
772 log.Error("Get user: %s", err)
773 os.Exit(1)
774 }
775
776 // Prompt for new password
777 prompt := promptui.Prompt{
778 Templates: &promptui.PromptTemplates{
779 Success: "{{ . | bold | faint }}: ",
780 },
781 Label: "New password",
782 Mask: '*',
783 }
784 newPass, err := prompt.Run()
785 if err != nil {
786 log.Error("%s", err)
787 os.Exit(1)
788 }
789
790 // Do the update
791 log.Info("Updating...")
792 err = adminResetPassword(apper.App(), u, newPass)
793 if err != nil {
794 log.Error("%s", err)
795 os.Exit(1)
796 }
797 log.Info("Success.")
798 return nil
799}
800
801// DoDeleteAccount runs the confirmation and account delete process.
802func DoDeleteAccount(apper Apper, username string) error {

Callers 2

resetPassActionFunction · 0.92
legacyActionsFunction · 0.92

Calls 6

connectToDatabaseFunction · 0.85
shutdownFunction · 0.85
adminResetPasswordFunction · 0.85
LoadConfigMethod · 0.65
AppMethod · 0.65
GetUserForAuthMethod · 0.65

Tested by

no test coverage detected