正在显示
5 个修改的文件
包含
22 行增加
和
112 行删除
@@ -5,7 +5,7 @@ import ( | @@ -5,7 +5,7 @@ import ( | ||
5 | "fmt" | 5 | "fmt" |
6 | "oppmg/common/log" | 6 | "oppmg/common/log" |
7 | "oppmg/protocol" | 7 | "oppmg/protocol" |
8 | - "oppmg/services/serveauth" | 8 | + "oppmg/services/auth" |
9 | 9 | ||
10 | "github.com/astaxie/beego/validation" | 10 | "github.com/astaxie/beego/validation" |
11 | ) | 11 | ) |
@@ -44,7 +44,7 @@ func (c *AuthController) AccessToken() { | @@ -44,7 +44,7 @@ func (c *AuthController) AccessToken() { | ||
44 | //TODO | 44 | //TODO |
45 | log.Error("参数错误") | 45 | log.Error("参数错误") |
46 | } | 46 | } |
47 | - data, commErr := serveauth.GetAccessToken(param) | 47 | + data, commErr := auth.GetAccessToken(param) |
48 | msg = protocol.NewReturnResponse(data, commErr) | 48 | msg = protocol.NewReturnResponse(data, commErr) |
49 | return | 49 | return |
50 | } | 50 | } |
@@ -68,3 +68,21 @@ type RequestPositionDelete struct { | @@ -68,3 +68,21 @@ type RequestPositionDelete struct { | ||
68 | CompanyID int64 `json:"company_id"` | 68 | CompanyID int64 `json:"company_id"` |
69 | IDs []int64 `json:"ids"` | 69 | IDs []int64 `json:"ids"` |
70 | } | 70 | } |
71 | + | ||
72 | +type RequestUserAdd struct { | ||
73 | + Name string `json:"name"` | ||
74 | + CompanyId int64 `json:"company_id"` | ||
75 | + Phone string `json:"phone` | ||
76 | + Departments []int `json:"departments"` | ||
77 | + Positions []int `json:"positions"` | ||
78 | + Roles []int `json:"roles"` | ||
79 | +} | ||
80 | + | ||
81 | +type RequestUserEdit struct { | ||
82 | + Name string `json:"name"` | ||
83 | + CompanyId int64 `json:"company_id"` | ||
84 | + Phone string `json:"phone` | ||
85 | + Departments []int `json:"departments"` | ||
86 | + Positions []int `json:"positions"` | ||
87 | + Roles []int `json:"roles"` | ||
88 | +} |
@@ -148,7 +148,7 @@ func positionRelationUpdate(positionUpdate *models.Position, newparent *models.P | @@ -148,7 +148,7 @@ func positionRelationUpdate(positionUpdate *models.Position, newparent *models.P | ||
148 | return nil | 148 | return nil |
149 | } | 149 | } |
150 | const ( | 150 | const ( |
151 | - //获取某个部门的下级部门 select ... for update | 151 | + //获取某个部门的下级部门 锁数据 select ... for update |
152 | dataSql0 string = `SELECT id,relation FROM position WHERE relation LIKE ? AND delete_at = 0 FOR UPDATE` | 152 | dataSql0 string = `SELECT id,relation FROM position WHERE relation LIKE ? AND delete_at = 0 FOR UPDATE` |
153 | //更新关系树 | 153 | //更新关系树 |
154 | dataSql2 string = `update position set relation=? where id=?` | 154 | dataSql2 string = `update position set relation=? where id=?` |
services/serveauth/auth.go
已删除
100644 → 0
1 | -package serveauth | ||
2 | - | ||
3 | -import ( | ||
4 | - "crypto/sha1" | ||
5 | - "encoding/hex" | ||
6 | - "fmt" | ||
7 | - "io" | ||
8 | - "oppmg/common/config" | ||
9 | - "oppmg/common/log" | ||
10 | - "oppmg/models" | ||
11 | - "oppmg/protocol" | ||
12 | - "oppmg/utils" | ||
13 | - "strings" | ||
14 | - "time" | ||
15 | - | ||
16 | - "github.com/astaxie/beego/orm" | ||
17 | -) | ||
18 | - | ||
19 | -//GetAccessToken 获取accessToken | ||
20 | -func GetAccessToken(param protocol.RequestCheckSmsCode) (*protocol.DataUserInfo, error) { | ||
21 | - data := &protocol.DataUserInfo{} | ||
22 | - err := protocol.NewErrWithMessage("00000") | ||
23 | - log.Info("log 打印") | ||
24 | - log.Info("%+v", config.MConfig) | ||
25 | - return data, err | ||
26 | -} | ||
27 | - | ||
28 | -//ValidatePassword ... | ||
29 | -//from:待校验的密码;to:比对用的密文 | ||
30 | -func validatePassword(from, to string) bool { | ||
31 | - //密码加密方式sha1 | ||
32 | - h := sha1.New() | ||
33 | - io.WriteString(h, from) | ||
34 | - str := hex.EncodeToString(h.Sum(nil)) | ||
35 | - if strings.Compare(str, to) == 0 { | ||
36 | - return true | ||
37 | - } | ||
38 | - return false | ||
39 | -} | ||
40 | - | ||
41 | -//LoginAuth 登录认证 | ||
42 | -func LoginAuthByPassword(account, password string) error { | ||
43 | - var ( | ||
44 | - user *models.User | ||
45 | - uAuth *models.UserAuth | ||
46 | - err error | ||
47 | - ) | ||
48 | - user, err = models.GetUserByPhone(account) | ||
49 | - if err != nil { | ||
50 | - log.Error(err.Error()) | ||
51 | - return protocol.NewErrWithMessage("1", err) | ||
52 | - } | ||
53 | - if ok := validatePassword(password, user.Passwd); !ok { | ||
54 | - return protocol.NewErrWithMessage("1", err) | ||
55 | - } | ||
56 | - | ||
57 | - uAuth, err = models.ReadUserAuthByDevice(user.Id, models.DEVICE_TYPE_WEB) | ||
58 | - if err != nil && err != orm.ErrNoRows { | ||
59 | - e := fmt.Errorf("ReadUserAuthByDevice(%d,%d) err:%s", user.Id, models.DEVICE_TYPE_WEB, err) | ||
60 | - log.Error(e.Error()) | ||
61 | - return protocol.NewErrWithMessage("1", e) | ||
62 | - } | ||
63 | - var ( | ||
64 | - authcode string | ||
65 | - authcodeExp time.Time | ||
66 | - ) | ||
67 | - authcode = utils.GenerateIDByUUID() | ||
68 | - authcodeExp = time.Now().Add(time.Duration(models.AUTHCODE_TIME) * time.Second) | ||
69 | - if err == orm.ErrNoRows { | ||
70 | - uAuth := &models.UserAuth{ | ||
71 | - UserId: user.Id, | ||
72 | - AuthCode: authcode, | ||
73 | - AuthCodeExp: authcodeExp, | ||
74 | - CreateAt: time.Now(), | ||
75 | - } | ||
76 | - _, err = models.AddUserAuth(uAuth) | ||
77 | - if err != nil { | ||
78 | - e := fmt.Errorf("AddUserAuth err:%s", err) | ||
79 | - log.Error(e.Error()) | ||
80 | - return protocol.NewErrWithMessage("1", e) | ||
81 | - } | ||
82 | - } | ||
83 | - if err == nil { | ||
84 | - uAuth.AuthCode = authcode | ||
85 | - uAuth.AuthCodeExp = authcodeExp | ||
86 | - uAuth.UpdateAt = time.Now() | ||
87 | - err = models.UpdateUserAuthById(uAuth) | ||
88 | - if err != nil { | ||
89 | - e := fmt.Errorf("UpdateUserAuthById err:%s", err) | ||
90 | - log.Error(e.Error()) | ||
91 | - return protocol.NewErrWithMessage("1", e) | ||
92 | - } | ||
93 | - } | ||
94 | - | ||
95 | - return nil | ||
96 | -} | ||
97 | - | ||
98 | -//RefreshAccessToken 刷新token | ||
99 | -func RefreshAccessToken(account string, token string) error { | ||
100 | - return nil | ||
101 | -} | ||
102 | - | ||
103 | -// func buildNewUserAuth(uid int64,) *models.UserAuth { | ||
104 | -// m:=&models.UserAuth{ | ||
105 | -// User | ||
106 | -// } | ||
107 | -// return nil | ||
108 | -// } |
@@ -26,7 +26,7 @@ func CreateJWTToken(id int) (string, error) { | @@ -26,7 +26,7 @@ func CreateJWTToken(id int) (string, error) { | ||
26 | NotBefore: nowTime, | 26 | NotBefore: nowTime, |
27 | IssuedAt: nowTime, | 27 | IssuedAt: nowTime, |
28 | ExpiresAt: 60 * 60 * 2, //过期时间 | 28 | ExpiresAt: 60 * 60 * 2, //过期时间 |
29 | - Issuer: "test_a", | 29 | + Issuer: "mmm_oppmg", |
30 | }, | 30 | }, |
31 | UID: id, | 31 | UID: id, |
32 | } | 32 | } |
-
请 注册 或 登录 后发表评论