You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.6 KiB

// 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 user
import (
"github.com/Unknwon/com"
api "github.com/gogs/go-gogs-client"
"github.com/gogs/gogs/models"
"github.com/gogs/gogs/models/errors"
"github.com/gogs/gogs/pkg/context"
"github.com/gogs/gogs/pkg/markup"
)
func Search(c *context.APIContext) {
opts := &models.SearchUserOptions{
Keyword: c.Query("q"),
Type: models.USER_TYPE_INDIVIDUAL,
PageSize: com.StrTo(c.Query("limit")).MustInt(),
}
if opts.PageSize == 0 {
opts.PageSize = 10
}
users, _, err := models.SearchUserByName(opts)
if err != nil {
c.JSON(500, map[string]interface{}{
"ok": false,
"error": err.Error(),
})
return
}
results := make([]*api.User, len(users))
for i := range users {
results[i] = &api.User{
ID: users[i].ID,
UserName: users[i].Name,
AvatarUrl: users[i].AvatarLink(),
FullName: markup.Sanitize(users[i].FullName),
}
if c.IsLogged {
results[i].Email = users[i].Email
}
}
c.JSON(200, map[string]interface{}{
"ok": true,
"data": results,
})
}
10 years ago
func GetInfo(c *context.APIContext) {
u, err := models.GetUserByName(c.Params(":username"))
10 years ago
if err != nil {
if errors.IsUserNotExist(err) {
c.Status(404)
10 years ago
} else {
c.Error(500, "GetUserByName", err)
10 years ago
}
return
}
// Hide user e-mail when API caller isn't signed in.
if !c.IsLogged {
u.Email = ""
}
c.JSON(200, u.APIFormat())
9 years ago
}
func GetAuthenticatedUser(c *context.APIContext) {
c.JSON(200, c.User.APIFormat())
10 years ago
}