Some checks failed
Build docker and publish / build (20.15.1) (push) Failing after 6m27s
feat: 添加版本和构建时间变量 fix: 修正短信队列类型注释错误 style: 清理未使用的代码和测试文件 docs: 更新安装文档中的下载链接 chore: 迁移数据库脚本添加日志和订阅配置
51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
package user
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/perfect-panel/server/pkg/constant"
|
|
|
|
"github.com/perfect-panel/server/internal/model/user"
|
|
"github.com/perfect-panel/server/internal/svc"
|
|
"github.com/perfect-panel/server/internal/types"
|
|
"github.com/perfect-panel/server/pkg/logger"
|
|
"github.com/perfect-panel/server/pkg/xerr"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
type UnbindOAuthLogic struct {
|
|
logger.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// Unbind OAuth
|
|
func NewUnbindOAuthLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UnbindOAuthLogic {
|
|
return &UnbindOAuthLogic{
|
|
Logger: logger.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *UnbindOAuthLogic) UnbindOAuth(req *types.UnbindOAuthRequest) error {
|
|
u, ok := l.ctx.Value(constant.CtxKeyUser).(*user.User)
|
|
if !ok {
|
|
logger.Error("current user is not found in context")
|
|
return errors.Wrapf(xerr.NewErrCode(xerr.InvalidAccess), "Invalid Access")
|
|
}
|
|
if !l.validator(req) {
|
|
return errors.Wrapf(xerr.NewErrCode(xerr.InvalidParams), "invalid parameter")
|
|
}
|
|
err := l.svcCtx.UserModel.DeleteUserAuthMethods(l.ctx, u.Id, req.Method)
|
|
if err != nil {
|
|
l.Errorw("delete user auth methods failed:", logger.Field("error", err.Error()))
|
|
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseDeletedError), "delete user auth methods failed: %v", err.Error())
|
|
}
|
|
|
|
return nil
|
|
}
|
|
func (l *UnbindOAuthLogic) validator(req *types.UnbindOAuthRequest) bool {
|
|
return req.Method != "" && req.Method != "email" && req.Method != "mobile"
|
|
}
|