accountaction.go
1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package actions
import (
"context"
"fmt"
"pro2d/conf"
"pro2d/models"
"pro2d/protos/pb"
"pro2d/utils"
)
func (s *AccountServer) RegisterHandler(ctx context.Context, in *pb.Register) (*pb.PubRsp, error) {
ok, account := models.AccountExistByPhone(in.Phone)
if !ok {
account.Phone = in.Phone
account.Password = utils.Md5V(in.Password)
account.Uid = conf.SnowFlack.NextValStr()
account.Device = "123123"
account.Create()
}else {
return nil, fmt.Errorf("1")
}
return &pb.PubRsp{
Code: 0,
}, nil
}
func (s *AccountServer) CreateTokenHandler(ctx context.Context, in *pb.AccountInfo) (*pb.CreateTokenRsp, error) {
m := models.NewAccount(in.Phone)
if err := m.Load(); err != nil {
return &pb.CreateTokenRsp{
Rsp: &pb.PubRsp{
Code: 1,
Msg: err.Error(),
},
}, nil
}
if m.Password != utils.Md5V(in.Password) {
return &pb.CreateTokenRsp{
Rsp: &pb.PubRsp{
Code: 2,
Msg: "password error",
},
}, nil
}
serverInfo := s.EtcdClient.GetByPrefix(conf.GlobalConf.GameConf.Name)
var gameInfo []*pb.ServiceInfo
for k, v := range serverInfo {
gameInfo = append(gameInfo, &pb.ServiceInfo{
Id: k,
Name: conf.GlobalConf.GameConf.Name,
Address: v,
})
}
return &pb.CreateTokenRsp{
Rsp: &pb.PubRsp{
Code: 0,
},
Token: utils.CreateToken(m.AccountInfo),
GameService: gameInfo,
}, nil
}