// Copyright 2015 - Present, The Gogs Authors. All rights reserved. // Copyright 2018 - Present, Gitote. All rights reserved. // // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. package user import ( "gitote/gitote/models" "gitote/gitote/models/errors" "gitote/gitote/pkg/context" "gitote/gitote/pkg/markup" "gitlab.com/gitote/com" api "gitlab.com/gitote/go-gitote-client" ) // Search search users func Search(c *context.APIContext) { opts := &models.SearchUserOptions{ Keyword: c.Query("q"), Type: models.UserTypeIndividual, 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, }) } // GetInfo get user's information func GetInfo(c *context.APIContext) { u, err := models.GetUserByName(c.Params(":username")) if err != nil { if errors.IsUserNotExist(err) { c.Status(404) } else { c.Error(500, "GetUserByName", err) } return } // Hide user e-mail when API caller isn't signed in. if !c.IsLogged { u.Email = "" } c.JSON(200, u.APIFormat()) } // GetAuthenticatedUser get current user's information func GetAuthenticatedUser(c *context.APIContext) { c.JSON(200, c.User.APIFormat()) }