예제 #1
0
파일: initDB.go 프로젝트: ohko/gmdd
func runInit(ctx *cli.Context) {

	pass := ctx.String("password")
	if pass == "" {
		fmt.Println("Please password: --password ******")
		return
	}

	libs.DB.Exec("SET FOREIGN_KEY_CHECKS = 0")

	// drop
	if err := libs.DB.DropTables(
		new(model.Category),
		new(model.Tag),
		new(model.Md),
		new(model.MdTag),
		new(model.User),
	); err != nil {
		panic(err.Error())
	}

	// create
	if err := libs.DB.Sync2(
		new(model.Category),
		new(model.Tag),
		new(model.Md),
		new(model.MdTag),
		new(model.User),
	); err != nil {
		panic(err.Error())
	}

	pass_md5 := md5.New()
	pass_md5.Write([]byte(pass))

	user := new(model.User)
	user.User = "******"
	user.Pass = hex.EncodeToString(pass_md5.Sum(nil))
	libs.DB.Insert(user)

	cat := new(model.Category)
	cat.Id = 1
	cat.Name = "default"
	libs.DB.Insert(cat)

	libs.DB.Exec("ALTER TABLE `" + libs.Conf["PREFIX"] + "md` ADD FOREIGN KEY (`category_id`) REFERENCES `" + libs.Conf["PREFIX"] + "category` (`id`)")
	libs.DB.Exec("ALTER TABLE `" + libs.Conf["PREFIX"] + "md_tag` ADD FOREIGN KEY (`md_id`) REFERENCES `" + libs.Conf["PREFIX"] + "md` (`id`)")
	libs.DB.Exec("ALTER TABLE `" + libs.Conf["PREFIX"] + "md_tag` ADD FOREIGN KEY (`tag_id`) REFERENCES `" + libs.Conf["PREFIX"] + "tag` (`id`)")
	libs.DB.Exec("SET FOREIGN_KEY_CHECKS = 1")
}
예제 #2
0
파일: resetPassword.go 프로젝트: ohko/gmdd
func runResetPassword(ctx *cli.Context) {

	pass := ctx.String("resetPass")
	if pass == "" {
		fmt.Println("Please password: --password ******")
		return
	}

	pass_md5 := md5.New()
	pass_md5.Write([]byte(pass))

	user := new(model.User)
	user.User = "******"
	user.Pass = hex.EncodeToString(pass_md5.Sum(nil))
	libs.DB.Where("id=1").Update(user)
}