summaryrefslogtreecommitdiffstats
path: root/web.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2014-04-10 22:21:12 +0800
committerLunny Xiao <xiaolunwen@gmail.com>2014-04-10 22:21:12 +0800
commit94c7278194694fec728b518d4390b03ba6c237a4 (patch)
tree2aebf5fe63423b7b2eb14d58697bab1c95ffb3bb /web.go
parent16b6e5d50b665c5376b61ca7d02e3716a1c05ead (diff)
parent2577940c30f6a6d15390974ab36f8c3d1e00f9f4 (diff)
downloadgitea-94c7278194694fec728b518d4390b03ba6c237a4.tar.gz
gitea-94c7278194694fec728b518d4390b03ba6c237a4.zip
Merge branch 'master' of github.com:gogits/gogs into dev
Conflicts: web.go
Diffstat (limited to 'web.go')
-rw-r--r--web.go39
1 files changed, 20 insertions, 19 deletions
diff --git a/web.go b/web.go
index 248cd8d3d1..af79b2b96b 100644
--- a/web.go
+++ b/web.go
@@ -12,14 +12,15 @@ import (
"github.com/codegangsta/cli"
"github.com/go-martini/martini"
- // "github.com/martini-contrib/oauth2"
- // "github.com/martini-contrib/sessions"
+ qlog "github.com/qiniu/log"
+
"github.com/gogits/binding"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/avatar"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware"
+ "github.com/gogits/gogs/modules/oauth2"
"github.com/gogits/gogs/routers"
"github.com/gogits/gogs/routers/admin"
"github.com/gogits/gogs/routers/api/v1"
@@ -50,27 +51,25 @@ func newMartini() *martini.ClassicMartini {
}
func runWeb(*cli.Context) {
- fmt.Println("Server is running...")
routers.GlobalInit()
- log.Info("%s %s", base.AppName, base.AppVer)
m := newMartini()
// Middlewares.
m.Use(middleware.Renderer(middleware.RenderOptions{Funcs: []template.FuncMap{base.TemplateFuncs}}))
-
- // scope := "https://api.github.com/user"
- // oauth2.PathCallback = "/oauth2callback"
- // m.Use(sessions.Sessions("my_session", sessions.NewCookieStore([]byte("secret123"))))
- // m.Use(oauth2.Github(&oauth2.Options{
- // ClientId: "09383403ff2dc16daaa1",
- // ClientSecret: "5f6e7101d30b77952aab22b75eadae17551ea6b5",
- // RedirectURL: base.AppUrl + oauth2.PathCallback,
- // Scopes: []string{scope},
- // }))
-
m.Use(middleware.InitContext())
+ if base.OauthService != nil {
+ if base.OauthService.GitHub.Enabled {
+ m.Use(oauth2.Github(&oauth2.Options{
+ ClientId: base.OauthService.GitHub.ClientId,
+ ClientSecret: base.OauthService.GitHub.ClientSecret,
+ RedirectURL: base.AppUrl + oauth2.PathCallback[1:],
+ Scopes: []string{base.OauthService.GitHub.Scopes},
+ }))
+ }
+ }
+
reqSignIn := middleware.Toggle(&middleware.ToggleOptions{SignInRequire: true})
ignSignIn := middleware.Toggle(&middleware.ToggleOptions{SignInRequire: base.Service.RequireSignInView})
ignSignInAndCsrf := middleware.Toggle(&middleware.ToggleOptions{
@@ -96,9 +95,11 @@ func runWeb(*cli.Context) {
m.Get("/avatar/:hash", avt.ServeHTTP)
m.Group("/user", func(r martini.Router) {
- // r.Any("/login/github", user.SocialSignIn)
r.Any("/login", binding.BindIgnErr(auth.LogInForm{}), user.SignIn)
+ r.Any("/login/github", oauth2.LoginRequired, user.SocialSignIn)
r.Any("/sign_up", binding.BindIgnErr(auth.RegisterForm{}), user.SignUp)
+ r.Any("/forget_password", user.ForgotPasswd)
+ r.Any("/reset_password", user.ResetPasswd)
}, reqSignOut)
m.Group("/user", func(r martini.Router) {
r.Any("/logout", user.SignOut)
@@ -152,6 +153,7 @@ func runWeb(*cli.Context) {
r.Get("/issues", repo.Issues)
r.Get("/issues/:index", repo.ViewIssue)
r.Get("/releases", repo.Releases)
+ r.Any("/releases/new", repo.ReleasesNew)
r.Get("/pulls", repo.Pulls)
r.Get("/branches", repo.Branches)
}, ignSignIn, middleware.RepoAssignment(true))
@@ -181,14 +183,13 @@ func runWeb(*cli.Context) {
if protocol == "http" {
log.Info("Listen: http://%s", listenAddr)
if err := http.ListenAndServe(listenAddr, m); err != nil {
- fmt.Println(err.Error())
- //log.Critical(err.Error()) // not working now
+ qlog.Error(err.Error())
}
} else if protocol == "https" {
log.Info("Listen: https://%s", listenAddr)
if err := http.ListenAndServeTLS(listenAddr, base.Cfg.MustValue("server", "CERT_FILE"),
base.Cfg.MustValue("server", "KEY_FILE"), m); err != nil {
- fmt.Println(err.Error())
+ qlog.Error(err.Error())
}
}
}