Beispiel #1
0
func (this *ReplyController) Delete() {

	tid := this.Input().Get("tid")
	beego.Alert(tid)
	beego.Alert(tid)

	if !checkAccount(this.Ctx) {
		return
	}

	var err error
	switch beego.AppConfig.String("database") {
	case "redis":
		err = models.DeleteReplyRedis(this.Input().Get("rid"))
	default:
		err = models.DeleteReply(this.Input().Get("rid"))
	}

	if err != nil {
		beego.Error(err)
	}

	this.Redirect("/topic/view?tid="+tid, 302)
}
Beispiel #2
0
func init() {
	err := orm.RegisterDataBase(
		"default",
		"mysql",
		fmt.Sprintf(DBS,
			beego.AppConfig.String("database::mysqluser"),
			beego.AppConfig.String("database::mysqlpass"),
			beego.AppConfig.String("database::mysqlurl"),
			beego.AppConfig.String("database::mysqldb"),
		),
	)
	if err != nil {
		beego.Alert(err)
	}
}
Beispiel #3
0
//20151006添加添加用户头像逻辑
// @router /api/users/changs/userheadpic [post]
func (u *UserController) AddUserHeadPic() {
	picfliter := [2]string{"jpg", "png"}
	var uc models.UserCore
	var ok bool
	uc.UserName, ok = u.GetSession("longined").(string)
	if !ok {
		u.Data["json"] = models.ErrorContext{Err: "发生了未知错误"}
		u.ServeJson()
	} else {
		f, fh, err := u.GetFile("userheadpic")
		if err != nil {
			beego.Error(err.Error())
			u.Abort("404")
		}
		defer f.Close()
		arr := strings.Split(fh.Filename, ".")
		ok = false
		for _, v := range picfliter {
			if v == arr[len(arr)-1] {
				ok = true
			}
		}
		if ok {
			picname := fmt.Sprintf("%s.%s", uc.UserName, arr[len(arr)-1])
			picpath := "./static/img/UserPic/headPic/" + picname
			beego.Notice(picpath)
			uc.UserPic = picname
			fheadle, err := os.OpenFile(picpath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
			if err != nil {
				beego.Error(err.Error())
			}
			defer fheadle.Close()
			io.Copy(fheadle, f)
			err = models.AddUserPic(uc)
			if err != nil {
				beego.Alert(err.Error())
				u.Data["json"] = models.ErrorContext{Err: "发生了未知错误"}
				u.ServeJson()
			} else {
				u.Data["json"] = models.ErrorContext{Data: "上传成功"}
				u.ServeJson()
			}
		}
	}
}
Beispiel #4
0
func main() {
	beego.Info("ModuleAB server", version.Version, "starting...")
	logfile := beego.AppConfig.String("logFile")
	if logfile == "" {
		logfile = "logs/moduleab_server.log"
	}
	err := beego.SetLogger("file", fmt.Sprintf(`{"filename":"%s"}`, logfile))
	if err != nil {
		panic(err)
	}
	beego.SetLevel(beego.LevelInformational)

	beego.Info("Hello!")

	// 别用root运行我!
	if os.Getuid() == 0 {
		beego.Alert("Hey! You're running this server with user root!")
		panic("Don't run me with root!")
	}

	switch beego.BConfig.RunMode {
	case "initdb":
		beego.Info("Got runmode: Initialize database")
		err = orm.RunSyncdb("default", true, true)
		orm.Debug = true
		policies.InitDb()
		beego.Info("Database is ready")
		os.Exit(0)

	case "dev":
		beego.Info("Got runmode: Development")
		beego.SetLevel(beego.LevelDebug)
		beego.BConfig.WebConfig.DirectoryIndex = true
		beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"

		beego.Debug("Now import database")
		orm.Debug = true
		err = orm.RunSyncdb("default", false, true)

	case "deb":
		beego.Info("Got runmode: Debug")
		beego.SetLevel(beego.LevelDebug)

		beego.Debug("Now import database")
		orm.Debug = true
		err = orm.RunSyncdb("default", false, true)

	default:
		beego.BeeLogger.DelLogger("console")
		err = orm.RunSyncdb("default", false, false)
	}
	if err != nil {
		beego.Alert("Database error:", err, ". go exit.")
		os.Exit(1)
	}
	beego.Debug("Current PID:", os.Getpid())
	ioutil.WriteFile(
		beego.AppConfig.String("pidFile"),
		[]byte(fmt.Sprint(os.Getpid())),
		0600,
	)
	beego.Info("Run check oas job...")
	go policies.CheckOasJob()
	beego.Info("All is ready, go running...")
	beego.BConfig.WebConfig.Session.SessionOn = true
	beego.BConfig.WebConfig.Session.SessionName = "Session_MobuleAB"
	beego.Run()
	defer func() {
		x := recover()
		if x != nil {
			beego.Error("Got fatal error:", x)
			stack := make([]byte, 0)
			runtime.Stack(stack, true)
			beego.Error("Stack trace:\n", string(stack))
			os.Exit(1)
		}
	}()
}