diff options
author | Unknown <joe2010xtmf@163.com> | 2014-04-30 23:48:01 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-04-30 23:48:01 -0400 |
commit | 49dc57e3368c6b6557520b671c9f1c3b4fe26db8 (patch) | |
tree | 8ca5d226ed52fc4600e16efeb6a027523beb2bf6 /models | |
parent | de46c06d2ef10c580015cabed67ae8eb17667605 (diff) | |
download | gitea-49dc57e3368c6b6557520b671c9f1c3b4fe26db8.tar.gz gitea-49dc57e3368c6b6557520b671c9f1c3b4fe26db8.zip |
Add /api/v1/users/search
Diffstat (limited to 'models')
-rw-r--r-- | models/issue.go | 7 | ||||
-rw-r--r-- | models/user.go | 19 |
2 files changed, 20 insertions, 6 deletions
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 |