//初始化的函数,设置验证码 func init() { store := cache.NewMemoryCache() capt = captcha.NewWithFilter("/captcha/", store) capt.StdWidth = 120 capt.StdHeight = 40 capt.ChallengeNums = 4 }
func LoadConfig() { redisServer := beego.AppConfig.String("redis_resource") redisServer = "{\"conn\":\"" + redisServer + "\"}" store, err := cache.NewCache("redis", redisServer) if err != nil { log.Panic("缓存出错" + err.Error()) } Captcha = captcha.NewWithFilter("/captcha/", store) driverName := beego.AppConfig.String("driverName") dataSource := beego.AppConfig.String("dataSource") maxIdle, _ := beego.AppConfig.Int("maxIdle") maxOpen, _ := beego.AppConfig.Int("maxOpen") orm.RegisterDriver("mysql", orm.DR_MySQL) // set default database err = orm.RegisterDataBase("default", driverName, dataSource, maxIdle, maxOpen) if err != nil { beego.Error(err) } orm.RunCommand() err = orm.RunSyncdb("default", false, false) if err != nil { beego.Error(err) } SocialAuthInit() config.InitConfig() }
func init() { // init captcha store := cache.NewMemoryCache() cpt = captcha.NewWithFilter("/captcha/", store) cpt.ChallengeNums = 4 cpt.StdWidth = 120 cpt.StdHeight = 60 // init db orm.RegisterDriver("sqlite", orm.DRSqlite) orm.RegisterDataBase("default", "sqlite3", "./idoc_data.db") orm.RunSyncdb("default", false, true) }
func init() { // read config from file EmailUser = beego.AppConfig.String("EmailUser") EmailPasswd = beego.AppConfig.String("EmailPasswd") if pwd, err := utils.AesDecrypt(EmailPasswd); err != nil { panic(err) } else { EmailPasswd = pwd } EmailHost = beego.AppConfig.String("EmailHost") Log = logs.NewLogger(1000) Log.Async() Log.SetLogger("console", "") // 较简单的校验码 store := cache.NewMemoryCache() Cpt = captcha.NewWithFilter("/captcha/", store) }
func (this *Util) Captcha() { cpt := captcha.NewWithFilter("/captcha/", bm) Debug(cpt) }
func init() { store := cache.NewMemoryCache() cpt = captcha.NewWithFilter("/captcha/", store) }
func init() { // use beego cache system store the captcha data store := cache.NewMemoryCache() cpt = captcha.NewWithFilter("/captcha/", store) }
func ReadConfig() { var err error AppName = beego.AppConfig.String("appname") AppHost = beego.AppConfig.String("apphost") AppUrl = beego.AppConfig.String("appurl") AppLogo = beego.AppConfig.String("applogo") TmpPath = beego.AppConfig.String("tmppath") CookieUserName = beego.AppConfig.String("cookieusername") CookieRememberName = beego.AppConfig.String("CookieRememberName") MySQLHost = beego.AppConfig.String("mysql::host") MySQLUser = beego.AppConfig.String("mysql::user") MySQLPassword = beego.AppConfig.String("mysql::password") MySQLDB = beego.AppConfig.String("mysql::db") MongodbHost = beego.AppConfig.String("mongodb::host") MongodbName = beego.AppConfig.String("mongodb::name") RedisHost = beego.AppConfig.String("redis::host") RedisPort = beego.AppConfig.String("redis::port") SendcloudDomain = beego.AppConfig.String("sendcloud::domain") SendcloudUser = beego.AppConfig.String("sendcloud::user") SendcloudKey = beego.AppConfig.String("sendcloud::key") From = beego.AppConfig.String("sendcloud::from") FromName = beego.AppConfig.String("sendcloud::fromname") if err := orm.RegisterDriver("mysql", orm.DR_MySQL); err != nil { beego.Error("mysql", err) ConfigBroken = true } if err := orm.RegisterDataBase("default", "mysql", fmt.Sprintf("%s:%s@tcp(%s:3306)/%s?charset=utf8", MySQLUser, MySQLPassword, MySQLHost, MySQLDB)+"&loc=Asia%2FShanghai", 30); err != nil { beego.Error("mysql", err) ConfigBroken = true } MongodbSession, err = mgo.Dial(MongodbHost) if err != nil { beego.Error("mongodb", err) ConfigBroken = true } // cache system Cache, err = cache.NewCache("redis", fmt.Sprintf(`{"conn":"%s:%s"}`, RedisHost, RedisPort)) if err != nil { beego.Error("cache", err) ConfigBroken = true } Captcha = captcha.NewWithFilter("/captcha/", Cache) Captcha.FieldIdName = "captcha-id" Captcha.FieldCaptchaName = "captcha" beego.SessionOn = true beego.SessionProvider = "redis" beego.SessionSavePath = RedisHost + ":" + RedisPort beego.SessionCookieLifeTime = 0 beego.SessionGCMaxLifetime = 86400 //todo 更好的利用mongodb session avatarstore := beego.AppConfig.String("avatar::store") switch avatarstore { case "local": avatarConfig := filestore.Config{FSPath: beego.AppConfig.String("avatar::local_path"), UrlPrefix: beego.AppConfig.String("avatar::url")} AvatarFSM, err = filestore.NewManager(avatarstore, avatarConfig) } if err != nil { beego.Error(err) } //初始化sendcloud,用来发送邮件 Sendcloud = sendcloud.New() Sendcloud.AddDomain(SendcloudDomain, SendcloudUser, SendcloudKey) //StopForumSpam StopForumSpam = stopforumspam.New(beego.AppConfig.String("stopforumspam::key")) //社交帐号登录 GithubClientId = beego.AppConfig.String("oauth::github_client_id") GithubClientSecret = beego.AppConfig.String("oauth::github_client_secret") QQClientId = beego.AppConfig.String("oauth::qq_client_id") QQClientSecret = beego.AppConfig.String("oauth::qq_client_secret") WeiboClientId = beego.AppConfig.String("oauth::weibo_client_id") WeiboClientSecret = beego.AppConfig.String("oauth::weibo_client_secret") }