aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
Diffstat (limited to 'routers')
-rw-r--r--routers/admin/admin.go4
-rw-r--r--routers/admin/auths.go18
-rw-r--r--routers/api/v1/user.go6
-rw-r--r--routers/api/v1/user_app.go2
-rw-r--r--routers/install.go2
-rw-r--r--routers/repo/http.go9
-rw-r--r--routers/repo/issue.go2
-rw-r--r--routers/repo/repo.go5
-rw-r--r--routers/user/auth.go11
-rw-r--r--routers/user/setting.go78
10 files changed, 74 insertions, 63 deletions
diff --git a/routers/admin/admin.go b/routers/admin/admin.go
index 316f1d4257..46106aa427 100644
--- a/routers/admin/admin.go
+++ b/routers/admin/admin.go
@@ -14,8 +14,8 @@ import (
"github.com/Unknwon/macaron"
"github.com/gogits/gogs/models"
+ "github.com/gogits/gogs/models/cron"
"github.com/gogits/gogs/modules/base"
- "github.com/gogits/gogs/modules/cron"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/process"
"github.com/gogits/gogs/modules/setting"
@@ -229,6 +229,6 @@ func Monitor(ctx *middleware.Context) {
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminMonitor"] = true
ctx.Data["Processes"] = process.Processes
- ctx.Data["Entries"] = cron.ListEntries()
+ ctx.Data["Entries"] = cron.ListTasks()
ctx.HTML(200, MONITOR)
}
diff --git a/routers/admin/auths.go b/routers/admin/auths.go
index 2bec7da46c..bb73026b7d 100644
--- a/routers/admin/auths.go
+++ b/routers/admin/auths.go
@@ -63,18 +63,18 @@ func NewAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
case models.LDAP:
u = &models.LDAPConfig{
Ldapsource: ldap.Ldapsource{
+ Name: form.Name,
Host: form.Host,
Port: form.Port,
UseSSL: form.UseSSL,
- BaseDN: form.BaseDN,
- AttributeUsername: form.AttributeUsername,
+ BindDN: form.BindDN,
+ BindPassword: form.BindPassword,
+ UserBase: form.UserBase,
+ Filter: form.Filter,
AttributeName: form.AttributeName,
AttributeSurname: form.AttributeSurname,
AttributeMail: form.AttributeMail,
- Filter: form.Filter,
- MsAdSAFormat: form.MsAdSA,
Enabled: true,
- Name: form.Name,
},
}
case models.SMTP:
@@ -149,18 +149,18 @@ func EditAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
case models.LDAP:
config = &models.LDAPConfig{
Ldapsource: ldap.Ldapsource{
+ Name: form.Name,
Host: form.Host,
Port: form.Port,
UseSSL: form.UseSSL,
- BaseDN: form.BaseDN,
- AttributeUsername: form.AttributeUsername,
+ BindDN: form.BindDN,
+ BindPassword: form.BindPassword,
+ UserBase: form.UserBase,
AttributeName: form.AttributeName,
AttributeSurname: form.AttributeSurname,
AttributeMail: form.AttributeMail,
Filter: form.Filter,
- MsAdSAFormat: form.MsAdSA,
Enabled: true,
- Name: form.Name,
},
}
case models.SMTP:
diff --git a/routers/api/v1/user.go b/routers/api/v1/user.go
index feecda483d..60b6adcd12 100644
--- a/routers/api/v1/user.go
+++ b/routers/api/v1/user.go
@@ -18,7 +18,7 @@ import (
// ToApiUser converts user to API format.
func ToApiUser(u *models.User) *api.User {
return &api.User{
- Id: u.Id,
+ ID: u.Id,
UserName: u.Name,
AvatarUrl: string(setting.Protocol) + u.AvatarLink(),
}
@@ -45,10 +45,14 @@ func SearchUsers(ctx *middleware.Context) {
results := make([]*api.User, len(us))
for i := range us {
results[i] = &api.User{
+ ID: us[i].Id,
UserName: us[i].Name,
AvatarUrl: us[i].AvatarLink(),
FullName: us[i].FullName,
}
+ if ctx.IsSigned {
+ results[i].Email = us[i].Email
+ }
}
ctx.Render.JSON(200, map[string]interface{}{
diff --git a/routers/api/v1/user_app.go b/routers/api/v1/user_app.go
index 31da8a3eef..5e5156aca4 100644
--- a/routers/api/v1/user_app.go
+++ b/routers/api/v1/user_app.go
@@ -34,7 +34,7 @@ type CreateAccessTokenForm struct {
// POST /users/:username/tokens
func CreateAccessToken(ctx *middleware.Context, form CreateAccessTokenForm) {
t := &models.AccessToken{
- Uid: ctx.User.Id,
+ UID: ctx.User.Id,
Name: form.Name,
}
if err := models.NewAccessToken(t); err != nil {
diff --git a/routers/install.go b/routers/install.go
index 8fed105fc2..4e7dd3904e 100644
--- a/routers/install.go
+++ b/routers/install.go
@@ -18,9 +18,9 @@ import (
"gopkg.in/ini.v1"
"github.com/gogits/gogs/models"
+ "github.com/gogits/gogs/models/cron"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
- "github.com/gogits/gogs/modules/cron"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/mailer"
"github.com/gogits/gogs/modules/middleware"
diff --git a/routers/repo/http.go b/routers/repo/http.go
index 54ea91cada..9c1f227391 100644
--- a/routers/repo/http.go
+++ b/routers/repo/http.go
@@ -113,7 +113,7 @@ func Http(ctx *middleware.Context) {
}
// Assume username now is a token.
- token, err := models.GetAccessTokenBySha(authUsername)
+ token, err := models.GetAccessTokenBySHA(authUsername)
if err != nil {
if err == models.ErrAccessTokenNotExist {
ctx.HandleText(401, "invalid token")
@@ -122,7 +122,11 @@ func Http(ctx *middleware.Context) {
}
return
}
- authUser, err = models.GetUserByID(token.Uid)
+ token.Updated = time.Now()
+ if err = models.UpdateAccessToekn(token); err != nil {
+ ctx.Handle(500, "UpdateAccessToekn", err)
+ }
+ authUser, err = models.GetUserByID(token.UID)
if err != nil {
ctx.Handle(500, "GetUserById", err)
return
@@ -292,6 +296,7 @@ func serviceReceivePack(hr handler) {
func serviceRpc(rpc string, hr handler) {
w, r, dir := hr.w, hr.r, hr.Dir
+ defer r.Body.Close()
if !hasAccess(r, hr.Config, dir, rpc, true) {
renderNoAccess(w)
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index 4072483e89..2fa270f373 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -1013,7 +1013,7 @@ func ChangeMilestonStatus(ctx *middleware.Context) {
func DeleteMilestone(ctx *middleware.Context) {
if err := models.DeleteMilestoneByID(ctx.QueryInt64("id")); err != nil {
- ctx.Flash.Error("DeleteMilestone: " + err.Error())
+ ctx.Flash.Error("DeleteMilestoneByID: " + err.Error())
} else {
ctx.Flash.Success(ctx.Tr("repo.milestones.deletion_success"))
}
diff --git a/routers/repo/repo.go b/routers/repo/repo.go
index 533bd569ad..1d29557005 100644
--- a/routers/repo/repo.go
+++ b/routers/repo/repo.go
@@ -214,9 +214,10 @@ func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) {
}
}
- if strings.Contains(err.Error(), "Authentication failed") {
+ if strings.Contains(err.Error(), "Authentication failed") ||
+ strings.Contains(err.Error(), " not found") {
ctx.Data["Err_Auth"] = true
- ctx.RenderWithErr(ctx.Tr("form.auth_failed", err), MIGRATE, &form)
+ ctx.RenderWithErr(ctx.Tr("form.auth_failed", strings.Replace(err.Error(), ":"+form.AuthPassword+"@", ":<password>@", 1)), MIGRATE, &form)
return
}
diff --git a/routers/user/auth.go b/routers/user/auth.go
index 61e572f9bc..5c6bb26fba 100644
--- a/routers/user/auth.go
+++ b/routers/user/auth.go
@@ -220,7 +220,6 @@ func SignUpPost(ctx *middleware.Context, cpt *captcha.Captcha, form auth.Registe
Passwd: form.Password,
IsActive: !setting.Service.RegisterEmailConfirm || isOauth,
}
-
if err := models.CreateUser(u); err != nil {
switch {
case models.IsErrUserAlreadyExist(err):
@@ -242,6 +241,16 @@ func SignUpPost(ctx *middleware.Context, cpt *captcha.Captcha, form auth.Registe
}
log.Trace("Account created: %s", u.Name)
+ // Auto-set admin for the only user.
+ if models.CountUsers() == 1 {
+ u.IsAdmin = true
+ u.IsActive = true
+ if err := models.UpdateUser(u); err != nil {
+ ctx.Handle(500, "UpdateUser", err)
+ return
+ }
+ }
+
// Bind social account.
if isOauth {
if err := models.BindUserOauth2(u.Id, sid); err != nil {
diff --git a/routers/user/setting.go b/routers/user/setting.go
index de9af6556b..c8b9f130d4 100644
--- a/routers/user/setting.go
+++ b/routers/user/setting.go
@@ -33,14 +33,12 @@ const (
func Settings(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("settings")
- ctx.Data["PageIsUserSettings"] = true
ctx.Data["PageIsSettingsProfile"] = true
ctx.HTML(200, SETTINGS_PROFILE)
}
func SettingsPost(ctx *middleware.Context, form auth.UpdateProfileForm) {
ctx.Data["Title"] = ctx.Tr("settings")
- ctx.Data["PageIsUserSettings"] = true
ctx.Data["PageIsSettingsProfile"] = true
if ctx.HasError() {
@@ -132,7 +130,6 @@ func SettingsAvatar(ctx *middleware.Context, form auth.UploadAvatarForm) {
func SettingsEmails(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("settings")
- ctx.Data["PageIsUserSettings"] = true
ctx.Data["PageIsSettingsEmails"] = true
emails, err := models.GetEmailAddresses(ctx.User.Id)
@@ -147,7 +144,6 @@ func SettingsEmails(ctx *middleware.Context) {
func SettingsEmailPost(ctx *middleware.Context, form auth.AddEmailForm) {
ctx.Data["Title"] = ctx.Tr("settings")
- ctx.Data["PageIsUserSettings"] = true
ctx.Data["PageIsSettingsEmails"] = true
emails, err := models.GetEmailAddresses(ctx.User.Id)
@@ -232,14 +228,12 @@ func SettingsEmailPost(ctx *middleware.Context, form auth.AddEmailForm) {
func SettingsPassword(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("settings")
- ctx.Data["PageIsUserSettings"] = true
ctx.Data["PageIsSettingsPassword"] = true
ctx.HTML(200, SETTINGS_PASSWORD)
}
func SettingsPasswordPost(ctx *middleware.Context, form auth.ChangePasswordForm) {
ctx.Data["Title"] = ctx.Tr("settings")
- ctx.Data["PageIsUserSettings"] = true
ctx.Data["PageIsSettingsPassword"] = true
if ctx.HasError() {
@@ -273,7 +267,6 @@ func SettingsPasswordPost(ctx *middleware.Context, form auth.ChangePasswordForm)
func SettingsSSHKeys(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("settings")
- ctx.Data["PageIsUserSettings"] = true
ctx.Data["PageIsSettingsSSHKeys"] = true
var err error
@@ -288,7 +281,6 @@ func SettingsSSHKeys(ctx *middleware.Context) {
func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) {
ctx.Data["Title"] = ctx.Tr("settings")
- ctx.Data["PageIsUserSettings"] = true
ctx.Data["PageIsSettingsSSHKeys"] = true
var err error
@@ -355,7 +347,6 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) {
func SettingsSocial(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("settings")
- ctx.Data["PageIsUserSettings"] = true
ctx.Data["PageIsSettingsSocial"] = true
// Unbind social account.
@@ -381,21 +372,8 @@ func SettingsSocial(ctx *middleware.Context) {
func SettingsApplications(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("settings")
- ctx.Data["PageIsUserSettings"] = true
ctx.Data["PageIsSettingsApplications"] = true
- // Delete access token.
- remove, _ := com.StrTo(ctx.Query("remove")).Int64()
- if remove > 0 {
- if err := models.DeleteAccessTokenById(remove); err != nil {
- ctx.Handle(500, "DeleteAccessTokenById", err)
- return
- }
- ctx.Flash.Success(ctx.Tr("settings.delete_token_success"))
- ctx.Redirect(setting.AppSubUrl + "/user/settings/applications")
- return
- }
-
tokens, err := models.ListAccessTokens(ctx.User.Id)
if err != nil {
ctx.Handle(500, "ListAccessTokens", err)
@@ -406,42 +384,56 @@ func SettingsApplications(ctx *middleware.Context) {
ctx.HTML(200, SETTINGS_APPLICATIONS)
}
-// FIXME: split to two different functions and pages to handle access token and oauth2
func SettingsApplicationsPost(ctx *middleware.Context, form auth.NewAccessTokenForm) {
ctx.Data["Title"] = ctx.Tr("settings")
- ctx.Data["PageIsUserSettings"] = true
ctx.Data["PageIsSettingsApplications"] = true
- switch ctx.Query("type") {
- case "token":
- if ctx.HasError() {
- ctx.HTML(200, SETTINGS_APPLICATIONS)
- return
- }
-
- t := &models.AccessToken{
- Uid: ctx.User.Id,
- Name: form.Name,
- }
- if err := models.NewAccessToken(t); err != nil {
- ctx.Handle(500, "NewAccessToken", err)
- return
- }
+ if ctx.HasError() {
+ ctx.HTML(200, SETTINGS_APPLICATIONS)
+ return
+ }
- ctx.Flash.Success(ctx.Tr("settings.generate_token_succees"))
- ctx.Flash.Info(t.Sha1)
+ t := &models.AccessToken{
+ UID: ctx.User.Id,
+ Name: form.Name,
+ }
+ if err := models.NewAccessToken(t); err != nil {
+ ctx.Handle(500, "NewAccessToken", err)
+ return
}
+ ctx.Flash.Success(ctx.Tr("settings.generate_token_succees"))
+ ctx.Flash.Info(t.Sha1)
+
ctx.Redirect(setting.AppSubUrl + "/user/settings/applications")
}
+func SettingsDeleteApplication(ctx *middleware.Context) {
+ if err := models.DeleteAccessTokenByID(ctx.QueryInt64("id")); err != nil {
+ ctx.Flash.Error("DeleteAccessTokenByID: " + err.Error())
+ } else {
+ ctx.Flash.Success(ctx.Tr("settings.delete_token_success"))
+ }
+
+ ctx.JSON(200, map[string]interface{}{
+ "redirect": setting.AppSubUrl + "/user/settings/applications",
+ })
+}
+
func SettingsDelete(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("settings")
- ctx.Data["PageIsUserSettings"] = true
ctx.Data["PageIsSettingsDelete"] = true
if ctx.Req.Method == "POST" {
- // FIXME: validate password.
+ if _, err := models.UserSignIn(ctx.User.Name, ctx.Query("password")); err != nil {
+ if models.IsErrUserNotExist(err) {
+ ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), SETTINGS_DELETE, nil)
+ } else {
+ ctx.Handle(500, "UserSignIn", err)
+ }
+ return
+ }
+
if err := models.DeleteUser(ctx.User); err != nil {
switch {
case models.IsErrUserOwnRepos(err):