| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package grpc
- import (
- "context"
- "google.golang.org/grpc/metadata"
- pb "sportfitness/base/api/grpc/base"
- "sportfitness/base/assembly/base/service"
- "strings"
- )
- type Api struct {
- pb.UnimplementedApiServer
- }
- func (Api) getRemoteIp(ctx context.Context) string {
- if md, ok := metadata.FromIncomingContext(ctx); ok {
- ip := md.Get("x-forwarded-for")
- if len(ip) > 0 {
- return ip[0]
- }
- }
- return ""
- }
- func (Api) getUserAgent(ctx context.Context) string {
- if md, ok := metadata.FromIncomingContext(ctx); ok {
- agents := md.Get("user-agent")
- return strings.Join(agents, "\n")
- }
- return ""
- }
- func (Api) getToken(ctx context.Context) (token string) {
- if md, ok := metadata.FromIncomingContext(ctx); ok {
- sl := md.Get("token")
- if len(sl) >= 1 {
- token = sl[0]
- }
- }
- return
- }
- func (a Api) SignIn(ctx context.Context, q *pb.SignInRequest) (*pb.SignInReply, error) {
- token := service.User{}.SignInUserCodePassword(
- q.Name, q.Password, a.getRemoteIp(ctx), a.getUserAgent(ctx), q.CodeID, q.VerifyCode)
- return &pb.SignInReply{Token: token}, nil
- }
- func (a Api) GenVerifyImage(ctx context.Context, q *pb.GenVerifyImageRequest) (*pb.GenVerifyImageReply, error) {
- codeId, imageBase64 := service.User{}.GenVerifyImage(q.Height, q.Width)
- return &pb.GenVerifyImageReply{ImageBase64: imageBase64, CodeId: codeId}, nil
- }
- //func (a Api) SignUpInWithPhone() {
- //
- //}
|