aboutsummaryrefslogtreecommitdiff
path: root/routes
diff options
context:
space:
mode:
Diffstat (limited to 'routes')
-rw-r--r--routes/admin/auths.go62
-rw-r--r--routes/api/v1/admin/user.go3
-rw-r--r--routes/install.go1
-rw-r--r--routes/org/setting.go12
-rw-r--r--routes/repo/http.go4
-rw-r--r--routes/user/auth.go40
-rw-r--r--routes/user/setting.go4
7 files changed, 74 insertions, 52 deletions
diff --git a/routes/admin/auths.go b/routes/admin/auths.go
index 56a0aad6..6356d112 100644
--- a/routes/admin/auths.go
+++ b/routes/admin/auths.go
@@ -25,19 +25,19 @@ const (
)
func Authentications(c *context.Context) {
- c.Data["Title"] = c.Tr("admin.authentication")
- c.Data["PageIsAdmin"] = true
- c.Data["PageIsAdminAuthentications"] = true
+ c.Title("admin.authentication")
+ c.PageIs("Admin")
+ c.PageIs("AdminAuthentications")
var err error
c.Data["Sources"], err = models.LoginSources()
if err != nil {
- c.Handle(500, "LoginSources", err)
+ c.ServerError("LoginSources", err)
return
}
c.Data["Total"] = models.CountLoginSources()
- c.HTML(200, AUTHS)
+ c.Success(AUTHS)
}
type dropdownItem struct {
@@ -60,9 +60,9 @@ var (
)
func NewAuthSource(c *context.Context) {
- c.Data["Title"] = c.Tr("admin.auths.new")
- c.Data["PageIsAdmin"] = true
- c.Data["PageIsAdminAuthentications"] = true
+ c.Title("admin.auths.new")
+ c.PageIs("Admin")
+ c.PageIs("AdminAuthentications")
c.Data["type"] = models.LOGIN_LDAP
c.Data["CurrentTypeName"] = models.LoginNames[models.LOGIN_LDAP]
@@ -72,13 +72,12 @@ func NewAuthSource(c *context.Context) {
c.Data["AuthSources"] = authSources
c.Data["SecurityProtocols"] = securityProtocols
c.Data["SMTPAuths"] = models.SMTPAuths
- c.HTML(200, AUTH_NEW)
+ c.Success(AUTH_NEW)
}
func parseLDAPConfig(f form.Authentication) *models.LDAPConfig {
return &models.LDAPConfig{
Source: &ldap.Source{
- Name: f.Name,
Host: f.Host,
Port: f.Port,
SecurityProtocol: ldap.SecurityProtocol(f.SecurityProtocol),
@@ -99,7 +98,6 @@ func parseLDAPConfig(f form.Authentication) *models.LDAPConfig {
GroupMemberUID: f.GroupMemberUID,
UserUID: f.UserUID,
AdminFilter: f.AdminFilter,
- Enabled: true,
},
}
}
@@ -116,9 +114,9 @@ func parseSMTPConfig(f form.Authentication) *models.SMTPConfig {
}
func NewAuthSourcePost(c *context.Context, f form.Authentication) {
- c.Data["Title"] = c.Tr("admin.auths.new")
- c.Data["PageIsAdmin"] = true
- c.Data["PageIsAdminAuthentications"] = true
+ c.Title("admin.auths.new")
+ c.PageIs("Admin")
+ c.PageIs("AdminAuthentications")
c.Data["CurrentTypeName"] = models.LoginNames[models.LoginType(f.Type)]
c.Data["CurrentSecurityProtocol"] = models.SecurityProtocolNames[ldap.SecurityProtocol(f.SecurityProtocol)]
@@ -146,7 +144,7 @@ func NewAuthSourcePost(c *context.Context, f form.Authentication) {
c.Data["HasTLS"] = hasTLS
if c.HasError() {
- c.HTML(200, AUTH_NEW)
+ c.Success(AUTH_NEW)
return
}
@@ -160,7 +158,7 @@ func NewAuthSourcePost(c *context.Context, f form.Authentication) {
c.Data["Err_Name"] = true
c.RenderWithErr(c.Tr("admin.auths.login_source_exist", err.(models.ErrLoginSourceAlreadyExist).Name), AUTH_NEW, f)
} else {
- c.Handle(500, "CreateSource", err)
+ c.ServerError("CreateSource", err)
}
return
}
@@ -172,41 +170,41 @@ func NewAuthSourcePost(c *context.Context, f form.Authentication) {
}
func EditAuthSource(c *context.Context) {
- c.Data["Title"] = c.Tr("admin.auths.edit")
- c.Data["PageIsAdmin"] = true
- c.Data["PageIsAdminAuthentications"] = true
+ c.Title("admin.auths.edit")
+ c.PageIs("Admin")
+ c.PageIs("AdminAuthentications")
c.Data["SecurityProtocols"] = securityProtocols
c.Data["SMTPAuths"] = models.SMTPAuths
source, err := models.GetLoginSourceByID(c.ParamsInt64(":authid"))
if err != nil {
- c.Handle(500, "GetLoginSourceByID", err)
+ c.ServerError("GetLoginSourceByID", err)
return
}
c.Data["Source"] = source
c.Data["HasTLS"] = source.HasTLS()
- c.HTML(200, AUTH_EDIT)
+ c.Success(AUTH_EDIT)
}
func EditAuthSourcePost(c *context.Context, f form.Authentication) {
- c.Data["Title"] = c.Tr("admin.auths.edit")
- c.Data["PageIsAdmin"] = true
- c.Data["PageIsAdminAuthentications"] = true
+ c.Title("admin.auths.edit")
+ c.PageIs("Admin")
+ c.PageIs("AdminAuthentications")
c.Data["SMTPAuths"] = models.SMTPAuths
source, err := models.GetLoginSourceByID(c.ParamsInt64(":authid"))
if err != nil {
- c.Handle(500, "GetLoginSourceByID", err)
+ c.ServerError("GetLoginSourceByID", err)
return
}
c.Data["Source"] = source
c.Data["HasTLS"] = source.HasTLS()
if c.HasError() {
- c.HTML(200, AUTH_EDIT)
+ c.Success(AUTH_EDIT)
return
}
@@ -228,11 +226,11 @@ func EditAuthSourcePost(c *context.Context, f form.Authentication) {
source.Name = f.Name
source.IsActived = f.IsActive
source.Cfg = config
- if err := models.UpdateSource(source); err != nil {
- c.Handle(500, "UpdateSource", err)
+ if err := models.UpdateLoginSource(source); err != nil {
+ c.ServerError("UpdateLoginSource", err)
return
}
- log.Trace("Authentication changed by admin(%s): %d", c.User.Name, source.ID)
+ log.Trace("Authentication changed by admin '%s': %d", c.User.Name, source.ID)
c.Flash.Success(c.Tr("admin.auths.update_success"))
c.Redirect(setting.AppSubURL + "/admin/auths/" + com.ToStr(f.ID))
@@ -241,7 +239,7 @@ func EditAuthSourcePost(c *context.Context, f form.Authentication) {
func DeleteAuthSource(c *context.Context) {
source, err := models.GetLoginSourceByID(c.ParamsInt64(":authid"))
if err != nil {
- c.Handle(500, "GetLoginSourceByID", err)
+ c.ServerError("GetLoginSourceByID", err)
return
}
@@ -251,7 +249,7 @@ func DeleteAuthSource(c *context.Context) {
} else {
c.Flash.Error(fmt.Sprintf("DeleteSource: %v", err))
}
- c.JSON(200, map[string]interface{}{
+ c.JSONSuccess(map[string]interface{}{
"redirect": setting.AppSubURL + "/admin/auths/" + c.Params(":authid"),
})
return
@@ -259,7 +257,7 @@ func DeleteAuthSource(c *context.Context) {
log.Trace("Authentication deleted by admin(%s): %d", c.User.Name, source.ID)
c.Flash.Success(c.Tr("admin.auths.deletion_success"))
- c.JSON(200, map[string]interface{}{
+ c.JSONSuccess(map[string]interface{}{
"redirect": setting.AppSubURL + "/admin/auths",
})
}
diff --git a/routes/api/v1/admin/user.go b/routes/api/v1/admin/user.go
index 623911fd..d48ecc2f 100644
--- a/routes/api/v1/admin/user.go
+++ b/routes/api/v1/admin/user.go
@@ -10,6 +10,7 @@ import (
api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/models"
+ "github.com/gogits/gogs/models/errors"
"github.com/gogits/gogs/pkg/context"
"github.com/gogits/gogs/pkg/mailer"
"github.com/gogits/gogs/pkg/setting"
@@ -23,7 +24,7 @@ func parseLoginSource(c *context.APIContext, u *models.User, sourceID int64, log
source, err := models.GetLoginSourceByID(sourceID)
if err != nil {
- if models.IsErrLoginSourceNotExist(err) {
+ if errors.IsLoginSourceNotExist(err) {
c.Error(422, "", err)
} else {
c.Error(500, "GetLoginSourceByID", err)
diff --git a/routes/install.go b/routes/install.go
index 29177936..4e8890f7 100644
--- a/routes/install.go
+++ b/routes/install.go
@@ -67,6 +67,7 @@ func GlobalInit() {
}
models.HasEngine = true
+ models.LoadAuthSources()
models.LoadRepoConfig()
models.NewRepoContext()
diff --git a/routes/org/setting.go b/routes/org/setting.go
index 397ffa8f..c5083d1a 100644
--- a/routes/org/setting.go
+++ b/routes/org/setting.go
@@ -107,16 +107,16 @@ func SettingsDeleteAvatar(c *context.Context) {
}
func SettingsDelete(c *context.Context) {
- c.Data["Title"] = c.Tr("org.settings")
- c.Data["PageIsSettingsDelete"] = true
+ c.Title("org.settings")
+ c.PageIs("SettingsDelete")
org := c.Org.Organization
if c.Req.Method == "POST" {
- if _, err := models.UserSignIn(c.User.Name, c.Query("password")); err != nil {
+ if _, err := models.UserLogin(c.User.Name, c.Query("password"), c.User.LoginSource); err != nil {
if errors.IsUserNotExist(err) {
c.RenderWithErr(c.Tr("form.enterred_invalid_password"), SETTINGS_DELETE, nil)
} else {
- c.Handle(500, "UserSignIn", err)
+ c.ServerError("UserLogin", err)
}
return
}
@@ -126,7 +126,7 @@ func SettingsDelete(c *context.Context) {
c.Flash.Error(c.Tr("form.org_still_own_repo"))
c.Redirect(c.Org.OrgLink + "/settings/delete")
} else {
- c.Handle(500, "DeleteOrganization", err)
+ c.ServerError("DeleteOrganization", err)
}
} else {
log.Trace("Organization deleted: %s", org.Name)
@@ -135,7 +135,7 @@ func SettingsDelete(c *context.Context) {
return
}
- c.HTML(200, SETTINGS_DELETE)
+ c.Success(SETTINGS_DELETE)
}
func Webhooks(c *context.Context) {
diff --git a/routes/repo/http.go b/routes/repo/http.go
index 2724ee1c..07101661 100644
--- a/routes/repo/http.go
+++ b/routes/repo/http.go
@@ -124,9 +124,9 @@ func HTTPContexter() macaron.Handler {
return
}
- authUser, err := models.UserSignIn(authUsername, authPassword)
+ authUser, err := models.UserLogin(authUsername, authPassword, -1)
if err != nil && !errors.IsUserNotExist(err) {
- c.Handle(http.StatusInternalServerError, "UserSignIn", err)
+ c.Handle(http.StatusInternalServerError, "UserLogin", err)
return
}
diff --git a/routes/user/auth.go b/routes/user/auth.go
index b145fb1f..bf689f9a 100644
--- a/routes/user/auth.go
+++ b/routes/user/auth.go
@@ -80,12 +80,12 @@ func isValidRedirect(url string) bool {
}
func Login(c *context.Context) {
- c.Data["Title"] = c.Tr("sign_in")
+ c.Title("sign_in")
- // Check auto-login.
+ // Check auto-login
isSucceed, err := AutoLogin(c)
if err != nil {
- c.Handle(500, "AutoLogin", err)
+ c.ServerError("AutoLogin", err)
return
}
@@ -106,7 +106,15 @@ func Login(c *context.Context) {
return
}
- c.HTML(200, LOGIN)
+ // Display normal login page
+ loginSources, err := models.ActivatedLoginSources()
+ if err != nil {
+ c.ServerError("ActivatedLoginSources", err)
+ return
+ }
+ c.Data["LoginSources"] = loginSources
+
+ c.Success(LOGIN)
}
func afterLogin(c *context.Context, u *models.User, remember bool) {
@@ -138,19 +146,33 @@ func afterLogin(c *context.Context, u *models.User, remember bool) {
}
func LoginPost(c *context.Context, f form.SignIn) {
- c.Data["Title"] = c.Tr("sign_in")
+ c.Title("sign_in")
+
+ loginSources, err := models.ActivatedLoginSources()
+ if err != nil {
+ c.ServerError("ActivatedLoginSources", err)
+ return
+ }
+ c.Data["LoginSources"] = loginSources
if c.HasError() {
c.Success(LOGIN)
return
}
- u, err := models.UserSignIn(f.UserName, f.Password)
+ u, err := models.UserLogin(f.UserName, f.Password, f.LoginSource)
if err != nil {
- if errors.IsUserNotExist(err) {
+ switch err.(type) {
+ case errors.UserNotExist:
+ c.FormErr("UserName")
+ c.FormErr("Password")
c.RenderWithErr(c.Tr("form.username_password_incorrect"), LOGIN, &f)
- } else {
- c.ServerError("UserSignIn", err)
+ case errors.LoginSourceMismatch:
+ c.FormErr("LoginSource")
+ c.RenderWithErr(c.Tr("form.auth_source_mismatch"), LOGIN, &f)
+
+ default:
+ c.ServerError("UserLogin", err)
}
return
}
diff --git a/routes/user/setting.go b/routes/user/setting.go
index 723b3da2..4b8b48bb 100644
--- a/routes/user/setting.go
+++ b/routes/user/setting.go
@@ -633,11 +633,11 @@ func SettingsDelete(c *context.Context) {
c.PageIs("SettingsDelete")
if c.Req.Method == "POST" {
- if _, err := models.UserSignIn(c.User.Name, c.Query("password")); err != nil {
+ if _, err := models.UserLogin(c.User.Name, c.Query("password"), c.User.LoginSource); err != nil {
if errors.IsUserNotExist(err) {
c.RenderWithErr(c.Tr("form.enterred_invalid_password"), SETTINGS_DELETE, nil)
} else {
- c.ServerError("UserSignIn", err)
+ c.ServerError("UserLogin", err)
}
return
}