Created
July 15, 2016 11:29
-
-
Save kavirajk/21588757af71a700ae64d2b62259fb2f to your computer and use it in GitHub Desktop.
Reset password (unable to mock)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"log" | |
"code.launchyard.com/root/aircto-backend/config" | |
"code.launchyard.com/root/aircto-backend/models" | |
"code.launchyard.com/root/aircto-backend/utils" | |
) | |
var ( | |
email = flag.String("email", "", "user's email to reset the password") | |
password = flag.String("password", "", "new password") | |
) | |
func main() { | |
flag.Parse() | |
if *email == "" { | |
fmt.Print("email: ") | |
fmt.Scanln(email) | |
} | |
if *password == "" { | |
fmt.Print("new-password: ") | |
fmt.Scanln(password) | |
} | |
models.InitModel(config.DBDriver, fmt.Sprintf(config.DBDataSource)) | |
user, err := models.GetUserByEmail(*email) | |
if err != nil { | |
log.Fatalf("error getting user: %v\n", err) | |
} | |
user.Password = utils.HashString(*password) | |
if err := user.Save(); err != nil { | |
log.Fatalf("error saving new password: %v\n", err) | |
} | |
fmt.Println("Password reset success.") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment