MCPcopy Create free account
hub / github.com/MertJSX/folderhost / GetUser

Function GetUser

routes/get_user.go:10–59  ·  view source on GitHub ↗
(c *fiber.Ctx)

Source from the content-addressed store, hash-verified

8)
9
10func GetUser(c *fiber.Ctx) error {
11 if !c.Locals("account").(types.Account).Permissions.ReadUsers {
12 return c.Status(403).JSON(
13 fiber.Map{"err": "No permission!"},
14 )
15 }
16
17 var username string = c.Params("username")
18
19 if username == "" {
20 return c.Status(400).JSON(
21 fiber.Map{"err": "Username is missing!"},
22 )
23 }
24
25 if cacheUser, ok := cache.SessionCache.Get(username); ok {
26 cacheUser.Password = ""
27 return c.Status(200).JSON(
28 fiber.Map{"user": cacheUser},
29 )
30 }
31
32 isExist, err := users.CheckIfUsernameExists(username)
33
34 if err != nil {
35 return c.Status(500).JSON(
36 fiber.Map{"err": "Internal server error!"},
37 )
38 }
39
40 if !isExist {
41 return c.Status(400).JSON(
42 fiber.Map{"err": "Username does not exist!"},
43 )
44 }
45
46 user, err := users.GetUserByUsername(username)
47
48 if err != nil {
49 return c.Status(500).JSON(
50 fiber.Map{"err": "Unknown error!"},
51 )
52 }
53
54 user.Password = ""
55
56 return c.Status(200).JSON(
57 fiber.Map{"user": user},
58 )
59}

Callers

nothing calls this directly

Calls 3

CheckIfUsernameExistsFunction · 0.92
GetUserByUsernameFunction · 0.92
GetMethod · 0.80

Tested by

no test coverage detected