func InitApp() { initTemplates() initLocales() watcher, err := fsnotify.NewWatcher() if err != nil { panic("Failed start app watcher: " + err.Error()) } go func() { for { select { case event := <-watcher.Event: switch filepath.Ext(event.Name) { case ".ini": log.Info(event) if err := i18n.ReloadLangs(); err != nil { log.Error("Conf Reload: ", err) } log.Info("Config Reloaded") case ".json": if event.Name == CompressConfPath { log.Info("Beego Compress Reloaded") } } } } }() if err := watcher.WatchFlags("conf", fsnotify.FSN_MODIFY); err != nil { log.Error(err) } }
func (auth *XormAuth) CheckPasswd(userName, pass string) bool { if auth.allowAnony && userName == "anonymous" { return true } var user = User{Name: userName} has, err := auth.orm.Get(&user) if err != nil { log.Error(err) return false } if !has { return false } return user.Pass == auth.encryptFunc(pass) }
func initLocales() { // Initialized language type list. langs := strings.Split(models.Cfg.MustValue("lang", "types"), "|") names := strings.Split(models.Cfg.MustValue("lang", "names"), "|") langTypes = make([]*langType, 0, len(langs)) for i, v := range langs { langTypes = append(langTypes, &langType{ Lang: v, Name: names[i], }) } for _, lang := range langs { log.Debug("Loading language: " + lang) if err := i18n.SetMessage(lang, "conf/"+"locale_"+lang+".ini"); err != nil { log.Error("Fail to set message file: " + err.Error()) return } } }