diff --git a/backend/app/repo/website_acme_account.go b/backend/app/repo/website_acme_account.go index 0ec2e0478..3bbb3ff23 100644 --- a/backend/app/repo/website_acme_account.go +++ b/backend/app/repo/website_acme_account.go @@ -1,13 +1,17 @@ package repo -import "github.com/1Panel-dev/1Panel/backend/app/model" +import ( + "github.com/1Panel-dev/1Panel/backend/app/model" + "gorm.io/gorm" +) type IAcmeAccountRepo interface { Page(page, size int, opts ...DBOption) (int64, []model.WebsiteAcmeAccount, error) - GetFirst(opts ...DBOption) (model.WebsiteAcmeAccount, error) + GetFirst(opts ...DBOption) (*model.WebsiteAcmeAccount, error) Create(account model.WebsiteAcmeAccount) error Save(account model.WebsiteAcmeAccount) error DeleteBy(opts ...DBOption) error + WithEmail(email string) DBOption } func NewIAcmeAccountRepo() IAcmeAccountRepo { @@ -17,6 +21,12 @@ func NewIAcmeAccountRepo() IAcmeAccountRepo { type WebsiteAcmeAccountRepo struct { } +func (w *WebsiteAcmeAccountRepo) WithEmail(email string) DBOption { + return func(db *gorm.DB) *gorm.DB { + return db.Where("email = ?", email) + } +} + func (w *WebsiteAcmeAccountRepo) Page(page, size int, opts ...DBOption) (int64, []model.WebsiteAcmeAccount, error) { var accounts []model.WebsiteAcmeAccount db := getDb(opts...).Model(&model.WebsiteAcmeAccount{}) @@ -26,13 +36,13 @@ func (w *WebsiteAcmeAccountRepo) Page(page, size int, opts ...DBOption) (int64, return count, accounts, err } -func (w *WebsiteAcmeAccountRepo) GetFirst(opts ...DBOption) (model.WebsiteAcmeAccount, error) { +func (w *WebsiteAcmeAccountRepo) GetFirst(opts ...DBOption) (*model.WebsiteAcmeAccount, error) { var account model.WebsiteAcmeAccount db := getDb(opts...).Model(&model.WebsiteAcmeAccount{}) if err := db.First(&account).Error; err != nil { - return account, err + return nil, err } - return account, nil + return &account, nil } func (w *WebsiteAcmeAccountRepo) Create(account model.WebsiteAcmeAccount) error { diff --git a/backend/app/service/website_acme_account.go b/backend/app/service/website_acme_account.go index 6a79f7e70..85278254d 100644 --- a/backend/app/service/website_acme_account.go +++ b/backend/app/service/website_acme_account.go @@ -25,6 +25,11 @@ func (w WebsiteAcmeAccountService) Page(search dto.PageInfo) (int64, []response. } func (w WebsiteAcmeAccountService) Create(create request.WebsiteAcmeAccountCreate) (response.WebsiteAcmeAccountDTO, error) { + exist, _ := websiteAcmeRepo.GetFirst(websiteAcmeRepo.WithEmail(create.Email)) + if exist != nil { + return response.WebsiteAcmeAccountDTO{}, buserr.New(constant.ErrEmailIsExist) + } + client, err := ssl.NewAcmeClient(create.Email, "") if err != nil { return response.WebsiteAcmeAccountDTO{}, err diff --git a/backend/constant/errs.go b/backend/constant/errs.go index 0a94ef0fb..cb1f4ac17 100644 --- a/backend/constant/errs.go +++ b/backend/constant/errs.go @@ -70,6 +70,7 @@ var ( ErrSSLCannotDelete = "ErrSSLCannotDelete" ErrAccountCannotDelete = "ErrAccountCannotDelete" ErrSSLApply = "ErrSSLApply" + ErrEmailIsExist = "ErrEmailIsExist" ) //file diff --git a/backend/i18n/lang/en.yaml b/backend/i18n/lang/en.yaml index cb0d1bf64..2e6e5f3d5 100644 --- a/backend/i18n/lang/en.yaml +++ b/backend/i18n/lang/en.yaml @@ -36,4 +36,5 @@ ErrAppDelete: 'Other Website use this App' #ssl ErrSSLCannotDelete: "The certificate is being used by the website and cannot be removed" ErrAccountCannotDelete: "The certificate associated with the account cannot be deleted" -ErrSSLApply: "The certificate continues to be signed successfully, but openresty reload fails, please check the configuration!" \ No newline at end of file +ErrSSLApply: "The certificate continues to be signed successfully, but openresty reload fails, please check the configuration!" +ErrEmailIsExist: 'Email is already exist' \ No newline at end of file diff --git a/backend/i18n/lang/zh.yaml b/backend/i18n/lang/zh.yaml index 5859a9d75..f62ab5362 100644 --- a/backend/i18n/lang/zh.yaml +++ b/backend/i18n/lang/zh.yaml @@ -36,4 +36,5 @@ ErrAppDelete: '其他网站使用此应用,不能删除' #ssl ErrSSLCannotDelete: "证书正在被网站使用,无法删除" ErrAccountCannotDelete: "账号关联证书,无法删除" -ErrSSLApply: "证书续签成功,openresty reload失败,请检查配置!" \ No newline at end of file +ErrSSLApply: "证书续签成功,openresty reload失败,请检查配置!" +ErrEmailIsExist: '邮箱已存在' \ No newline at end of file diff --git a/frontend/src/views/website/ssl/acme-account/create/index.vue b/frontend/src/views/website/ssl/acme-account/create/index.vue index 3bc1a6ef8..b4d92b02c 100644 --- a/frontend/src/views/website/ssl/acme-account/create/index.vue +++ b/frontend/src/views/website/ssl/acme-account/create/index.vue @@ -11,7 +11,7 @@ - +