Initial commit (code only without large binaries)
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package identity
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
)
|
||||
|
||||
type CancelAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CancelAction) RunPost(params struct {
|
||||
IdentityId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.UserIdentity_LogCancelUserIdentity)
|
||||
|
||||
_, err := this.RPC().UserIdentityRPC().CancelUserIdentity(this.UserContext(), &pb.CancelUserIdentityRequest{UserIdentityId: params.IdentityId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package identity
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type EnterpriseAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *EnterpriseAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *EnterpriseAction) RunGet(params struct{}) {
|
||||
resp, err := this.RPC().UserIdentityRPC().FindEnabledUserIdentityWithOrgType(this.UserContext(), &pb.FindEnabledUserIdentityWithOrgTypeRequest{
|
||||
OrgType: userconfigs.UserIdentityOrgTypeEnterprise,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var userIdentity = resp.UserIdentity
|
||||
if userIdentity == nil {
|
||||
this.Data["identity"] = nil
|
||||
this.Show()
|
||||
return
|
||||
}
|
||||
if len(userIdentity.FileIds) != 1 {
|
||||
this.Data["identity"] = nil
|
||||
this.Show()
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["identity"] = maps.Map{
|
||||
"id": userIdentity.Id,
|
||||
"realName": userIdentity.RealName,
|
||||
"number": userIdentity.Number,
|
||||
"status": userIdentity.Status,
|
||||
"frontFileId": userIdentity.FileIds[0],
|
||||
"rejectReason": userIdentity.RejectReason,
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package identity
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct{}) {
|
||||
// 个人认证
|
||||
{
|
||||
resp, err := this.RPC().UserIdentityRPC().FindEnabledUserIdentityWithOrgType(this.UserContext(), &pb.FindEnabledUserIdentityWithOrgTypeRequest{
|
||||
UserId: this.UserId(),
|
||||
OrgType: userconfigs.UserIdentityOrgTypeIndividual,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if resp.UserIdentity == nil {
|
||||
this.Data["individualIdentity"] = nil
|
||||
} else {
|
||||
this.Data["individualIdentity"] = maps.Map{
|
||||
"realName": resp.UserIdentity.RealName,
|
||||
"status": resp.UserIdentity.Status,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 企业认证
|
||||
{
|
||||
resp, err := this.RPC().UserIdentityRPC().FindEnabledUserIdentityWithOrgType(this.UserContext(), &pb.FindEnabledUserIdentityWithOrgTypeRequest{
|
||||
UserId: this.UserId(),
|
||||
OrgType: userconfigs.UserIdentityOrgTypeEnterprise,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if resp.UserIdentity == nil {
|
||||
this.Data["enterpriseIdentity"] = nil
|
||||
} else {
|
||||
this.Data["enterpriseIdentity"] = maps.Map{
|
||||
"realName": resp.UserIdentity.RealName,
|
||||
"status": resp.UserIdentity.Status,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package identity
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type IndividualAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndividualAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *IndividualAction) RunGet(params struct{}) {
|
||||
resp, err := this.RPC().UserIdentityRPC().FindEnabledUserIdentityWithOrgType(this.UserContext(), &pb.FindEnabledUserIdentityWithOrgTypeRequest{
|
||||
OrgType: userconfigs.UserIdentityOrgTypeIndividual,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var userIdentity = resp.UserIdentity
|
||||
if userIdentity == nil {
|
||||
this.Data["identity"] = nil
|
||||
this.Show()
|
||||
return
|
||||
}
|
||||
if len(userIdentity.FileIds) != 2 {
|
||||
this.Data["identity"] = nil
|
||||
this.Show()
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["identity"] = maps.Map{
|
||||
"id": userIdentity.Id,
|
||||
"realName": userIdentity.RealName,
|
||||
"number": userIdentity.Number,
|
||||
"status": userIdentity.Status,
|
||||
"frontFileId": userIdentity.FileIds[1],
|
||||
"backFileId": userIdentity.FileIds[0],
|
||||
"rejectReason": userIdentity.RejectReason,
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package identity
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/default/settings/settingutils"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||
server.
|
||||
Helper(helpers.NewUserMustAuth("")).
|
||||
Helper(settingutils.NewHelper("identity")).
|
||||
Prefix("/settings/identity").
|
||||
Get("", new(IndexAction)).
|
||||
Get("/individual", new(IndividualAction)).
|
||||
Get("/enterprise", new(EnterpriseAction)).
|
||||
Post("/uploadIndividual", new(UploadIndividualAction)).
|
||||
Post("/uploadEnterprise", new(UploadEnterpriseAction)).
|
||||
Post("/submit", new(SubmitAction)).
|
||||
Post("/cancel", new(CancelAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package identity
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
)
|
||||
|
||||
type SubmitAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *SubmitAction) RunPost(params struct {
|
||||
IdentityId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.UserIdentity_LogSubmitUserIdentity)
|
||||
|
||||
_, err := this.RPC().UserIdentityRPC().SubmitUserIdentity(this.UserContext(), &pb.SubmitUserIdentityRequest{UserIdentityId: params.IdentityId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package identity
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/utils/sizes"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type UploadEnterpriseAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UploadEnterpriseAction) RunPost(params struct {
|
||||
IdentityId int64
|
||||
|
||||
RealName string
|
||||
Number string
|
||||
FrontFile *actions.File
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.UserIdentity_LogUpdateUserIdentityEnterprise)
|
||||
|
||||
// 检查IdentityId
|
||||
var identityId = params.IdentityId
|
||||
var oldFileIds = []int64{0, 0}
|
||||
if identityId > 0 {
|
||||
identityResp, err := this.RPC().UserIdentityRPC().FindEnabledUserIdentity(this.UserContext(), &pb.FindEnabledUserIdentityRequest{
|
||||
UserIdentityId: identityId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if identityResp.UserIdentity == nil {
|
||||
this.Fail("错误的表单数据,请刷新后重试")
|
||||
}
|
||||
|
||||
var status = identityResp.UserIdentity.Status
|
||||
if status != userconfigs.UserIdentityStatusNone && status != userconfigs.UserIdentityStatusRejected {
|
||||
this.Fail("当前状态下无法修改")
|
||||
}
|
||||
|
||||
oldFileIds = identityResp.UserIdentity.FileIds
|
||||
}
|
||||
var mustUpload = identityId <= 0
|
||||
|
||||
params.Must.
|
||||
Field("realName", params.RealName).
|
||||
Require("请输入企业全称").
|
||||
Field("number", params.Number).
|
||||
Require("请输入营业执照号码")
|
||||
|
||||
var number = regexp.MustCompile(`\s+`).ReplaceAllString(params.Number, "")
|
||||
number = strings.ToUpper(number)
|
||||
|
||||
// front
|
||||
var frontFile = params.FrontFile
|
||||
if frontFile == nil {
|
||||
if mustUpload {
|
||||
this.Fail("请上传营业执照照片")
|
||||
}
|
||||
} else {
|
||||
var frontContentType = strings.ToLower(frontFile.ContentType)
|
||||
_, ok := allowedContentTypes[frontContentType]
|
||||
if !ok {
|
||||
this.Fail("请上传正确格式的图片")
|
||||
}
|
||||
|
||||
// TODO 需要可以配置最大上传尺寸,包括界面上的提示
|
||||
if frontFile.Size > 8*sizes.M {
|
||||
this.Fail("要上传的图片(营业执照照片)不能超过8MiB")
|
||||
}
|
||||
}
|
||||
|
||||
// 上传到服务器
|
||||
|
||||
var frontFileId int64 = 0
|
||||
|
||||
if frontFile != nil {
|
||||
fileId, ok, err := this.UploadFile(frontFile, "enterprise.license")
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if !ok {
|
||||
this.Fail("上传失败,请刷新后重试")
|
||||
}
|
||||
frontFileId = fileId
|
||||
}
|
||||
|
||||
if len(oldFileIds) == 1 {
|
||||
if frontFileId == 0 {
|
||||
frontFileId = oldFileIds[0]
|
||||
}
|
||||
}
|
||||
|
||||
var err error
|
||||
if identityId > 0 {
|
||||
_, err = this.RPC().UserIdentityRPC().UpdateUserIdentity(this.UserContext(), &pb.UpdateUserIdentityRequest{
|
||||
UserIdentityId: identityId,
|
||||
Type: userconfigs.UserIdentityTypeEnterpriseLicense,
|
||||
RealName: params.RealName,
|
||||
Number: number,
|
||||
FileIds: []int64{frontFileId},
|
||||
})
|
||||
} else {
|
||||
_, err = this.RPC().UserIdentityRPC().CreateUserIdentity(this.UserContext(), &pb.CreateUserIdentityRequest{
|
||||
OrgType: userconfigs.UserIdentityOrgTypeEnterprise,
|
||||
Type: userconfigs.UserIdentityTypeEnterpriseLicense,
|
||||
RealName: params.RealName,
|
||||
Number: number,
|
||||
FileIds: []int64{frontFileId},
|
||||
})
|
||||
}
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package identity
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/utils/sizes"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var allowedContentTypes = map[string]bool{
|
||||
"image/png": true,
|
||||
"image/jpeg": true,
|
||||
}
|
||||
|
||||
type UploadIndividualAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UploadIndividualAction) RunPost(params struct {
|
||||
IdentityId int64
|
||||
|
||||
RealName string
|
||||
Number string
|
||||
BackFile *actions.File
|
||||
FrontFile *actions.File
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.UserIdentity_LogUpdateUserIdentityIndividual)
|
||||
|
||||
// 检查IdentityId
|
||||
var identityId = params.IdentityId
|
||||
var oldFileIds = []int64{0, 0}
|
||||
if identityId > 0 {
|
||||
identityResp, err := this.RPC().UserIdentityRPC().FindEnabledUserIdentity(this.UserContext(), &pb.FindEnabledUserIdentityRequest{
|
||||
UserIdentityId: identityId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if identityResp.UserIdentity == nil {
|
||||
this.Fail("错误的表单数据,请刷新后重试")
|
||||
}
|
||||
|
||||
var status = identityResp.UserIdentity.Status
|
||||
if status != userconfigs.UserIdentityStatusNone && status != userconfigs.UserIdentityStatusRejected {
|
||||
this.Fail("当前状态下无法修改")
|
||||
}
|
||||
|
||||
oldFileIds = identityResp.UserIdentity.FileIds
|
||||
}
|
||||
var mustUpload = identityId <= 0
|
||||
|
||||
params.Must.
|
||||
Field("realName", params.RealName).
|
||||
Require("请输入真实姓名").
|
||||
Field("number", params.Number).
|
||||
Require("请输入身份证号")
|
||||
|
||||
var number = regexp.MustCompile(`\s+`).ReplaceAllString(params.Number, "")
|
||||
number = strings.ToUpper(number)
|
||||
if !regexp.MustCompile(`^\d+(X)?$`).MatchString(number) {
|
||||
this.FailField("number", "身份证号中只能含有数字和X字母")
|
||||
}
|
||||
var numberLen = len(number)
|
||||
if numberLen != 15 && numberLen != 18 {
|
||||
this.FailField("number", "身份证号只能是15或者18位")
|
||||
}
|
||||
|
||||
// back
|
||||
var backFile = params.BackFile
|
||||
if backFile == nil {
|
||||
if mustUpload {
|
||||
this.Fail("请上传身份证-照片面")
|
||||
}
|
||||
} else {
|
||||
var backContentType = strings.ToLower(backFile.ContentType)
|
||||
_, ok := allowedContentTypes[backContentType]
|
||||
if !ok {
|
||||
this.Fail("请上传正确格式的图片")
|
||||
}
|
||||
|
||||
// TODO 需要可以配置最大上传尺寸,包括界面上的提示
|
||||
if backFile.Size > 8*sizes.M {
|
||||
this.Fail("要上传的图片(身份证-照片面)不能超过8MiB")
|
||||
}
|
||||
}
|
||||
|
||||
// front
|
||||
var frontFile = params.FrontFile
|
||||
if frontFile == nil {
|
||||
if mustUpload {
|
||||
this.Fail("请上传身份证-国徽面")
|
||||
}
|
||||
} else {
|
||||
var frontContentType = strings.ToLower(frontFile.ContentType)
|
||||
_, ok := allowedContentTypes[frontContentType]
|
||||
if !ok {
|
||||
this.Fail("请上传正确格式的图片")
|
||||
}
|
||||
|
||||
// TODO 需要可以配置最大上传尺寸,包括界面上的提示
|
||||
if frontFile.Size > 8*sizes.M {
|
||||
this.Fail("要上传的图片(身份证-国徽面)不能超过8MiB")
|
||||
}
|
||||
}
|
||||
|
||||
// 上传到服务器
|
||||
var backFileId int64 = 0
|
||||
var frontFileId int64 = 0
|
||||
|
||||
if backFile != nil {
|
||||
fileId, ok, err := this.UploadFile(backFile, "user.idcard")
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if !ok {
|
||||
this.Fail("上传失败,请刷新后重试")
|
||||
}
|
||||
backFileId = fileId
|
||||
}
|
||||
|
||||
if frontFile != nil {
|
||||
fileId, ok, err := this.UploadFile(frontFile, "user.idcard")
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if !ok {
|
||||
this.Fail("上传失败,请刷新后重试")
|
||||
}
|
||||
frontFileId = fileId
|
||||
}
|
||||
|
||||
if len(oldFileIds) == 2 {
|
||||
if backFileId == 0 {
|
||||
backFileId = oldFileIds[0]
|
||||
}
|
||||
if frontFileId == 0 {
|
||||
frontFileId = oldFileIds[1]
|
||||
}
|
||||
}
|
||||
|
||||
var err error
|
||||
if identityId > 0 {
|
||||
_, err = this.RPC().UserIdentityRPC().UpdateUserIdentity(this.UserContext(), &pb.UpdateUserIdentityRequest{
|
||||
UserIdentityId: identityId,
|
||||
Type: userconfigs.UserIdentityTypeIDCard,
|
||||
RealName: params.RealName,
|
||||
Number: number,
|
||||
FileIds: []int64{backFileId, frontFileId},
|
||||
})
|
||||
} else {
|
||||
_, err = this.RPC().UserIdentityRPC().CreateUserIdentity(this.UserContext(), &pb.CreateUserIdentityRequest{
|
||||
OrgType: userconfigs.UserIdentityOrgTypeIndividual,
|
||||
Type: userconfigs.UserIdentityTypeIDCard,
|
||||
RealName: params.RealName,
|
||||
Number: number,
|
||||
FileIds: []int64{backFileId, frontFileId},
|
||||
})
|
||||
}
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user