1
|
package auth
|
1
|
package auth
|
2
|
|
2
|
|
3
|
import (
|
3
|
import (
|
|
|
4
|
+ "fmt"
|
4
|
"gitlab.fjmaimaimai.com/mmm-go/ability/models"
|
5
|
"gitlab.fjmaimaimai.com/mmm-go/ability/models"
|
5
|
"gitlab.fjmaimaimai.com/mmm-go/ability/protocol"
|
6
|
"gitlab.fjmaimaimai.com/mmm-go/ability/protocol"
|
6
|
- "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego"
|
|
|
7
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
|
7
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
|
|
|
8
|
+ "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego"
|
8
|
"strings"
|
9
|
"strings"
|
9
|
)
|
10
|
)
|
10
|
|
11
|
|
11
|
-func Login(request *protocol.LoginRequest)*mybeego.Message{
|
|
|
12
|
- user,err:=models.GetUsersByMobile(request.Phone)
|
12
|
+func Login(request *protocol.LoginRequest)(rsp *protocol.LoginResponse,err error){
|
|
|
13
|
+ var (
|
|
|
14
|
+ user *models.Users
|
|
|
15
|
+ userInfo *models.UserInfo
|
|
|
16
|
+ )
|
|
|
17
|
+ user,err =models.GetUsersByMobile(request.Phone)
|
13
|
if err!=nil{
|
18
|
if err!=nil{
|
14
|
log.Error(err)
|
19
|
log.Error(err)
|
15
|
- return mybeego.NewMessage(1)
|
20
|
+ return
|
16
|
}
|
21
|
}
|
17
|
switch request.GrantType {
|
22
|
switch request.GrantType {
|
18
|
case protocol.LoginPassPord:
|
23
|
case protocol.LoginPassPord:
|
|
@@ -23,19 +28,20 @@ func Login(request *protocol.LoginRequest)*mybeego.Message{ |
|
@@ -23,19 +28,20 @@ func Login(request *protocol.LoginRequest)*mybeego.Message{ |
23
|
case protocol.LoginSmdcode:
|
28
|
case protocol.LoginSmdcode:
|
24
|
goto Success
|
29
|
goto Success
|
25
|
default:
|
30
|
default:
|
26
|
- return mybeego.NewErrMessage(2,"err grantType")
|
31
|
+ err =fmt.Errorf("grantType error")
|
|
|
32
|
+ return
|
27
|
}
|
33
|
}
|
28
|
Success:
|
34
|
Success:
|
29
|
{
|
35
|
{
|
30
|
- userInfo,err :=models.GetUserInfoByMobile(request.Phone)
|
36
|
+ userInfo,err =models.GetUserInfoByMobile(request.Phone)
|
31
|
if err!=nil{
|
37
|
if err!=nil{
|
32
|
log.Error(err)
|
38
|
log.Error(err)
|
33
|
- return mybeego.NewMessage(1)
|
39
|
+ return
|
34
|
}
|
40
|
}
|
35
|
rsp :=protocol.LoginResponse{AuthCode:userInfo.Auth}
|
41
|
rsp :=protocol.LoginResponse{AuthCode:userInfo.Auth}
|
36
|
msg :=mybeego.NewMessage(0)
|
42
|
msg :=mybeego.NewMessage(0)
|
37
|
msg.Data =rsp
|
43
|
msg.Data =rsp
|
38
|
- return msg
|
44
|
+ return
|
39
|
}
|
45
|
}
|
40
|
- return mybeego.NewMessage(1)
|
46
|
+ return
|
41
|
} |
47
|
} |