aboutsummaryrefslogtreecommitdiff
path: root/modules/auth
diff options
context:
space:
mode:
Diffstat (limited to 'modules/auth')
-rw-r--r--modules/auth/auth.go15
-rw-r--r--modules/auth/auth_form.go1
-rw-r--r--modules/auth/pam/pam.go35
-rw-r--r--modules/auth/pam/pam_stub.go15
-rw-r--r--modules/auth/user_form.go51
5 files changed, 94 insertions, 23 deletions
diff --git a/modules/auth/auth.go b/modules/auth/auth.go
index 5b24591a..42346430 100644
--- a/modules/auth/auth.go
+++ b/modules/auth/auth.go
@@ -21,6 +21,10 @@ import (
"github.com/gogits/gogs/modules/uuid"
)
+func IsAPIPath(url string) bool {
+ return strings.HasPrefix(url, "/api/")
+}
+
// SignedInId returns the id of signed in user.
func SignedInId(req *http.Request, sess session.Store) int64 {
if !models.HasEngine {
@@ -28,7 +32,7 @@ func SignedInId(req *http.Request, sess session.Store) int64 {
}
// API calls need to check access token.
- if strings.HasPrefix(req.URL.Path, "/api/") {
+ if IsAPIPath(req.URL.Path) {
auHead := req.Header.Get("Authorization")
if len(auHead) > 0 {
auths := strings.Fields(auHead)
@@ -208,7 +212,14 @@ func validate(errs binding.Errors, data map[string]interface{}, f Form, l macaro
if errs[0].FieldNames[0] == field.Name {
data["Err_"+field.Name] = true
- trName := l.Tr("form." + field.Name)
+
+ trName := field.Tag.Get("locale")
+ if len(trName) == 0 {
+ trName = l.Tr("form." + field.Name)
+ } else {
+ trName = l.Tr(trName)
+ }
+
switch errs[0].Classification {
case binding.ERR_REQUIRED:
data["ErrorMsg"] = trName + l.Tr("form.require_error")
diff --git a/modules/auth/auth_form.go b/modules/auth/auth_form.go
index 7d459999..1102dc34 100644
--- a/modules/auth/auth_form.go
+++ b/modules/auth/auth_form.go
@@ -30,6 +30,7 @@ type AuthenticationForm struct {
SMTPPort int `form:"smtp_port"`
TLS bool `form:"tls"`
AllowAutoRegister bool `form:"allowautoregister"`
+ PAMServiceName string
}
func (f *AuthenticationForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
diff --git a/modules/auth/pam/pam.go b/modules/auth/pam/pam.go
new file mode 100644
index 00000000..7f326d42
--- /dev/null
+++ b/modules/auth/pam/pam.go
@@ -0,0 +1,35 @@
+// +build pam
+
+// Copyright 2014 The Gogs Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package pam
+
+import (
+ "errors"
+
+ "github.com/msteinert/pam"
+)
+
+func PAMAuth(serviceName, userName, passwd string) error {
+ t, err := pam.StartFunc(serviceName, userName, func(s pam.Style, msg string) (string, error) {
+ switch s {
+ case pam.PromptEchoOff:
+ return passwd, nil
+ case pam.PromptEchoOn, pam.ErrorMsg, pam.TextInfo:
+ return "", nil
+ }
+ return "", errors.New("Unrecognized PAM message style")
+ })
+
+ if err != nil {
+ return err
+ }
+
+ if err = t.Authenticate(0); err != nil {
+ return err
+ }
+
+ return nil
+}
diff --git a/modules/auth/pam/pam_stub.go b/modules/auth/pam/pam_stub.go
new file mode 100644
index 00000000..33ac751a
--- /dev/null
+++ b/modules/auth/pam/pam_stub.go
@@ -0,0 +1,15 @@
+// +build !pam
+
+// Copyright 2014 The Gogs Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package pam
+
+import (
+ "errors"
+)
+
+func PAMAuth(serviceName, userName, passwd string) error {
+ return errors.New("PAM not supported")
+}
diff --git a/modules/auth/user_form.go b/modules/auth/user_form.go
index b616a460..fa5583ff 100644
--- a/modules/auth/user_form.go
+++ b/modules/auth/user_form.go
@@ -12,27 +12,36 @@ import (
)
type InstallForm struct {
- DbType string `binding:"Required"`
- DbHost string
- DbUser string
- DbPasswd string
- DbName string
- SSLMode string
- DbPath string
- RepoRootPath string `binding:"Required"`
- RunUser string `binding:"Required"`
- Domain string `binding:"Required"`
- HTTPPort string `binding:"Required"`
- AppUrl string `binding:"Required"`
- SMTPHost string
- SMTPEmail string
- SMTPPasswd string
- RegisterConfirm string
- MailNotify string
- AdminName string `binding:"Required;AlphaDashDot;MaxSize(30)"`
- AdminPasswd string `binding:"Required;MinSize(6);MaxSize(255)"`
- AdminConfirmPasswd string `binding:"Required;MinSize(6);MaxSize(255)"`
- AdminEmail string `binding:"Required;Email;MaxSize(50)"`
+ DbType string `binding:"Required"`
+ DbHost string
+ DbUser string
+ DbPasswd string
+ DbName string
+ SSLMode string
+ DbPath string
+
+ AppName string `binding:"Required" locale:"install.app_name"`
+ RepoRootPath string `binding:"Required"`
+ RunUser string `binding:"Required"`
+ Domain string `binding:"Required"`
+ HTTPPort string `binding:"Required"`
+ AppUrl string `binding:"Required"`
+
+ SMTPHost string
+ SMTPFrom string
+ SMTPEmail string `binding:"OmitEmpty;Email;MaxSize(50)" locale:"install.mailer_user"`
+ SMTPPasswd string
+ RegisterConfirm bool
+ MailNotify bool
+
+ OfflineMode bool
+ DisableRegistration bool
+ RequireSignInView bool
+
+ AdminName string `binding:"OmitEmpty;AlphaDashDot;MaxSize(30)" locale:"install.admin_name"`
+ AdminPasswd string `binding:"OmitEmpty;MinSize(6);MaxSize(255)" locale:"install.admin_password"`
+ AdminConfirmPasswd string
+ AdminEmail string `binding:"OmitEmpty;Email;MaxSize(50)" locale:"install.admin_email"`
}
func (f *InstallForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {