The new Ripple frontend.
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.

profile.go 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package main
  2. import (
  3. "database/sql"
  4. "strconv"
  5. "github.com/gin-gonic/gin"
  6. "zxq.co/ripple/rippleapi/common"
  7. )
  8. // TODO: replace with simple ResponseInfo containing userid
  9. type profileData struct {
  10. baseTemplateData
  11. UserID int
  12. }
  13. func userProfile(c *gin.Context) {
  14. var (
  15. userID int
  16. username string
  17. privileges uint64
  18. )
  19. ctx := getContext(c)
  20. u := c.Param("user")
  21. if _, err := strconv.Atoi(u); err != nil {
  22. err := db.QueryRow("SELECT id, username, privileges FROM users WHERE username = ? AND "+ctx.OnlyUserPublic()+" LIMIT 1", u).Scan(&userID, &username, &privileges)
  23. if err != nil && err != sql.ErrNoRows {
  24. c.Error(err)
  25. }
  26. } else {
  27. err := db.QueryRow(`SELECT id, username, privileges FROM users WHERE id = ? AND `+ctx.OnlyUserPublic()+` LIMIT 1`, u).Scan(&userID, &username, &privileges)
  28. switch {
  29. case err == nil:
  30. case err == sql.ErrNoRows:
  31. err := db.QueryRow(`SELECT id, username, privileges FROM users WHERE username = ? AND `+ctx.OnlyUserPublic()+` LIMIT 1`, u).Scan(&userID, &username, &privileges)
  32. if err != nil && err != sql.ErrNoRows {
  33. c.Error(err)
  34. }
  35. default:
  36. c.Error(err)
  37. }
  38. }
  39. data := new(profileData)
  40. data.UserID = userID
  41. defer resp(c, 200, "profile.html", data)
  42. if data.UserID == 0 {
  43. data.TitleBar = "User not found"
  44. data.Messages = append(data.Messages, warningMessage{T(c, "That user could not be found.")})
  45. return
  46. }
  47. if common.UserPrivileges(privileges)&common.UserPrivilegeDonor > 0 {
  48. var profileBackground struct {
  49. Type int
  50. Value string
  51. }
  52. db.Get(&profileBackground, "SELECT type, value FROM profile_backgrounds WHERE uid = ?", data.UserID)
  53. switch profileBackground.Type {
  54. case 1:
  55. data.KyutGrill = "/static/profbackgrounds/" + profileBackground.Value
  56. data.KyutGrillAbsolute = true
  57. case 2:
  58. data.SolidColour = profileBackground.Value
  59. }
  60. }
  61. data.TitleBar = T(c, "%s's profile", username)
  62. data.DisableHH = true
  63. data.Scripts = append(data.Scripts, "/static/profile.js")
  64. }