summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorUnknwon <joe2010xtmf@163.com>2014-12-05 17:54:57 -0500
committerUnknwon <joe2010xtmf@163.com>2014-12-05 17:54:57 -0500
commit069486d169d7adac902a310e10b6580857735880 (patch)
tree18966a493e6d1d8d57bb8c9ef56ec65a16604db3 /modules
parent298ebc58c1bc79375248e4b0be173201b935b742 (diff)
downloadgitea-069486d169d7adac902a310e10b6580857735880.tar.gz
gitea-069486d169d7adac902a310e10b6580857735880.zip
fix #165
Diffstat (limited to 'modules')
-rw-r--r--modules/auth/auth.go20
-rw-r--r--modules/setting/setting.go19
2 files changed, 29 insertions, 10 deletions
diff --git a/modules/auth/auth.go b/modules/auth/auth.go
index 302620dbc8..5b7276b48a 100644
--- a/modules/auth/auth.go
+++ b/modules/auth/auth.go
@@ -60,6 +60,7 @@ func SignedInId(req *http.Request, sess session.Store) int64 {
}
// SignedInUser returns the user object of signed user.
+// It returns a bool value to indicate whether user uses basic auth or not.
func SignedInUser(req *http.Request, sess session.Store) (*models.User, bool) {
if !models.HasEngine {
return nil, false
@@ -75,8 +76,25 @@ func SignedInUser(req *http.Request, sess session.Store) (*models.User, bool) {
if err != nil {
if err != models.ErrUserNotExist {
log.Error(4, "GetUserByName: %v", err)
+ return nil, false
+ }
+
+ // Check if enabled auto-registeration.
+ if setting.Service.EnableReverseProxyAutoRegister {
+ u := &models.User{
+ Name: webAuthUser,
+ Email: webAuthUser + "@gogs.io",
+ Passwd: webAuthUser,
+ IsActive: true,
+ }
+ if err = models.CreateUser(u); err != nil {
+ // FIXME: should I create a system notice?
+ log.Error(4, "CreateUser: %v", err)
+ return nil, false
+ } else {
+ return u, false
+ }
}
- return nil, false
}
return u, false
}
diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index 476fc6affa..b1efc9c7a8 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -300,15 +300,15 @@ func NewConfigContext() {
}
var Service struct {
- RegisterEmailConfirm bool
- DisableRegistration bool
- RequireSignInView bool
- EnableCacheAvatar bool
- EnableNotifyMail bool
- EnableReverseProxyAuth bool
- LdapAuth bool
- ActiveCodeLives int
- ResetPwdCodeLives int
+ RegisterEmailConfirm bool
+ DisableRegistration bool
+ RequireSignInView bool
+ EnableCacheAvatar bool
+ EnableNotifyMail bool
+ EnableReverseProxyAuth bool
+ EnableReverseProxyAutoRegister bool
+ ActiveCodeLives int
+ ResetPwdCodeLives int
}
func newService() {
@@ -318,6 +318,7 @@ func newService() {
Service.RequireSignInView = Cfg.MustBool("service", "REQUIRE_SIGNIN_VIEW")
Service.EnableCacheAvatar = Cfg.MustBool("service", "ENABLE_CACHE_AVATAR")
Service.EnableReverseProxyAuth = Cfg.MustBool("service", "ENABLE_REVERSE_PROXY_AUTHENTICATION")
+ Service.EnableReverseProxyAutoRegister = Cfg.MustBool("service", "ENABLE_REVERSE_PROXY_AUTO_REGISTERATION")
}
var logLevels = map[string]string{