2021-06-24 03:58:44 +08:00
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
2022-11-28 02:20:29 +08:00
|
|
|
// SPDX-License-Identifier: MIT
|
2021-06-24 03:58:44 +08:00
|
|
|
|
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2021-11-24 17:49:20 +08:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2021-06-24 03:58:44 +08:00
|
|
|
"code.gitea.io/gitea/modules/context"
|
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
|
|
|
"code.gitea.io/gitea/modules/web"
|
2022-12-29 10:57:15 +08:00
|
|
|
"code.gitea.io/gitea/services/convert"
|
2021-06-24 03:58:44 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// GetUserSettings returns user settings
|
|
|
|
func GetUserSettings(ctx *context.APIContext) {
|
|
|
|
// swagger:operation GET /user/settings user getUserSettings
|
|
|
|
// ---
|
|
|
|
// summary: Get user settings
|
|
|
|
// produces:
|
|
|
|
// - application/json
|
|
|
|
// responses:
|
|
|
|
// "200":
|
|
|
|
// "$ref": "#/responses/UserSettings"
|
2022-03-22 15:03:22 +08:00
|
|
|
ctx.JSON(http.StatusOK, convert.User2UserSettings(ctx.Doer))
|
2021-06-24 03:58:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateUserSettings returns user settings
|
|
|
|
func UpdateUserSettings(ctx *context.APIContext) {
|
|
|
|
// swagger:operation PATCH /user/settings user updateUserSettings
|
|
|
|
// ---
|
|
|
|
// summary: Update user settings
|
|
|
|
// parameters:
|
|
|
|
// - name: body
|
|
|
|
// in: body
|
|
|
|
// schema:
|
|
|
|
// "$ref": "#/definitions/UserSettingsOptions"
|
|
|
|
// produces:
|
|
|
|
// - application/json
|
|
|
|
// responses:
|
|
|
|
// "200":
|
|
|
|
// "$ref": "#/responses/UserSettings"
|
|
|
|
|
|
|
|
form := web.GetForm(ctx).(*api.UserSettingsOptions)
|
|
|
|
|
|
|
|
if form.FullName != nil {
|
2022-03-22 15:03:22 +08:00
|
|
|
ctx.Doer.FullName = *form.FullName
|
2021-06-24 03:58:44 +08:00
|
|
|
}
|
|
|
|
if form.Description != nil {
|
2022-03-22 15:03:22 +08:00
|
|
|
ctx.Doer.Description = *form.Description
|
2021-06-24 03:58:44 +08:00
|
|
|
}
|
|
|
|
if form.Website != nil {
|
2022-03-22 15:03:22 +08:00
|
|
|
ctx.Doer.Website = *form.Website
|
2021-06-24 03:58:44 +08:00
|
|
|
}
|
|
|
|
if form.Location != nil {
|
2022-03-22 15:03:22 +08:00
|
|
|
ctx.Doer.Location = *form.Location
|
2021-06-24 03:58:44 +08:00
|
|
|
}
|
|
|
|
if form.Language != nil {
|
2022-03-22 15:03:22 +08:00
|
|
|
ctx.Doer.Language = *form.Language
|
2021-06-24 03:58:44 +08:00
|
|
|
}
|
|
|
|
if form.Theme != nil {
|
2022-03-22 15:03:22 +08:00
|
|
|
ctx.Doer.Theme = *form.Theme
|
2021-06-24 03:58:44 +08:00
|
|
|
}
|
|
|
|
if form.DiffViewStyle != nil {
|
2022-03-22 15:03:22 +08:00
|
|
|
ctx.Doer.DiffViewStyle = *form.DiffViewStyle
|
2021-06-24 03:58:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if form.HideEmail != nil {
|
2022-03-22 15:03:22 +08:00
|
|
|
ctx.Doer.KeepEmailPrivate = *form.HideEmail
|
2021-06-24 03:58:44 +08:00
|
|
|
}
|
|
|
|
if form.HideActivity != nil {
|
2022-03-22 15:03:22 +08:00
|
|
|
ctx.Doer.KeepActivityPrivate = *form.HideActivity
|
2021-06-24 03:58:44 +08:00
|
|
|
}
|
|
|
|
|
2022-05-20 22:08:52 +08:00
|
|
|
if err := user_model.UpdateUser(ctx, ctx.Doer, false); err != nil {
|
2021-06-24 03:58:44 +08:00
|
|
|
ctx.InternalServerError(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:03:22 +08:00
|
|
|
ctx.JSON(http.StatusOK, convert.User2UserSettings(ctx.Doer))
|
2021-06-24 03:58:44 +08:00
|
|
|
}
|