Add POST users/self/userpage

This commit is contained in:
Howl 2016-11-07 18:34:53 +01:00
parent 6c8d7baee2
commit 1c2201317f
2 changed files with 18 additions and 0 deletions

View File

@ -118,6 +118,7 @@ func Start(conf common.Conf, dbO *sqlx.DB) *gin.Engine {
gv1.GET("/friends/add", Method(v1.FriendsAddGET, common.PrivilegeWrite))
gv1.GET("/friends/del", Method(v1.FriendsDelGET, common.PrivilegeWrite))
gv1.POST("/users/self/settings", Method(v1.UsersSelfSettingsPOST, common.PrivilegeWrite))
gv1.POST("/users/self/userpage", Method(v1.UserSelfUserpagePOST, common.PrivilegeWrite))
//gv1.POST("/beatmaps/rank_requests", Method(v1.BeatmapRankRequestsSubmitPOST, common.PrivilegeWrite))
// Admin: beatmap

View File

@ -333,6 +333,23 @@ func UserUserpageGET(md common.MethodData) common.CodeMessager {
return r
}
// UserSelfUserpagePOST allows to change the current user's userpage.
func UserSelfUserpagePOST(md common.MethodData) common.CodeMessager {
var d struct {
Data *string `json:"data"`
}
md.RequestData.Unmarshal(&d)
if d.Data == nil {
return ErrMissingField("data")
}
_, err := md.DB.Exec("UPDATE users_stats SET userpage_content = ? WHERE id = ? LIMIT 1", *d.Data, md.ID())
if err != nil {
md.Err(err)
}
md.C.Request.URL.RawQuery += "&id=" + strconv.Itoa(md.ID())
return UserUserpageGET(md)
}
func whereClauseUser(md common.MethodData, tableName string) (*common.CodeMessager, string, interface{}) {
switch {
case md.Query("id") == "self":