mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Add /api/v1/users/search
This commit is contained in:
@@ -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.
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user