code

package
v0.0.0-...-6a8978f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2022 License: MIT Imports: 18 Imported by: 0

README

验证码管理模块

  • 发送验证码, 生成一个验证码, 通知给用户
  • 校验验证码(一次性使用凭证), 判断下 用户的这个验证码 是不是有效的, 验证通过, 需要把验证码删除

Documentation

Index

Constants

View Source
const (
	//
	CODE_HEADER_KEY = "X-MCENTER-CODE"
	// url?code=???
	CODE_QUERY_KEY = "code"
)
View Source
const (
	AppName = "code"
)

Variables

View Source
var File_apps_code_pb_code_proto protoreflect.FileDescriptor
View Source
var File_apps_code_pb_rpc_proto protoreflect.FileDescriptor
View Source
var RPC_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "go8.devcloud.mcenter.code.RPC",
	HandlerType: (*RPCServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "VerifyCode",
			Handler:    _RPC_VerifyCode_Handler,
		},
	},
	Streams:  []grpc.StreamDesc{},
	Metadata: "apps/code/pb/rpc.proto",
}

RPC_ServiceDesc is the grpc.ServiceDesc for RPC service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

Functions

func GenRandomCode

func GenRandomCode(length uint) string

GenRandomCode todo 000001 100001 10000

func GetCodeFromHTTP

func GetCodeFromHTTP(r *http.Request) string

优先从认证头中获取, 如果头没有从Query String中获取

func HashID

func HashID(username, code string) string

HashID todo

func RegisterRPCServer

func RegisterRPCServer(s grpc.ServiceRegistrar, srv RPCServer)

Types

type Code

type Code struct {

	// 编号
	// @gotags: bson:"_id" json:"id"
	Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"`
	// 验证码
	// @gotags: bson:"code" json:"code"
	Code string `protobuf:"bytes,2,opt,name=code,proto3" json:"code" bson:"code"`
	// 用户名称
	// @gotags: json:"username" validate:"required"
	Username string `protobuf:"bytes,3,opt,name=username,proto3" json:"username" validate:"required"`
	// 颁发时间
	// @gotags: bson:"issue_at" json:"issue_at"
	IssueAt int64 `protobuf:"varint,4,opt,name=issue_at,json=issueAt,proto3" json:"issue_at" bson:"issue_at"`
	// 验证码过期时间
	// @gotags: bson:"expired_minite" json:"expired_minite"
	ExpiredMinite uint32 `protobuf:"varint,5,opt,name=expired_minite,json=expiredMinite,proto3" json:"expired_minite" bson:"expired_minite"`
	// contains filtered or unexported fields
}

Code 验证码

func NewCode

func NewCode(req *IssueCodeRequest) (*Code, error)

NewCode todo

func (*Code) Descriptor deprecated

func (*Code) Descriptor() ([]byte, []int)

Deprecated: Use Code.ProtoReflect.Descriptor instead.

func (*Code) GetCode

func (x *Code) GetCode() string

func (*Code) GetExpiredMinite

func (x *Code) GetExpiredMinite() uint32

func (*Code) GetId

func (x *Code) GetId() string

func (*Code) GetIssueAt

func (x *Code) GetIssueAt() int64

func (*Code) GetUsername

func (x *Code) GetUsername() string

func (*Code) IsExpired

func (c *Code) IsExpired() bool

IsExpired todo

func (*Code) ProtoMessage

func (*Code) ProtoMessage()

func (*Code) ProtoReflect

func (x *Code) ProtoReflect() protoreflect.Message

func (*Code) Reset

func (x *Code) Reset()

func (*Code) String

func (x *Code) String() string

type IssueCodeRequest

type IssueCodeRequest struct {

	// 颁发方式
	// @gotags: json:"issue_by"
	IssueBy token.GRANT_TYPE `protobuf:"varint,1,opt,name=issue_by,json=issueBy,proto3,enum=go8.devcloud.mcenter.token.GRANT_TYPE" json:"issue_by"`
	// PASSWORD/LDAP授权时, 用户名
	// @gotags: json:"username,omitempty"
	Username string `protobuf:"bytes,2,opt,name=username,proto3" json:"username,omitempty"`
	// PASSWORD/LDAP授权时, 用户密码
	// @gotags: json:"password,omitempty"
	Password string `protobuf:"bytes,3,opt,name=password,proto3" json:"password,omitempty"`
	// PRIVATE_TOKEN授权时, 访问令牌
	// @gotags: json:"access_token,omitempty"
	AccessToken string `protobuf:"bytes,4,opt,name=access_token,json=accessToken,proto3" json:"access_token,omitempty"`
	// AUTH_CODE授权时, Code, 针对第三方登陆: 飞书/钉钉/企业微信
	// @gotags: json:"auth_code"
	AuthCode string `protobuf:"bytes,5,opt,name=auth_code,json=authCode,proto3" json:"auth_code"`
	// contains filtered or unexported fields
}

IssueCodeRequest 验证码申请请求

func NewIssueCodeRequest

func NewIssueCodeRequest() *IssueCodeRequest

