aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gogs.go2
-rw-r--r--models/issue.go7
-rw-r--r--models/user.go19
-rw-r--r--routers/api/v1/users.go40
-rw-r--r--templates/base/footer.tmpl6
-rw-r--r--web.go4
6 files changed, 68 insertions, 10 deletions
diff --git a/gogs.go b/gogs.go
index 3901b1e543..7f7267ecd6 100644
--- a/gogs.go
+++ b/gogs.go
@@ -35,7 +35,7 @@ func main() {
CmdWeb,
CmdServ,
CmdUpdate,
- CmdFix,
+ // CmdFix,
}
app.Flags = append(app.Flags, []cli.Flag{}...)
app.Run(os.Args)
diff --git a/models/issue.go b/models/issue.go
index 26b8cecdd5..6a32312eed 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -70,12 +70,7 @@ func CreateIssue(userId, repoId, milestoneId, assigneeId int64, issueCount int,
return nil, err
}
- if err = sess.Commit(); err != nil {
- //sess.Rollback()
- return nil, err
- }
-
- return issue, nil
+ return issue, sess.Commit()
}
// GetIssueById returns issue object by given id.
diff --git a/models/user.go b/models/user.go
index 661eff2fdd..6751d11d49 100644
--- a/models/user.go
+++ b/models/user.go
@@ -409,6 +409,25 @@ func GetUserByEmail(email string) (*User, error) {
return user, nil
}
+// SearchUserByName returns given number of users whose name contains keyword.
+func SearchUserByName(key string, limit int) (us []*User, err error) {
+ // Prevent SQL inject.
+ key = strings.TrimSpace(key)
+ if len(key) == 0 {
+ return us, nil
+ }
+
+ key = strings.Split(key, " ")[0]
+ if len(key) == 0 {
+ return us, nil
+ }
+ key = strings.ToLower(key)
+
+ us = make([]*User, 0, limit)
+ err = orm.Limit(limit).Where("lower_name like '%" + key + "%'").Find(&us)
+ return us, err
+}
+
// LoginUserPlain validates user by raw user name and password.
func LoginUserPlain(uname, passwd string) (*User, error) {
var u *User
diff --git a/routers/api/v1/users.go b/routers/api/v1/users.go
new file mode 100644
index 0000000000..a5ad8fbca0
--- /dev/null
+++ b/routers/api/v1/users.go
@@ -0,0 +1,40 @@
+// 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 v1
+
+import (
+ "github.com/gogits/gogs/models"
+ "github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/middleware"
+)
+
+type user struct {
+ UserName string `json:"username"`
+ AvatarLink string `json:"avatar"`
+}
+
+func SearchUser(ctx *middleware.Context) {
+ q := ctx.Query("q")
+ limit, err := base.StrTo(ctx.Query("limit")).Int()
+ if err != nil {
+ limit = 10
+ }
+
+ us, err := models.SearchUserByName(q, limit)
+ if err != nil {
+ ctx.JSON(500, nil)
+ return
+ }
+
+ results := make([]*user, len(us))
+ for i := range us {
+ results[i] = &user{us[i].Name, us[i].AvatarLink()}
+ }
+
+ ctx.Render.JSON(200, map[string]interface{}{
+ "ok": true,
+ "data": results,
+ })
+}
diff --git a/templates/base/footer.tmpl b/templates/base/footer.tmpl
index 30f068913c..23a1173f99 100644
--- a/templates/base/footer.tmpl
+++ b/templates/base/footer.tmpl
@@ -10,12 +10,12 @@
</p>
</div>
- <div class="col-md-1" style="margin: -5px;">
+ <div class="col-md-2" style="margin: -5px;">
<a target="_blank" href="https://github.com/gogits/gogs"><i class="fa fa-github fa-2x"></i></a>
</div>
- <div class="col-md-5">
- <p class="desc"></p>
+ <div class="col-md-4">
+ <p class="desc"><a href="http://gogits.org">Official Website</a></p>
</div>
</div>
</div>
diff --git a/web.go b/web.go
index 23fa10796c..962764af5d 100644
--- a/web.go
+++ b/web.go
@@ -75,7 +75,11 @@ func runWeb(*cli.Context) {
m.Get("/help", routers.Help)
m.Group("/api/v1", func(r martini.Router) {
+ // Miscellaneous.
r.Post("/markdown", v1.Markdown)
+
+ // Users.
+ r.Get("/users/search", v1.SearchUser)
})
avt := avatar.CacheServer("public/img/avatar/", "public/img/avatar_default.jpg")