Move modules/forms to services/forms (#15305)
Forms are dependent on models and therefore should be in services. This PR also removes the old auth. aliasing Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
@@ -13,12 +13,12 @@ import (
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
auth "code.gitea.io/gitea/modules/forms"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/password"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/services/forms"
|
||||
"code.gitea.io/gitea/services/mailer"
|
||||
)
|
||||
|
||||
@@ -39,7 +39,7 @@ func Account(ctx *context.Context) {
|
||||
|
||||
// AccountPost response for change user's password
|
||||
func AccountPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*auth.ChangePasswordForm)
|
||||
form := web.GetForm(ctx).(*forms.ChangePasswordForm)
|
||||
ctx.Data["Title"] = ctx.Tr("settings")
|
||||
ctx.Data["PageIsSettingsAccount"] = true
|
||||
|
||||
@@ -84,7 +84,7 @@ func AccountPost(ctx *context.Context) {
|
||||
|
||||
// EmailPost response for change user's email
|
||||
func EmailPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*auth.AddEmailForm)
|
||||
form := web.GetForm(ctx).(*forms.AddEmailForm)
|
||||
ctx.Data["Title"] = ctx.Tr("settings")
|
||||
ctx.Data["PageIsSettingsAccount"] = true
|
||||
|
||||
@@ -257,7 +257,7 @@ func DeleteAccount(ctx *context.Context) {
|
||||
|
||||
// UpdateUIThemePost is used to update users' specific theme
|
||||
func UpdateUIThemePost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*auth.UpdateThemeForm)
|
||||
form := web.GetForm(ctx).(*forms.UpdateThemeForm)
|
||||
ctx.Data["Title"] = ctx.Tr("settings")
|
||||
ctx.Data["PageIsSettingsAccount"] = true
|
||||
|
||||
|
||||
@@ -9,10 +9,10 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
auth "code.gitea.io/gitea/modules/forms"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/services/forms"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@@ -86,7 +86,7 @@ func TestChangePassword(t *testing.T) {
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
|
||||
web.SetForm(ctx, &auth.ChangePasswordForm{
|
||||
web.SetForm(ctx, &forms.ChangePasswordForm{
|
||||
OldPassword: req.OldPassword,
|
||||
Password: req.NewPassword,
|
||||
Retype: req.Retype,
|
||||
|
||||
@@ -11,9 +11,9 @@ import (
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
auth "code.gitea.io/gitea/modules/forms"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/services/forms"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -32,7 +32,7 @@ func Applications(ctx *context.Context) {
|
||||
|
||||
// ApplicationsPost response for add user's access token
|
||||
func ApplicationsPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*auth.NewAccessTokenForm)
|
||||
form := web.GetForm(ctx).(*forms.NewAccessTokenForm)
|
||||
ctx.Data["Title"] = ctx.Tr("settings")
|
||||
ctx.Data["PageIsSettingsApplications"] = true
|
||||
|
||||
|
||||
@@ -11,9 +11,9 @@ import (
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
auth "code.gitea.io/gitea/modules/forms"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/services/forms"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -35,7 +35,7 @@ func Keys(ctx *context.Context) {
|
||||
|
||||
// KeysPost response for change user's SSH/GPG keys
|
||||
func KeysPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*auth.AddKeyForm)
|
||||
form := web.GetForm(ctx).(*forms.AddKeyForm)
|
||||
ctx.Data["Title"] = ctx.Tr("settings")
|
||||
ctx.Data["PageIsSettingsKeys"] = true
|
||||
ctx.Data["DisableSSH"] = setting.SSH.Disabled
|
||||
|
||||
@@ -11,10 +11,10 @@ import (
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
auth "code.gitea.io/gitea/modules/forms"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/services/forms"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -23,7 +23,7 @@ const (
|
||||
|
||||
// OAuthApplicationsPost response for adding a oauth2 application
|
||||
func OAuthApplicationsPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*auth.EditOAuth2ApplicationForm)
|
||||
form := web.GetForm(ctx).(*forms.EditOAuth2ApplicationForm)
|
||||
ctx.Data["Title"] = ctx.Tr("settings")
|
||||
ctx.Data["PageIsSettingsApplications"] = true
|
||||
|
||||
@@ -55,7 +55,7 @@ func OAuthApplicationsPost(ctx *context.Context) {
|
||||
|
||||
// OAuthApplicationsEdit response for editing oauth2 application
|
||||
func OAuthApplicationsEdit(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*auth.EditOAuth2ApplicationForm)
|
||||
form := web.GetForm(ctx).(*forms.EditOAuth2ApplicationForm)
|
||||
ctx.Data["Title"] = ctx.Tr("settings")
|
||||
ctx.Data["PageIsSettingsApplications"] = true
|
||||
|
||||
|
||||
@@ -17,12 +17,12 @@ import (
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
auth "code.gitea.io/gitea/modules/forms"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/modules/web/middleware"
|
||||
"code.gitea.io/gitea/services/forms"
|
||||
|
||||
"github.com/unknwon/i18n"
|
||||
)
|
||||
@@ -75,7 +75,7 @@ func HandleUsernameChange(ctx *context.Context, user *models.User, newName strin
|
||||
|
||||
// ProfilePost response for change user's profile
|
||||
func ProfilePost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*auth.UpdateProfileForm)
|
||||
form := web.GetForm(ctx).(*forms.UpdateProfileForm)
|
||||
ctx.Data["Title"] = ctx.Tr("settings")
|
||||
ctx.Data["PageIsSettingsProfile"] = true
|
||||
|
||||
@@ -127,8 +127,8 @@ func ProfilePost(ctx *context.Context) {
|
||||
|
||||
// UpdateAvatarSetting update user's avatar
|
||||
// FIXME: limit size.
|
||||
func UpdateAvatarSetting(ctx *context.Context, form *auth.AvatarForm, ctxUser *models.User) error {
|
||||
ctxUser.UseCustomAvatar = form.Source == auth.AvatarLocal
|
||||
func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser *models.User) error {
|
||||
ctxUser.UseCustomAvatar = form.Source == forms.AvatarLocal
|
||||
if len(form.Gravatar) > 0 {
|
||||
if form.Avatar != nil {
|
||||
ctxUser.Avatar = base.EncodeMD5(form.Gravatar)
|
||||
@@ -176,7 +176,7 @@ func UpdateAvatarSetting(ctx *context.Context, form *auth.AvatarForm, ctxUser *m
|
||||
|
||||
// AvatarPost response for change user's avatar request
|
||||
func AvatarPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*auth.AvatarForm)
|
||||
form := web.GetForm(ctx).(*forms.AvatarForm)
|
||||
if err := UpdateAvatarSetting(ctx, form, ctx.User); err != nil {
|
||||
ctx.Flash.Error(err.Error())
|
||||
} else {
|
||||
|
||||
@@ -10,15 +10,15 @@ import (
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/auth/openid"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
auth "code.gitea.io/gitea/modules/forms"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/services/forms"
|
||||
)
|
||||
|
||||
// OpenIDPost response for change user's openid
|
||||
func OpenIDPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*auth.AddOpenIDForm)
|
||||
form := web.GetForm(ctx).(*forms.AddOpenIDForm)
|
||||
ctx.Data["Title"] = ctx.Tr("settings")
|
||||
ctx.Data["PageIsSettingsSecurity"] = true
|
||||
|
||||
@@ -81,7 +81,7 @@ func settingsOpenIDVerify(ctx *context.Context) {
|
||||
|
||||
id, err := openid.Verify(fullURL)
|
||||
if err != nil {
|
||||
ctx.RenderWithErr(err.Error(), tplSettingsSecurity, &auth.AddOpenIDForm{
|
||||
ctx.RenderWithErr(err.Error(), tplSettingsSecurity, &forms.AddOpenIDForm{
|
||||
Openid: id,
|
||||
})
|
||||
return
|
||||
@@ -92,7 +92,7 @@ func settingsOpenIDVerify(ctx *context.Context) {
|
||||
oid := &models.UserOpenID{UID: ctx.User.ID, URI: id}
|
||||
if err = models.AddUserOpenID(oid); err != nil {
|
||||
if models.IsErrOpenIDAlreadyUsed(err) {
|
||||
ctx.RenderWithErr(ctx.Tr("form.openid_been_used", id), tplSettingsSecurity, &auth.AddOpenIDForm{Openid: id})
|
||||
ctx.RenderWithErr(ctx.Tr("form.openid_been_used", id), tplSettingsSecurity, &forms.AddOpenIDForm{Openid: id})
|
||||
return
|
||||
}
|
||||
ctx.ServerError("AddUserOpenID", err)
|
||||
|
||||
@@ -15,10 +15,10 @@ import (
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
auth "code.gitea.io/gitea/modules/forms"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/services/forms"
|
||||
|
||||
"github.com/pquerna/otp"
|
||||
"github.com/pquerna/otp/totp"
|
||||
@@ -168,7 +168,7 @@ func EnrollTwoFactor(ctx *context.Context) {
|
||||
|
||||
// EnrollTwoFactorPost handles enrolling the user into 2FA.
|
||||
func EnrollTwoFactorPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*auth.TwoFactorAuthForm)
|
||||
form := web.GetForm(ctx).(*forms.TwoFactorAuthForm)
|
||||
ctx.Data["Title"] = ctx.Tr("settings")
|
||||
ctx.Data["PageIsSettingsSecurity"] = true
|
||||
|
||||
|
||||
@@ -10,17 +10,17 @@ import (
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
auth "code.gitea.io/gitea/modules/forms"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/services/forms"
|
||||
|
||||
"github.com/tstranex/u2f"
|
||||
)
|
||||
|
||||
// U2FRegister initializes the u2f registration procedure
|
||||
func U2FRegister(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*auth.U2FRegistrationForm)
|
||||
form := web.GetForm(ctx).(*forms.U2FRegistrationForm)
|
||||
if form.Name == "" {
|
||||
ctx.Error(http.StatusConflict)
|
||||
return
|
||||
@@ -87,7 +87,7 @@ func U2FRegisterPost(ctx *context.Context) {
|
||||
|
||||
// U2FDelete deletes an security key by id
|
||||
func U2FDelete(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*auth.U2FDeleteForm)
|
||||
form := web.GetForm(ctx).(*forms.U2FDeleteForm)
|
||||
reg, err := models.GetU2FRegistrationByID(form.ID)
|
||||
if err != nil {
|
||||
if models.IsErrU2FRegistrationNotExist(err) {
|
||||
|
||||
Reference in New Issue
Block a user