NewIssueCodeRequest todo

func (*IssueCodeRequest) Descriptor deprecated

func (*IssueCodeRequest) Descriptor() ([]byte, []int)

Deprecated: Use IssueCodeRequest.ProtoReflect.Descriptor instead.

func (*IssueCodeRequest) GetAccessToken

func (x *IssueCodeRequest) GetAccessToken() string

func (*IssueCodeRequest) GetAuthCode

func (x *IssueCodeRequest) GetAuthCode() string

func (*IssueCodeRequest) GetIssueBy

func (x *IssueCodeRequest) GetIssueBy() token.GRANT_TYPE

func (*IssueCodeRequest) GetPassword

func (x *IssueCodeRequest) GetPassword() string

func (*IssueCodeRequest) GetUsername

func (x *IssueCodeRequest) GetUsername() string

func (*IssueCodeRequest) ProtoMessage

func (*IssueCodeRequest) ProtoMessage()

func (*IssueCodeRequest) ProtoReflect

func (x *IssueCodeRequest) ProtoReflect() protoreflect.Message

func (*IssueCodeRequest) Reset

func (x *IssueCodeRequest) Reset()

func (*IssueCodeRequest) String

func (x *IssueCodeRequest) String() string

func (*IssueCodeRequest) Validate

func (req *IssueCodeRequest) Validate() error

type IssueCodeResponse

type IssueCodeResponse struct {

	// 颁发后返回的消息, 比如以发送到xxx手机
	// @gotags: json:"message"
	Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message"`
	// contains filtered or unexported fields
}

IssueCodeResponse todo

func (*IssueCodeResponse) Descriptor deprecated

func (*IssueCodeResponse) Descriptor() ([]byte, []int)

Deprecated: Use IssueCodeResponse.ProtoReflect.Descriptor instead.

func (*IssueCodeResponse) GetMessage

func (x *IssueCodeResponse) GetMessage() string

func (*IssueCodeResponse) ProtoMessage

func (*IssueCodeResponse) ProtoMessage()

func (*IssueCodeResponse) ProtoReflect

func (x *IssueCodeResponse) ProtoReflect() protoreflect.Message

func (*IssueCodeResponse) Reset

func (x *IssueCodeResponse) Reset()

func (*IssueCodeResponse) String

func (x *IssueCodeResponse) String() string

type RPCClient

type RPCClient interface {
	VerifyCode(ctx context.Context, in *VerifyCodeRequest, opts ...grpc.CallOption) (*Code, error)
}

RPCClient is the client API for RPC service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

func NewRPCClient

func NewRPCClient(cc grpc.ClientConnInterface) RPCClient

type RPCServer

type RPCServer interface {
	VerifyCode(context.Context, *VerifyCodeRequest) (*Code, error)
	// contains filtered or unexported methods
}

RPCServer is the server API for RPC service. All implementations must embed UnimplementedRPCServer for forward compatibility

type Service

type Service interface {
	RPCServer
	IssueCode(context.Context, *IssueCodeRequest) (*IssueCodeResponse, error)
}

type UnimplementedRPCServer

type UnimplementedRPCServer struct {
}

UnimplementedRPCServer must be embedded to have forward compatible implementations.

func (UnimplementedRPCServer) VerifyCode

type UnsafeRPCServer

type UnsafeRPCServer interface {
	// contains filtered or unexported methods
}

UnsafeRPCServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to RPCServer will result in compilation errors.

type VerifyCodeRequest

type VerifyCodeRequest struct {

	// 用户名
	// @gotags: json:"username" validate:"required"
	Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username" validate:"required"`
	// 验证码
	// @gotags: json:"code" validate:"required"
	Code string `protobuf:"bytes,2,opt,name=code,proto3" json:"code" validate:"required"`
	// contains filtered or unexported fields
}

VerifyCodeRequest 验证码校验请求

func NewVerifyCodeRequest

func NewVerifyCodeRequest(username, code string) *VerifyCodeRequest

func (*VerifyCodeRequest) Descriptor deprecated

func (*VerifyCodeRequest) Descriptor() ([]byte, []int)

Deprecated: Use VerifyCodeRequest.ProtoReflect.Descriptor instead.

func (*VerifyCodeRequest) GetCode

func (x *VerifyCodeRequest) GetCode() string

func (*VerifyCodeRequest) GetUsername

func (x *VerifyCodeRequest) GetUsername() string

func (*VerifyCodeRequest) HashID

func (req *VerifyCodeRequest) HashID() string

HashID todo

func (*VerifyCodeRequest) ProtoMessage

func (*VerifyCodeRequest) ProtoMessage()

func (*VerifyCodeRequest) ProtoReflect

func (x *VerifyCodeRequest) ProtoReflect() protoreflect.Message

func (*VerifyCodeRequest) Reset

func (x *VerifyCodeRequest) Reset()

func (*VerifyCodeRequest) String

func (x *VerifyCodeRequest) String() string

func (*VerifyCodeRequest) Validate

func (req *VerifyCodeRequest) Validate() error

Validate todo

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL