Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/opp into dev
正在显示
20 个修改的文件
包含
486 行增加
和
122 行删除
CHANGELOG.md
0 → 100644
1 | +### 接口完成进度 | ||
2 | +|功能|完成状态|时间|接口路径|人员 | ||
3 | +|---|---|----|----|---| | ||
4 | +|修改手机号-校验验证码|完成|2019.11.20|/v1/user/checkSmsCode| | ||
5 | +|修改手机号|完成|2019.11.20|/v1/user/changePhone| | ||
6 | +|修改密码|完成|2019.11.20|v1/user/changePassword| | ||
7 | +|忘记密码|完成|2019.11.20|v1/user/resetPassword| | ||
8 | +|机会评论列表| |2019.11.|/v1/chance/comments| | ||
9 | +|我来评论| |2019.11.|/v1/chance/iComment| | ||
10 | +|我的评论| |2019.11.|/v1/chance/iComments| | ||
11 | +|我的点赞| |2019.11.| | | ||
12 | +|我的收藏| |2019.11.| | | ||
13 | +|我提交的机会| |2019.11.| | | ||
14 | +|我审核的机会| |2019.11.| | | ||
15 | +|待抓住机会列表| |2019.11. | | ||
16 | +|机会池| |2019.11.| | | ||
17 | +|提交机会| |2019.11.| | | ||
18 | +|机会审核消息| |2019.11.| | | ||
19 | +|机会互动消息| |2019.11.| | |
controllers/v1/user.go
0 → 100644
1 | +package v1 | ||
2 | + | ||
3 | +import ( | ||
4 | + "encoding/json" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | ||
6 | + "opp/controllers" | ||
7 | + "opp/protocol" | ||
8 | + "opp/services/user" | ||
9 | +) | ||
10 | + | ||
11 | +type UserController struct { | ||
12 | + controllers.BaseController | ||
13 | +} | ||
14 | + | ||
15 | +//CheckSmsCode | ||
16 | +// @router /checkSmsCode [post] | ||
17 | +func (this *UserController) CheckSmsCode() { | ||
18 | + var msg *protocol.ResponseMessage | ||
19 | + defer func() { | ||
20 | + this.Resp(msg) | ||
21 | + }() | ||
22 | + var request *protocol.CheckSmsCodeRequest | ||
23 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
24 | + log.Error(err) | ||
25 | + msg = protocol.BadRequestParam(1) | ||
26 | + return | ||
27 | + } | ||
28 | + if b, m := this.Valid(request); !b { | ||
29 | + msg = m | ||
30 | + return | ||
31 | + } | ||
32 | + header := controllers.GetRequestHeader(this.Ctx) | ||
33 | + msg = protocol.NewReturnResponse(user.CheckSmsCode(header, request)) | ||
34 | +} | ||
35 | + | ||
36 | +//ChangePhone | ||
37 | +// @router /changePhone [post] | ||
38 | +func (this *UserController) ChangePhone() { | ||
39 | + var msg *protocol.ResponseMessage | ||
40 | + defer func() { | ||
41 | + this.Resp(msg) | ||
42 | + }() | ||
43 | + var request *protocol.ChangePhoneRequest | ||
44 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
45 | + log.Error(err) | ||
46 | + msg = protocol.BadRequestParam(1) | ||
47 | + return | ||
48 | + } | ||
49 | + if b, m := this.Valid(request); !b { | ||
50 | + msg = m | ||
51 | + return | ||
52 | + } | ||
53 | + header := controllers.GetRequestHeader(this.Ctx) | ||
54 | + msg = protocol.NewReturnResponse(user.ChangePhone(header, request)) | ||
55 | +} | ||
56 | + | ||
57 | +//ResetPassword | ||
58 | +// @router /resetPassword [post] | ||
59 | +func (this *UserController) ResetPassword() { | ||
60 | + var msg *protocol.ResponseMessage | ||
61 | + defer func() { | ||
62 | + this.Resp(msg) | ||
63 | + }() | ||
64 | + var request *protocol.ResetPasswordRequest | ||
65 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
66 | + log.Error(err) | ||
67 | + msg = protocol.BadRequestParam(1) | ||
68 | + return | ||
69 | + } | ||
70 | + if b, m := this.Valid(request); !b { | ||
71 | + msg = m | ||
72 | + return | ||
73 | + } | ||
74 | + header := controllers.GetRequestHeader(this.Ctx) | ||
75 | + msg = protocol.NewReturnResponse(user.ResetPassword(header, request)) | ||
76 | +} | ||
77 | + | ||
78 | +//ChangePassword | ||
79 | +// @router /changePassword [post] | ||
80 | +func (this *UserController) ChangePassword() { | ||
81 | + var msg *protocol.ResponseMessage | ||
82 | + defer func() { | ||
83 | + this.Resp(msg) | ||
84 | + }() | ||
85 | + var request *protocol.ChangePasswordRequest | ||
86 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
87 | + log.Error(err) | ||
88 | + msg = protocol.BadRequestParam(1) | ||
89 | + return | ||
90 | + } | ||
91 | + if b, m := this.Valid(request); !b { | ||
92 | + msg = m | ||
93 | + return | ||
94 | + } | ||
95 | + header := controllers.GetRequestHeader(this.Ctx) | ||
96 | + msg = protocol.NewReturnResponse(user.ChangePassword(header, request)) | ||
97 | +} |
@@ -17,7 +17,7 @@ func (r *UserRepository) GetUsersById(uid int64) (v *models.User, err error) { | @@ -17,7 +17,7 @@ func (r *UserRepository) GetUsersById(uid int64) (v *models.User, err error) { | ||
17 | } | 17 | } |
18 | 18 | ||
19 | func (r *UserRepository) GetUsersByMobile(mobile string) (v *models.User, err error) { | 19 | func (r *UserRepository) GetUsersByMobile(mobile string) (v *models.User, err error) { |
20 | - return models.GetUsersByMobile(mobile) | 20 | + return models.GetUserByMobile(mobile) |
21 | } | 21 | } |
22 | 22 | ||
23 | func (r *UserRepository) UpdateUserInfo(m *models.User) (err error) { | 23 | func (r *UserRepository) UpdateUserInfo(m *models.User) (err error) { |
@@ -8,6 +8,7 @@ type IUserAuthRepository interface { | @@ -8,6 +8,7 @@ type IUserAuthRepository interface { | ||
8 | GetUserAuthByAuthCode(authCode string) (v *models.UserAuth, err error) | 8 | GetUserAuthByAuthCode(authCode string) (v *models.UserAuth, err error) |
9 | GetUserAuthByRefreshToken(refreshToken string) (v *models.UserAuth, err error) | 9 | GetUserAuthByRefreshToken(refreshToken string) (v *models.UserAuth, err error) |
10 | GetUserAuthByToken(refreshToken string) (v *models.UserAuth, err error) | 10 | GetUserAuthByToken(refreshToken string) (v *models.UserAuth, err error) |
11 | + AddUserAuth(m *models.UserAuth) (err error) | ||
11 | } | 12 | } |
12 | 13 | ||
13 | var _ IUserAuthRepository = (*UserAuthRepository)(nil) | 14 | var _ IUserAuthRepository = (*UserAuthRepository)(nil) |
@@ -22,6 +23,11 @@ func (r *UserAuthRepository) UpdateUserAuthById(m *models.UserAuth) (err error) | @@ -22,6 +23,11 @@ func (r *UserAuthRepository) UpdateUserAuthById(m *models.UserAuth) (err error) | ||
22 | return models.UpdateUserAuthById(m) | 23 | return models.UpdateUserAuthById(m) |
23 | } | 24 | } |
24 | 25 | ||
26 | +func (r *UserAuthRepository) AddUserAuth(m *models.UserAuth) (err error) { | ||
27 | + _, err = models.AddUserAuth(m) | ||
28 | + return | ||
29 | +} | ||
30 | + | ||
25 | func (r *UserAuthRepository) GetUserAuthByAuthCode(authCode string) (v *models.UserAuth, err error) { | 31 | func (r *UserAuthRepository) GetUserAuthByAuthCode(authCode string) (v *models.UserAuth, err error) { |
26 | return models.GetUserByAuthCode(authCode) | 32 | return models.GetUserByAuthCode(authCode) |
27 | } | 33 | } |
@@ -33,3 +33,8 @@ func (r *UserAuthMockRepository) GetUserAuthByToken(refreshToken string) (v *mod | @@ -33,3 +33,8 @@ func (r *UserAuthMockRepository) GetUserAuthByToken(refreshToken string) (v *mod | ||
33 | v = userAuth | 33 | v = userAuth |
34 | return | 34 | return |
35 | } | 35 | } |
36 | + | ||
37 | +func (r *UserAuthMockRepository) AddUserAuth(m *models.UserAuth) (err error) { | ||
38 | + //_,err =models.AddUserAuth(m) | ||
39 | + return | ||
40 | +} |
internal/utils/sql.go
0 → 100644
1 | +package utils | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "github.com/astaxie/beego" | ||
7 | + "github.com/astaxie/beego/orm" | ||
8 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | ||
9 | + "reflect" | ||
10 | +) | ||
11 | + | ||
12 | +// 更新指定表的几个列 | ||
13 | +func UpdateTableByMap(tabeleStruct interface{}, changeMap map[string]interface{}) error { | ||
14 | + if reflect.TypeOf(tabeleStruct).Kind() != reflect.Ptr { | ||
15 | + err := errors.New("UpdateTableByMap: tableStruct must ptr") | ||
16 | + beego.Error(err) | ||
17 | + return err | ||
18 | + } | ||
19 | + if len(changeMap) < 1 { | ||
20 | + beego.Info("changeMap is nil") | ||
21 | + return nil | ||
22 | + } | ||
23 | + o := orm.NewOrm() | ||
24 | + changeColumn := make([]string, 0, len(changeMap)) | ||
25 | + for i, v := range changeMap { | ||
26 | + changeColumn = append(changeColumn, i) | ||
27 | + if err := SetStructValueByType(tabeleStruct, i, v); err != nil { | ||
28 | + beego.Error(err, i, v) | ||
29 | + return err | ||
30 | + } | ||
31 | + } | ||
32 | + num, err := o.Update(tabeleStruct, changeColumn...) | ||
33 | + if err != nil { | ||
34 | + beego.Error(err) | ||
35 | + return err | ||
36 | + } | ||
37 | + log.Info(fmt.Sprintf("UpdateTableByMap: table:%s effect records:%d column:%v", GetTableName(tabeleStruct), num, changeColumn)) | ||
38 | + return nil | ||
39 | +} | ||
40 | + | ||
41 | +// 通过反射调用结构对应的TableName函数,达到返回表名的目的 | ||
42 | +func GetTableName(tableStruct interface{}) string { | ||
43 | + m := reflect.ValueOf(tableStruct).MethodByName("TableName") | ||
44 | + if m.IsValid() && m.Kind() == reflect.Func { | ||
45 | + re := m.Call(nil) | ||
46 | + for _, v := range re { | ||
47 | + if v.IsValid() { | ||
48 | + return v.String() | ||
49 | + } | ||
50 | + } | ||
51 | + } | ||
52 | + return "unknown" | ||
53 | +} | ||
54 | + | ||
55 | +// 通用事物提交sql结构体 | ||
56 | +type SqlData struct { | ||
57 | + Sql string | ||
58 | + Param []interface{} | ||
59 | +} | ||
60 | + | ||
61 | +func ExecuteSqlByRoll(isCheck bool, sqlSlice ...*SqlData) bool { | ||
62 | + o := orm.NewOrm() | ||
63 | + var someError bool = false | ||
64 | + o.Begin() | ||
65 | + for i := range sqlSlice { | ||
66 | + if sqlSlice[i].Sql == "" { | ||
67 | + continue | ||
68 | + } | ||
69 | + log.Info("execute sql:", sqlSlice[i]) | ||
70 | + if ret, err := o.Raw(sqlSlice[i].Sql, sqlSlice[i].Param...).Exec(); err != nil { | ||
71 | + log.Error(err) | ||
72 | + someError = true | ||
73 | + } else { | ||
74 | + num, _ := ret.RowsAffected() | ||
75 | + log.Debug("num:", num) | ||
76 | + if isCheck && num < 1 { | ||
77 | + someError = true | ||
78 | + } | ||
79 | + } | ||
80 | + } | ||
81 | + if someError { | ||
82 | + log.Error("出错,回滚事物") | ||
83 | + o.Rollback() | ||
84 | + return false | ||
85 | + } else { | ||
86 | + log.Info("成功,提交事物") | ||
87 | + o.Commit() | ||
88 | + return true | ||
89 | + } | ||
90 | + return true | ||
91 | +} |
internal/utils/utils.go
0 → 100644
1 | +package utils | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "reflect" | ||
6 | +) | ||
7 | + | ||
8 | +// 此函数将指定的结构体成员值更新到结构体中 | ||
9 | +func SetStructValueByType(s interface{}, columnType string, columnValue interface{}) error { | ||
10 | + columnValueV := reflect.ValueOf(columnValue) | ||
11 | + var setValue reflect.Value | ||
12 | + var flag = false | ||
13 | + v := reflect.ValueOf(s) | ||
14 | + for i, n := 0, v.Elem().NumField(); i < n; i++ { | ||
15 | + if v.Elem().Type().Field(i).Name == columnType { | ||
16 | + setValue = v.Elem().Field(i) | ||
17 | + flag = true | ||
18 | + break | ||
19 | + } | ||
20 | + } | ||
21 | + if !flag { | ||
22 | + return errors.New("struct is not type:") | ||
23 | + } else if !setValue.CanSet() { | ||
24 | + return errors.New("setValue.CanSet is false") | ||
25 | + } else if setValue.Kind() != columnValueV.Kind() { | ||
26 | + return errors.New("struct field and value of type is error") | ||
27 | + } | ||
28 | + switch columnValueV.Kind() { | ||
29 | + case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int, reflect.Int64: | ||
30 | + setValue.SetInt(int64(columnValueV.Int())) | ||
31 | + case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: | ||
32 | + setValue.SetUint(uint64(columnValueV.Uint())) | ||
33 | + case reflect.Float32, reflect.Float64: | ||
34 | + setValue.SetFloat(float64(columnValueV.Float())) | ||
35 | + case reflect.String: | ||
36 | + setValue.SetString(columnValueV.String()) | ||
37 | + default: | ||
38 | + return errors.New("columnValue err for:" + columnType) | ||
39 | + } | ||
40 | + return nil | ||
41 | +} |
@@ -12,7 +12,6 @@ import ( | @@ -12,7 +12,6 @@ import ( | ||
12 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/websocket" | 12 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/websocket" |
13 | "opp/controllers" | 13 | "opp/controllers" |
14 | "opp/internal/utils" | 14 | "opp/internal/utils" |
15 | - "opp/protocol" | ||
16 | _ "opp/routers" | 15 | _ "opp/routers" |
17 | "opp/services/im" | 16 | "opp/services/im" |
18 | "time" | 17 | "time" |
@@ -65,7 +64,6 @@ func main() { | @@ -65,7 +64,6 @@ func main() { | ||
65 | log.Info("app on stop!") | 64 | log.Info("app on stop!") |
66 | }() | 65 | }() |
67 | beego.InsertFilter("/*", beego.BeforeRouter, controllers.FilterComm) | 66 | beego.InsertFilter("/*", beego.BeforeRouter, controllers.FilterComm) |
68 | - protocol.InitMessageCode() | ||
69 | log.Info("app on start!") | 67 | log.Info("app on start!") |
70 | log.Info("Beego Run Mode:", beego.BConfig.RunMode) | 68 | log.Info("Beego Run Mode:", beego.BConfig.RunMode) |
71 | 69 |
@@ -187,7 +187,7 @@ func GetUserAuthByToken(refreshToken string) (v *UserAuth, err error) { | @@ -187,7 +187,7 @@ func GetUserAuthByToken(refreshToken string) (v *UserAuth, err error) { | ||
187 | // Id doesn't exist | 187 | // Id doesn't exist |
188 | func GetUserAuthByUserId(uid int64) (v *UserAuth, err error) { | 188 | func GetUserAuthByUserId(uid int64) (v *UserAuth, err error) { |
189 | o := orm.NewOrm() | 189 | o := orm.NewOrm() |
190 | - sql := "select * from user_id where user_id=?" // | 190 | + sql := "select * from user_auth where user_id=?" // |
191 | if err = o.Raw(sql, uid).QueryRow(&v); err == nil { | 191 | if err = o.Raw(sql, uid).QueryRow(&v); err == nil { |
192 | return v, nil | 192 | return v, nil |
193 | } | 193 | } |
@@ -56,7 +56,7 @@ func GetUsersById(id int64) (v *User, err error) { | @@ -56,7 +56,7 @@ func GetUsersById(id int64) (v *User, err error) { | ||
56 | 56 | ||
57 | // GetAllUsers retrieves all Users matches certain condition. Returns empty list if | 57 | // GetAllUsers retrieves all Users matches certain condition. Returns empty list if |
58 | // no records exist | 58 | // no records exist |
59 | -func GetAllUsers(query map[string]string, fields []string, sortby []string, order []string, | 59 | +func GetAllUser(query map[string]string, fields []string, sortby []string, order []string, |
60 | offset int64, limit int64) (ml []interface{}, err error) { | 60 | offset int64, limit int64) (ml []interface{}, err error) { |
61 | o := orm.NewOrm() | 61 | o := orm.NewOrm() |
62 | qs := o.QueryTable(new(User)) | 62 | qs := o.QueryTable(new(User)) |
@@ -162,18 +162,9 @@ func DeleteUsers(id int64) (err error) { | @@ -162,18 +162,9 @@ func DeleteUsers(id int64) (err error) { | ||
162 | return | 162 | return |
163 | } | 163 | } |
164 | 164 | ||
165 | -func GetUsersByMobile(mobile string) (v *User, err error) { | 165 | +func GetUserKefu() (v []*User, err error) { |
166 | o := orm.NewOrm() | 166 | o := orm.NewOrm() |
167 | - sql := `select * from users where username=?` | ||
168 | - if err = o.Raw(sql, mobile).QueryRow(&v); err == nil { | ||
169 | - return v, nil | ||
170 | - } | ||
171 | - return nil, err | ||
172 | -} | ||
173 | - | ||
174 | -func GetUsersKefu() (v []*User, err error) { | ||
175 | - o := orm.NewOrm() | ||
176 | - sql := `select * from users where is_kefu = 1` | 167 | + sql := `select * from user where is_kefu = 1` |
177 | if _, err = o.Raw(sql).QueryRows(&v); err == nil { | 168 | if _, err = o.Raw(sql).QueryRows(&v); err == nil { |
178 | return v, nil | 169 | return v, nil |
179 | } | 170 | } |
@@ -182,18 +173,9 @@ func GetUsersKefu() (v []*User, err error) { | @@ -182,18 +173,9 @@ func GetUsersKefu() (v []*User, err error) { | ||
182 | 173 | ||
183 | func GetUserByMobile(mobile string) (v *User, err error) { | 174 | func GetUserByMobile(mobile string) (v *User, err error) { |
184 | o := orm.NewOrm() | 175 | o := orm.NewOrm() |
185 | - sql := "select * from users where phone=?" | 176 | + sql := "select * from user where phone=?" |
186 | if err = o.Raw(sql, mobile).QueryRow(&v); err == nil { | 177 | if err = o.Raw(sql, mobile).QueryRow(&v); err == nil { |
187 | return v, nil | 178 | return v, nil |
188 | } | 179 | } |
189 | return nil, err | 180 | return nil, err |
190 | } | 181 | } |
191 | - | ||
192 | -//func GetUserInfoByClientId(clintId string) (v *User, err error) { | ||
193 | -// o := orm.NewOrm() | ||
194 | -// sql := "select * from users where clientId=?" | ||
195 | -// if err = o.Raw(sql, clintId).QueryRow(&v); err == nil { | ||
196 | -// return v, nil | ||
197 | -// } | ||
198 | -// return nil, err | ||
199 | -//} |
@@ -20,7 +20,7 @@ func (m ErrorMap) Search(code int) ErrorCode { | @@ -20,7 +20,7 @@ func (m ErrorMap) Search(code int) ErrorCode { | ||
20 | Errmsg: v, | 20 | Errmsg: v, |
21 | } | 21 | } |
22 | } | 22 | } |
23 | - return ErrorCode{} | 23 | + return ErrorCode{Errno: code, Errmsg: "错误码未定义"} |
24 | } | 24 | } |
25 | 25 | ||
26 | //ErrorCode 统一错误结构 | 26 | //ErrorCode 统一错误结构 |
1 | package protocol | 1 | package protocol |
2 | 2 | ||
3 | var errmessge ErrorMap = map[int]string{ | 3 | var errmessge ErrorMap = map[int]string{ |
4 | + 0: "", | ||
4 | 1: "系统异常", | 5 | 1: "系统异常", |
6 | + 2: "参数错误", | ||
5 | 101: "clientId或clientSecret无效", | 7 | 101: "clientId或clientSecret无效", |
6 | 113: "签名验证失败", | 8 | 113: "签名验证失败", |
7 | 1009: "验证码已超时,登录失败", | 9 | 1009: "验证码已超时,登录失败", |
@@ -19,35 +21,3 @@ var errmessge ErrorMap = map[int]string{ | @@ -19,35 +21,3 @@ var errmessge ErrorMap = map[int]string{ | ||
19 | 4141: "accessToken过期或无效,需要进行重新获取令牌", | 21 | 4141: "accessToken过期或无效,需要进行重新获取令牌", |
20 | 4142: "Uuid已存在,请求失败", | 22 | 4142: "Uuid已存在,请求失败", |
21 | } | 23 | } |
22 | - | ||
23 | - | ||
24 | -func InitMessageCode() { | ||
25 | - // messages := []struct { | ||
26 | - // Code int | ||
27 | - // Msg string | ||
28 | - // }{ | ||
29 | - // {101, "clientId或clientSecret无效"}, | ||
30 | - // {113, "签名验证失败"}, | ||
31 | - // {1009, "验证码已超时,登录失败"}, | ||
32 | - // {1011, "短信验证码次数超过限制,请稍后重试"}, | ||
33 | - // {1012, "验证码错误"}, | ||
34 | - | ||
35 | - // {2001, "请输入正确的手机号码"}, | ||
36 | - // {2002, "后台未配置账号信息,请联系管理员配置"}, | ||
37 | - // {2009, "上传的文件流为空"}, | ||
38 | - // {2020, "帐号不存在,请联系管理员"}, | ||
39 | - // {2021, "登录失败,手机号或密码错误"}, | ||
40 | - // {2025, "短信验证码验证失败"}, | ||
41 | - // {2026, "两次输入的密码不一致"}, | ||
42 | - | ||
43 | - // {4139, "authCode无效或过期"}, | ||
44 | - // {4140, "refreshToken过期,需要重新登录授权"}, | ||
45 | - // {4141, "accessToken过期或无效,需要进行重新获取令牌"}, | ||
46 | - // {4142, "Uuid已存在,请求失败"}, | ||
47 | - // } | ||
48 | - // for i := range messages { | ||
49 | - // mybeego.SetMessage(messages[i].Code, messages[i].Msg) | ||
50 | - // } | ||
51 | - //// | ||
52 | - | ||
53 | -} |
@@ -2,6 +2,7 @@ package protocol | @@ -2,6 +2,7 @@ package protocol | ||
2 | 2 | ||
3 | //短信类型 | 3 | //短信类型 |
4 | const ( | 4 | const ( |
5 | + SmsCode = "sms_code" | ||
5 | SmsLoginCode = "sms_login_code" | 6 | SmsLoginCode = "sms_login_code" |
6 | SmsChangeMobile = "sms_change_mobile" | 7 | SmsChangeMobile = "sms_change_mobile" |
7 | ) | 8 | ) |
@@ -12,4 +13,5 @@ type SmsInfo struct { | @@ -12,4 +13,5 @@ type SmsInfo struct { | ||
12 | ErrorCount int `json:"error_count"` | 13 | ErrorCount int `json:"error_count"` |
13 | LastTime int64 `json:"last_time"` | 14 | LastTime int64 `json:"last_time"` |
14 | CreateTime int64 `json:"create_time"` | 15 | CreateTime int64 `json:"create_time"` |
16 | + //Checked int `json:"checked"` //0:未校验证 1:已校验 | ||
15 | } | 17 | } |
protocol/user.go
0 → 100644
1 | +package protocol | ||
2 | + | ||
3 | +/*修改手机号-验证旧手机验证码 */ | ||
4 | +type CheckSmsCodeRequest struct { | ||
5 | + Captcha string `json:"captcha" valid:"Required"` | ||
6 | +} | ||
7 | +type CheckSmsCodeResponse struct { | ||
8 | +} | ||
9 | + | ||
10 | +/*修改手机号*/ | ||
11 | +type ChangePhoneRequest struct { | ||
12 | + Phone string `json:"phone" valid:"Required"` | ||
13 | + Captcha string `json:"captcha" valid:"Required"` | ||
14 | +} | ||
15 | +type ChangePhoneResponse struct { | ||
16 | +} | ||
17 | + | ||
18 | +/*ResetPassword */ | ||
19 | +type ResetPasswordRequest struct { | ||
20 | + NewPwd string `json:"newPwd" valid:"Required"` | ||
21 | + ConfirmPwd string `json:"confirmPwd" valid:"Required"` | ||
22 | +} | ||
23 | +type ResetPasswordResponse struct { | ||
24 | +} | ||
25 | + | ||
26 | +/*ChangePassword */ | ||
27 | +type ChangePasswordRequest struct { | ||
28 | + NewPwd string `json:"newPwd" valid:"Required"` | ||
29 | + ConfirmPwd string `json:"confirmPwd" valid:"Required"` | ||
30 | + OldPwd string `json:"oldPwd" valid:"Required"` | ||
31 | +} | ||
32 | +type ChangePasswordResponse struct { | ||
33 | +} |
@@ -9,66 +9,98 @@ func init() { | @@ -9,66 +9,98 @@ func init() { | ||
9 | 9 | ||
10 | beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"], | 10 | beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"], |
11 | beego.ControllerComments{ | 11 | beego.ControllerComments{ |
12 | - Method: "AccessToken", | ||
13 | - Router: `/accessToken`, | 12 | + Method: "AccessToken", |
13 | + Router: `/accessToken`, | ||
14 | AllowHTTPMethods: []string{"post"}, | 14 | AllowHTTPMethods: []string{"post"}, |
15 | - MethodParams: param.Make(), | ||
16 | - Params: nil}) | 15 | + MethodParams: param.Make(), |
16 | + Params: nil}) | ||
17 | 17 | ||
18 | beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"], | 18 | beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"], |
19 | beego.ControllerComments{ | 19 | beego.ControllerComments{ |
20 | - Method: "Login", | ||
21 | - Router: `/login`, | 20 | + Method: "Login", |
21 | + Router: `/login`, | ||
22 | AllowHTTPMethods: []string{"post"}, | 22 | AllowHTTPMethods: []string{"post"}, |
23 | - MethodParams: param.Make(), | ||
24 | - Params: nil}) | 23 | + MethodParams: param.Make(), |
24 | + Params: nil}) | ||
25 | 25 | ||
26 | beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"], | 26 | beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"], |
27 | beego.ControllerComments{ | 27 | beego.ControllerComments{ |
28 | - Method: "RefreshToken", | ||
29 | - Router: `/refreshToken`, | 28 | + Method: "RefreshToken", |
29 | + Router: `/refreshToken`, | ||
30 | AllowHTTPMethods: []string{"post"}, | 30 | AllowHTTPMethods: []string{"post"}, |
31 | - MethodParams: param.Make(), | ||
32 | - Params: nil}) | 31 | + MethodParams: param.Make(), |
32 | + Params: nil}) | ||
33 | 33 | ||
34 | beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"], | 34 | beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"], |
35 | beego.ControllerComments{ | 35 | beego.ControllerComments{ |
36 | - Method: "SmsCode", | ||
37 | - Router: `/smsCode`, | 36 | + Method: "SmsCode", |
37 | + Router: `/smsCode`, | ||
38 | AllowHTTPMethods: []string{"post"}, | 38 | AllowHTTPMethods: []string{"post"}, |
39 | - MethodParams: param.Make(), | ||
40 | - Params: nil}) | 39 | + MethodParams: param.Make(), |
40 | + Params: nil}) | ||
41 | 41 | ||
42 | beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"], | 42 | beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"], |
43 | beego.ControllerComments{ | 43 | beego.ControllerComments{ |
44 | - Method: "UpdateDevice", | ||
45 | - Router: `/updateDevice`, | 44 | + Method: "UpdateDevice", |
45 | + Router: `/updateDevice`, | ||
46 | AllowHTTPMethods: []string{"post"}, | 46 | AllowHTTPMethods: []string{"post"}, |
47 | - MethodParams: param.Make(), | ||
48 | - Params: nil}) | 47 | + MethodParams: param.Make(), |
48 | + Params: nil}) | ||
49 | 49 | ||
50 | beego.GlobalControllerRouter["opp/controllers/v1:CommendController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:CommendController"], | 50 | beego.GlobalControllerRouter["opp/controllers/v1:CommendController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:CommendController"], |
51 | beego.ControllerComments{ | 51 | beego.ControllerComments{ |
52 | - Method: "Company", | ||
53 | - Router: `/company`, | 52 | + Method: "Company", |
53 | + Router: `/company`, | ||
54 | AllowHTTPMethods: []string{"post"}, | 54 | AllowHTTPMethods: []string{"post"}, |
55 | - MethodParams: param.Make(), | ||
56 | - Params: nil}) | 55 | + MethodParams: param.Make(), |
56 | + Params: nil}) | ||
57 | 57 | ||
58 | beego.GlobalControllerRouter["opp/controllers/v1:UploadController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UploadController"], | 58 | beego.GlobalControllerRouter["opp/controllers/v1:UploadController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UploadController"], |
59 | beego.ControllerComments{ | 59 | beego.ControllerComments{ |
60 | - Method: "Image", | ||
61 | - Router: `/image`, | 60 | + Method: "Image", |
61 | + Router: `/image`, | ||
62 | AllowHTTPMethods: []string{"post"}, | 62 | AllowHTTPMethods: []string{"post"}, |
63 | - MethodParams: param.Make(), | ||
64 | - Params: nil}) | 63 | + MethodParams: param.Make(), |
64 | + Params: nil}) | ||
65 | 65 | ||
66 | beego.GlobalControllerRouter["opp/controllers/v1:UploadController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UploadController"], | 66 | beego.GlobalControllerRouter["opp/controllers/v1:UploadController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UploadController"], |
67 | beego.ControllerComments{ | 67 | beego.ControllerComments{ |
68 | - Method: "Voice", | ||
69 | - Router: `/voice`, | 68 | + Method: "Voice", |
69 | + Router: `/voice`, | ||
70 | AllowHTTPMethods: []string{"post"}, | 70 | AllowHTTPMethods: []string{"post"}, |
71 | - MethodParams: param.Make(), | ||
72 | - Params: nil}) | 71 | + MethodParams: param.Make(), |
72 | + Params: nil}) | ||
73 | + | ||
74 | + beego.GlobalControllerRouter["opp/controllers/v1:UserController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UserController"], | ||
75 | + beego.ControllerComments{ | ||
76 | + Method: "ChangePassword", | ||
77 | + Router: `/changePassword`, | ||
78 | + AllowHTTPMethods: []string{"post"}, | ||
79 | + MethodParams: param.Make(), | ||
80 | + Params: nil}) | ||
81 | + | ||
82 | + beego.GlobalControllerRouter["opp/controllers/v1:UserController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UserController"], | ||
83 | + beego.ControllerComments{ | ||
84 | + Method: "ChangePhone", | ||
85 | + Router: `/changePhone`, | ||
86 | + AllowHTTPMethods: []string{"post"}, | ||
87 | + MethodParams: param.Make(), | ||
88 | + Params: nil}) | ||
89 | + | ||
90 | + beego.GlobalControllerRouter["opp/controllers/v1:UserController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UserController"], | ||
91 | + beego.ControllerComments{ | ||
92 | + Method: "CheckSmsCode", | ||
93 | + Router: `/checkSmsCode`, | ||
94 | + AllowHTTPMethods: []string{"post"}, | ||
95 | + MethodParams: param.Make(), | ||
96 | + Params: nil}) | ||
97 | + | ||
98 | + beego.GlobalControllerRouter["opp/controllers/v1:UserController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UserController"], | ||
99 | + beego.ControllerComments{ | ||
100 | + Method: "ResetPassword", | ||
101 | + Router: `/resetPassword`, | ||
102 | + AllowHTTPMethods: []string{"post"}, | ||
103 | + MethodParams: param.Make(), | ||
104 | + Params: nil}) | ||
73 | 105 | ||
74 | } | 106 | } |
@@ -16,6 +16,7 @@ func init() { | @@ -16,6 +16,7 @@ func init() { | ||
16 | beego.NSNamespace("upload", beego.NSInclude(&v1.UploadController{})), | 16 | beego.NSNamespace("upload", beego.NSInclude(&v1.UploadController{})), |
17 | beego.NSNamespace("version", beego.NSInclude(&v1.VersionController{})), | 17 | beego.NSNamespace("version", beego.NSInclude(&v1.VersionController{})), |
18 | beego.NSNamespace("commend", beego.NSInclude(&v1.CommendController{})), | 18 | beego.NSNamespace("commend", beego.NSInclude(&v1.CommendController{})), |
19 | + beego.NSNamespace("user", beego.NSInclude(&v1.UserController{})), | ||
19 | ) | 20 | ) |
20 | beego.AddNamespace(nsV1) | 21 | beego.AddNamespace(nsV1) |
21 | beego.SetStaticPath("/file/ab", beego.AppConfig.String("source_path")) | 22 | beego.SetStaticPath("/file/ab", beego.AppConfig.String("source_path")) |
@@ -4,6 +4,7 @@ import ( | @@ -4,6 +4,7 @@ import ( | ||
4 | "bytes" | 4 | "bytes" |
5 | "encoding/json" | 5 | "encoding/json" |
6 | "fmt" | 6 | "fmt" |
7 | + "github.com/astaxie/beego/orm" | ||
7 | "html/template" | 8 | "html/template" |
8 | "math/rand" | 9 | "math/rand" |
9 | "strings" | 10 | "strings" |
@@ -72,7 +73,7 @@ func (s *AuthService) Login(request *protocol.LoginRequest) (rsp *protocol.Login | @@ -72,7 +73,7 @@ func (s *AuthService) Login(request *protocol.LoginRequest) (rsp *protocol.Login | ||
72 | } | 73 | } |
73 | break | 74 | break |
74 | case protocol.LoginTypeSmdcode: | 75 | case protocol.LoginTypeSmdcode: |
75 | - if result, err = CheckSmsCode(request.Phone, request.Code, protocol.SmsLoginCode); result && err == nil { | 76 | + if result, err = CheckSmsCode(request.Phone, request.Code, protocol.SmsCode); result && err == nil { |
76 | goto Success | 77 | goto Success |
77 | } else { | 78 | } else { |
78 | return | 79 | return |
@@ -90,12 +91,17 @@ Success: | @@ -90,12 +91,17 @@ Success: | ||
90 | } | 91 | } |
91 | userAuth, err = repository.UserAuth.GetUserAuthByUserId(user.Id) | 92 | userAuth, err = repository.UserAuth.GetUserAuthByUserId(user.Id) |
92 | if err != nil { | 93 | if err != nil { |
93 | - log.Error(err) | ||
94 | - return | ||
95 | - } | ||
96 | - if userAuth.AuthCode == "" { | ||
97 | - userAuth.AuthCode = uid.NewV1().StringNoDash() | 94 | + if err == orm.ErrNoRows { |
95 | + userAuth = &models.UserAuth{ | ||
96 | + UserId: user.Id, | ||
97 | + } | ||
98 | + repository.UserAuth.AddUserAuth(userAuth) | ||
99 | + } else { | ||
100 | + log.Error(err) | ||
101 | + return | ||
102 | + } | ||
98 | } | 103 | } |
104 | + userAuth.AuthCode = uid.NewV1().StringNoDash() | ||
99 | if checkImResponse, err = CheckIm(&protocol.CheckImRequest{ | 105 | if checkImResponse, err = CheckIm(&protocol.CheckImRequest{ |
100 | Uid: fmt.Sprintf("%v", user.Id), | 106 | Uid: fmt.Sprintf("%v", user.Id), |
101 | Uname: user.NickName, | 107 | Uname: user.NickName, |
@@ -239,8 +245,9 @@ func (s *AuthService) SmsCode(request *protocol.SmsCodeRequest) (rsp *protocol.S | @@ -239,8 +245,9 @@ func (s *AuthService) SmsCode(request *protocol.SmsCodeRequest) (rsp *protocol.S | ||
239 | case protocol.SmsLoginCode: | 245 | case protocol.SmsLoginCode: |
240 | case protocol.SmsChangeMobile: | 246 | case protocol.SmsChangeMobile: |
241 | default: | 247 | default: |
242 | - err = common.NewErrorWithMsg(2, "send_type error.") | ||
243 | - return | 248 | + request.SendType = protocol.SmsCode |
249 | + //err = common.NewErrorWithMsg(2, "send_type error.") | ||
250 | + //return | ||
244 | } | 251 | } |
245 | key = request.SendType | 252 | key = request.SendType |
246 | //check user phone exists | 253 | //check user phone exists |
@@ -427,7 +434,7 @@ func imUserRefreshToken(request *protocol.CheckImRequest, rsp *protocol.CheckImR | @@ -427,7 +434,7 @@ func imUserRefreshToken(request *protocol.CheckImRequest, rsp *protocol.CheckImR | ||
427 | 434 | ||
428 | // 获取客服id | 435 | // 获取客服id |
429 | func imGetRandomCSAccount() (acid int64) { | 436 | func imGetRandomCSAccount() (acid int64) { |
430 | - kefus, err := models.GetUsersKefu() | 437 | + kefus, err := models.GetUserKefu() |
431 | if err != nil { | 438 | if err != nil { |
432 | log.Error(err) | 439 | log.Error(err) |
433 | return | 440 | return |
1 | package user | 1 | package user |
2 | 2 | ||
3 | -//import | ||
4 | -//( | ||
5 | -// "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego" | ||
6 | -// "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | ||
7 | -// "opp/models" | ||
8 | -//) | ||
9 | -// | ||
10 | -//func GetUserList(mobile string)*protocol.ResponseMessage{ | ||
11 | -// u,err:=models.GetUserByMobile(mobile) | ||
12 | -// if err!=nil{ | ||
13 | -// log.Error(err) | ||
14 | -// log.Error(mobile) | ||
15 | -// return mybeego.NewErrMessage(1) | ||
16 | -// } | ||
17 | -// msg :=protocol.ReturnResponse(0) | ||
18 | -// msg.Data = u | ||
19 | -// return msg | ||
20 | -//} | 3 | +import ( |
4 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | ||
5 | + "opp/internal/repository" | ||
6 | + "opp/internal/utils" | ||
7 | + "opp/models" | ||
8 | + "opp/protocol" | ||
9 | + "opp/services/auth" | ||
10 | + "strings" | ||
11 | +) | ||
12 | + | ||
13 | +//验证smscode | ||
14 | +func CheckSmsCode(header *protocol.RequestHeader, request *protocol.CheckSmsCodeRequest) (rsp *protocol.CheckSmsCodeResponse, err error) { | ||
15 | + var ( | ||
16 | + user *models.User | ||
17 | + result bool | ||
18 | + ) | ||
19 | + //rsp =&protocol.CheckSmsCodeResponse{} | ||
20 | + | ||
21 | + if user, err = repository.User.GetUsersById(header.Uid); err != nil { | ||
22 | + log.Error(err) | ||
23 | + return | ||
24 | + } | ||
25 | + if result, err = auth.CheckSmsCode(user.Phone, request.Captcha, protocol.SmsCode); err != nil { | ||
26 | + log.Error(err) | ||
27 | + return | ||
28 | + } | ||
29 | + if !result { | ||
30 | + err = protocol.NewErrWithMessage(1012) | ||
31 | + } | ||
32 | + return | ||
33 | +} | ||
34 | + | ||
35 | +//修改手机号 | ||
36 | +func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRequest) (rsp *protocol.ChangePhoneResponse, err error) { | ||
37 | + var ( | ||
38 | + user *models.User | ||
39 | + result bool | ||
40 | + ) | ||
41 | + //rsp =&protocol.ChangePhoneResponse{} | ||
42 | + if user, err = repository.User.GetUsersById(header.Uid); err != nil { | ||
43 | + log.Error(err) | ||
44 | + return | ||
45 | + } | ||
46 | + if result, err = auth.CheckSmsCode(user.Phone, request.Captcha, protocol.SmsCode); err != nil { | ||
47 | + log.Error(err) | ||
48 | + return | ||
49 | + } | ||
50 | + if !result { | ||
51 | + err = protocol.NewErrWithMessage(1012) | ||
52 | + } | ||
53 | + err = utils.UpdateTableByMap(&models.User{Id: user.Id}, map[string]interface{}{"Phone": request.Phone}) | ||
54 | + return | ||
55 | +} | ||
56 | + | ||
57 | +//重置密码 | ||
58 | +func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswordRequest) (rsp *protocol.ResetPasswordResponse, err error) { | ||
59 | + var ( | ||
60 | + user *models.User | ||
61 | + ) | ||
62 | + //rsp =&protocol.ResetPasswordResponse{} | ||
63 | + if user, err = repository.User.GetUsersById(header.Uid); err != nil { | ||
64 | + log.Error(err) | ||
65 | + return | ||
66 | + } | ||
67 | + //TODO:未验证 校验码 | ||
68 | + if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) { | ||
69 | + err = protocol.NewErrWithMessage(2026) | ||
70 | + } | ||
71 | + err = utils.UpdateTableByMap(&models.User{Id: user.Id}, map[string]interface{}{"Passwd": request.NewPwd}) | ||
72 | + return | ||
73 | +} | ||
74 | + | ||
75 | +//修改密码 | ||
76 | +func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePasswordRequest) (rsp *protocol.ChangePasswordResponse, err error) { | ||
77 | + var ( | ||
78 | + user *models.User | ||
79 | + ) | ||
80 | + //rsp =&protocol.ChangePasswordResponse{} | ||
81 | + if user, err = repository.User.GetUsersById(header.Uid); err != nil { | ||
82 | + log.Error(err) | ||
83 | + return | ||
84 | + } | ||
85 | + if strings.EqualFold(request.OldPwd, user.Passwd) { | ||
86 | + err = protocol.NewErrWithMessage(1) | ||
87 | + } | ||
88 | + if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) { | ||
89 | + err = protocol.NewErrWithMessage(2026) | ||
90 | + } | ||
91 | + err = utils.UpdateTableByMap(&models.User{Id: user.Id}, map[string]interface{}{"Passwd": request.NewPwd}) | ||
92 | + return | ||
93 | +} |
1 | package tests | 1 | package tests |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "fmt" | ||
4 | "github.com/astaxie/beego" | 5 | "github.com/astaxie/beego" |
5 | _ "github.com/go-sql-driver/mysql" | 6 | _ "github.com/go-sql-driver/mysql" |
6 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/config" | 7 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/config" |
7 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | 8 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" |
8 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/orm" | 9 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/orm" |
9 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/redis" | 10 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/redis" |
10 | - "opp/protocol" | ||
11 | "os" | 11 | "os" |
12 | "path/filepath" | 12 | "path/filepath" |
13 | "runtime" | 13 | "runtime" |
@@ -34,11 +34,18 @@ func Init() { | @@ -34,11 +34,18 @@ func Init() { | ||
34 | log.Fatal(err) | 34 | log.Fatal(err) |
35 | panic(err) | 35 | panic(err) |
36 | } | 36 | } |
37 | + dataSource := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?loc=Asia%%2FShanghai", | ||
38 | + beego.AppConfig.String("mysql_user"), | ||
39 | + beego.AppConfig.String("mysql_password"), | ||
40 | + beego.AppConfig.String("mysql_host"), | ||
41 | + beego.AppConfig.String("mysql_port"), | ||
42 | + beego.AppConfig.String("mysql_db_name"), | ||
43 | + ) | ||
37 | orm.NewBeeormEngine(config.Mysql{ | 44 | orm.NewBeeormEngine(config.Mysql{ |
38 | - DataSource: beego.AppConfig.String("data_source"), | 45 | + DataSource: dataSource, |
39 | MaxIdle: 100, | 46 | MaxIdle: 100, |
40 | MaxOpen: 100, | 47 | MaxOpen: 100, |
41 | }) | 48 | }) |
42 | - protocol.InitMessageCode() | 49 | + //protocol.InitMessageCode() |
43 | }) | 50 | }) |
44 | } | 51 | } |
-
请 注册 或 登录 后发表评论