Ejemplo n.º 1
0
func init() {
	// Filters is the default set of global filters.
	revel.Filters = []revel.Filter{
		revel.PanicFilter,             // Recover from panics and display an error page instead.
		revel.I18nFilter,              // Resolve the requested language
		revel.RouterFilter,            // Use the routing table to select the right Action
		revel.FilterConfiguringFilter, // A hook for adding or removing per-Action filters.
		revel.ParamsFilter,            // Parse parameters into Controller.Params.
		revel.SessionFilter,           // Restore and write the session cookie.
		csrf.CSRFFilter,
		revel.FlashFilter,       // Restore and write the flash cookie.
		revel.ValidationFilter,  // Restore kept validation errors and save new ones from cookie.
		HeaderFilter,            // Add xnsome security based headers
		revel.InterceptorFilter, // Run interceptors around the action.
		revel.CompressFilter,    // Compress the result.
		revel.ActionInvoker,     // Invoke the action.
	}
	revel.OnAppStart(models.InitDB)
	revel.InterceptFunc(setNickname, revel.BEFORE, &pages.ShopPage{})
	revel.InterceptFunc(setNickname, revel.BEFORE, &pages.Authentication{})
	revel.InterceptFunc(setNickname, revel.BEFORE, &pages.Admin{})
	revel.InterceptFunc(redirectAuthenticationPageForAdmin, revel.BEFORE, &pages.Admin{})

	// register startup functions with OnAppStart
	// ( order dependent )
	// revel.OnAppStart(InitDB)
	// revel.OnAppStart(FillCache)
}
Ejemplo n.º 2
0
func init() {
	// Filters is the default set of global filters.
	revel.Filters = []revel.Filter{
		revel.PanicFilter,             // Recover from panics and display an error page instead.
		revel.RouterFilter,            // Use the routing table to select the right Action
		revel.FilterConfiguringFilter, // A hook for adding or removing per-Action filters.
		revel.ParamsFilter,            // Parse parameters into Controller.Params.
		revel.SessionFilter,           // Restore and write the session cookie.
		revel.FlashFilter,             // Restore and write the flash cookie.
		revel.ValidationFilter,        // Restore kept validation errors and save new ones from cookie.
		revel.I18nFilter,              // Resolve the requested language
		HeaderFilter,                  // Add some security based headers
		revel.InterceptorFilter,       // Run interceptors around the action.
		revel.CompressFilter,          // Compress the result.
		revel.ActionInvoker,           // Invoke the action.
	}

	// register startup functions with OnAppStart
	// ( order dependent )
	// revel.OnAppStart(InitDB)
	// revel.OnAppStart(FillCache)
	// 注册模板里的字符串相加函数
	revel.TemplateFuncs["sp2bk"] = func(a string) string {
		return strings.Replace(a, " ", " ", -1)
	}

	// 对访问者身份进行验证
	revel.InterceptFunc(checkRole, revel.BEFORE, &controllers.Admin{})
	revel.InterceptFunc(checkRole, revel.BEFORE, &controllers.Picture{})
}
Ejemplo n.º 3
0
func init() {
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &MemberIndex{})
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &MemberUser{})
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &MemberBlog{})
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &MemberGroup{})
	revel.OnAppStart(func() {
	})
}
Ejemplo n.º 4
0
func init() {
	revel.OnAppStart(InitDB)
	revel.InterceptFunc(checkUser, revel.BEFORE, &Post{})
	revel.InterceptFunc(checkUser, revel.BEFORE, &Profile{})
	revel.InterceptFunc(checkUser, revel.BEFORE, &Asset{})

	revel.InterceptFunc(adminOnly, revel.BEFORE, &Contributor{})
	revel.InterceptFunc(adminOnly, revel.BEFORE, &SiteInfo{})
	//revel.InterceptFunc(adminOnly, revel.BEFORE, &Category{})
	revel.InterceptMethod((*GormController).Begin, revel.BEFORE)
	revel.InterceptMethod((*GormController).Commit, revel.AFTER)
	revel.InterceptMethod((*GormController).RollBack, revel.FINALLY)

	revel.TemplateFuncs["config"] = func(key string) string {
		return revel.Config.StringDefault(key, "")
	}
}
Ejemplo n.º 5
0
func init() {
	// interceptor
	// revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Index{}) // Index.Note自己校验
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Notebook{})
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Note{})
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Share{})
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &User{})
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &File{})
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Blog{})
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &NoteContentHistory{})

	// service

	userService = &service.UserService{}
	noteService = &service.NoteService{}
	trashService = &service.TrashService{}
	notebookService = &service.NotebookService{}
	noteContentHistoryService = &service.NoteContentHistoryService{}
	authService = &service.AuthService{}
	shareService = &service.ShareService{}
	blogService = &service.BlogService{}
	tagService = &service.TagService{}
	pwdService = &service.PwdService{}
	tokenService = &service.TokenService{}
	suggestionService = &service.SuggestionService{}

	revel.OnAppStart(func() {
		leanoteUserId, _ = revel.Config.String("adminUsername")
		siteUrl, _ = revel.Config.String("site.url")
		openRegister, _ = revel.Config.Bool("register.open")
	})
}
Ejemplo n.º 6
0
func init() {
	revel.InterceptFunc(CheckUserAuth, revel.BEFORE, revel.ALL_CONTROLLERS)

	revel.OnAppStart(func() {
		ServersMap, ServersLastError = models.LoadServers()
		if ServersLastError != nil {
			revel.ERROR.Print(ServersLastError)
		}
	})
}
Ejemplo n.º 7
0
func init() {
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Admin{})
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &AdminSetting{})
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &AdminUser{})
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &AdminBlog{})
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &AdminEmail{})
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &AdminUpgrade{})
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &AdminData{})
}
Ejemplo n.º 8
0
func init() {
	// interceptors
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &ApiAuth{})
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &ApiUser{})
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &ApiFile{})
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &ApiNote{})
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &ApiTag{})
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &ApiNotebook{})
}
Ejemplo n.º 9
0
func init() {
	// interceptor
	// revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Index{}) // Index.Note自己校验
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Notebook{})
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Note{})
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Share{})
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &User{})
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Album{})
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &File{})
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Attach{})
	//	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Blog{})
	revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &NoteContentHistory{})

	revel.OnAppStart(func() {
		// 博客初始化模板
		blog.Init()
	})
}
Ejemplo n.º 10
0
func init() {
	revel.OnAppStart(Bootstrap)

	//检测是否登陆
	revel.InterceptFunc(CheckLogin, revel.BEFORE, revel.ALL_CONTROLLERS)
}
Ejemplo n.º 11
0
func init() {
	revel.InterceptFunc(CheckLogin, revel.BEFORE, &Cmds{})
}
Ejemplo n.º 12
0
func InitControllers() {

	revel.InterceptMethod(CheckCourseraMode, revel.BEFORE)
	revel.InterceptMethod(PublicApplication.AddUser, revel.BEFORE)
	revel.InterceptMethod(CheckWorker, revel.BEFORE)
	revel.InterceptFunc(CheckUser, revel.BEFORE, &SecuredApplication{})
	if CourseraMode {
		revel.InterceptFunc(CheckUser, revel.BEFORE, &CourseraApplication{})
	}

	revel.TemplateFuncs["rfc3339"] = func(t time.Time) string {
		return t.Format(time.RFC3339)
	}
	revel.TemplateFuncs["lower"] = func(s string) string {
		return strings.ToLower(s)
	}
	revel.TemplateFuncs["plus"] = func(x int, y int) int {
		return x + y
	}
	revel.TemplateFuncs["shorten"] = func(s string) string {
		if len(s) > 60 {
			bs := []byte(s)
			return string(bs[:60]) + "..."
		} else {
			return s
		}
	}
	revel.TemplateFuncs["percentageToInt"] = func(f float32) int {
		return int(f * 100)
	}
	revel.TemplateFuncs["splitComma"] = func(str string) []string {
		return strings.Split(str, ",")
	}
	revel.TemplateFuncs["positiveQ"] = func(i int) bool {
		return i > 0
	}
	revel.TemplateFuncs["notEmpty"] = func(xs interface{}) bool {
		vxs := reflect.ValueOf(xs)
		return vxs.Len() > 0
	}
	revel.TemplateFuncs["loggerClass"] = func(s string) (class string) {
		switch s {
		case "Fatal":
		case "Error":
			class = "danger"
		case "Warn":
			class = "warning"
		case "Info":
		case "Debug":
			class = "active"
		default:
			class = ""
		}
		return
	}
	revel.TemplateFuncs["milliSeconds"] = func(t int64) float64 {
		return float64(t) / 1000000.0
	}

	MPFileDirectory = filepath.Join(revel.BasePath, "mp")
	createBigCodeDatabaseMutex = &sync.Mutex{}
	if CourseraMode {
		InitCourseraController()
	}
	if IsMaster {
		InitAdminController()
	}
}
Ejemplo n.º 13
0
func init() {
	revel.InterceptFunc(checkDataTypeParam, revel.BEFORE, &Synchronization{})
}
Ejemplo n.º 14
0
func init() {
	revel.InterceptFunc(defaultRenderArgs, revel.BEFORE, &App{})
}
Ejemplo n.º 15
0
func init() {
	revel.InterceptFunc(setuser, revel.BEFORE, &App{})
}
Ejemplo n.º 16
0
func init() {
	revel.InterceptFunc(CheckLoginAdmin, revel.BEFORE, &Users{})
}