Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
FLIPPED-AURORA
gin-vue-admin
提交
8eae7f18
G
gin-vue-admin
项目概览
FLIPPED-AURORA
/
gin-vue-admin
大约 1 年 前同步成功
通知
344
Star
18155
Fork
5506
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gin-vue-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8eae7f18
编写于
9月 04, 2019
作者:
Mr.奇淼(
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
用户登录注册修改密码接口
上级
b70ab642
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
358 addition
and
48 deletion
+358
-48
QMPlusServer/controller/api/user.go
QMPlusServer/controller/api/user.go
+87
-12
QMPlusServer/docs/docs.go
QMPlusServer/docs/docs.go
+85
-6
QMPlusServer/docs/swagger.json
QMPlusServer/docs/swagger.json
+84
-5
QMPlusServer/docs/swagger.yaml
QMPlusServer/docs/swagger.yaml
+56
-5
QMPlusServer/go.mod
QMPlusServer/go.mod
+1
-0
QMPlusServer/model/dbModel/user.go
QMPlusServer/model/dbModel/user.go
+30
-12
QMPlusServer/model/modelInterface/interface.go
QMPlusServer/model/modelInterface/interface.go
+2
-1
QMPlusServer/router/user.go
QMPlusServer/router/user.go
+2
-0
QMPlusServer/tools/hasGap.go
QMPlusServer/tools/hasGap.go
+11
-7
未找到文件。
QMPlusServer/controller/api/user.go
浏览文件 @
8eae7f18
...
...
@@ -4,25 +4,100 @@ import (
"fmt"
"github.com/gin-gonic/gin"
"main/model/dbModel"
"main/model/modelInterface"
)
type
RegistStuct
struct
{
type
Regist
AndLogin
Stuct
struct
{
UserName
string
`json:"userName"`
PassWord
string
`json:"passWord"`
}
// @Summary 创建用户
// @Produce application/x-www-form-urlencoded
// @Param data body api.RegistStuct true "用户注册接口"
// @Success 200 {string} json "{"code":200,"data":{},"msg":"ok"}"
// @Tags User
// @Summary 用户注册账号
// @Produce application/json
// @Param data body api.RegistAndLoginStuct true "用户注册接口"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"注册成功"}"
// @Router /user/regist [post]
func
Regist
(
c
*
gin
.
Context
)
{
var
R
RegistStuct
var
R
Regist
AndLogin
Stuct
_
=
c
.
BindJSON
(
&
R
)
U
:=
dbModel
.
NewUser
(
dbModel
.
User
{
UserName
:
R
.
UserName
,
PassWord
:
R
.
PassWord
})
var
curd
modelInterface
.
CURD
curd
=
U
err
,
user
:=
curd
.
Create
()
fmt
.
Println
(
err
,
user
)
U
:=
&
dbModel
.
User
{
UserName
:
R
.
UserName
,
PassWord
:
R
.
PassWord
}
err
,
user
:=
U
.
Regist
()
if
err
!=
nil
{
c
.
JSON
(
200
,
gin
.
H
{
"success"
:
false
,
"msg"
:
fmt
.
Sprintf
(
"%v"
,
err
),
"data"
:
gin
.
H
{
"user"
:
user
,
},
})
}
else
{
c
.
JSON
(
200
,
gin
.
H
{
"success"
:
true
,
"msg"
:
"创建成功"
,
"data"
:
gin
.
H
{
"user"
:
user
,
},
})
}
}
// @Tags User
// @Summary 用户登录
// @Produce application/json
// @Param data body api.RegistAndLoginStuct true "用户登录接口"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"登陆成功"}"
// @Router /user/login [post]
func
Login
(
c
*
gin
.
Context
)
{
var
L
RegistAndLoginStuct
_
=
c
.
BindJSON
(
&
L
)
U
:=
&
dbModel
.
User
{
UserName
:
L
.
UserName
,
PassWord
:
L
.
PassWord
}
if
err
,
user
:=
U
.
Login
();
err
!=
nil
{
c
.
JSON
(
200
,
gin
.
H
{
"success"
:
false
,
"msg"
:
"用户名密码错误"
,
"data"
:
gin
.
H
{
"user"
:
user
,
},
})
}
else
{
c
.
JSON
(
200
,
gin
.
H
{
"success"
:
true
,
"msg"
:
"登录成功"
,
"data"
:
gin
.
H
{
"user"
:
user
,
},
})
}
}
type
ChangePassWordStutrc
struct
{
UserName
string
`json:"userName"`
PassWord
string
`json:"passWord"`
NewPassWord
string
`json:"newPassWord"`
}
// @Tags User
// @Summary 用户修改密码
// @Produce application/json
// @Param data body api.ChangePassWordStutrc true "用户修改密码"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"修改成功"}"
// @Router /user/changePassWord [post]
func
ChangePassWord
(
c
*
gin
.
Context
)
{
var
params
ChangePassWordStutrc
_
=
c
.
BindJSON
(
&
params
)
U
:=
&
dbModel
.
User
{
UserName
:
params
.
UserName
,
PassWord
:
params
.
PassWord
}
if
err
,
_
:=
U
.
ChangePassWord
(
params
.
NewPassWord
);
err
!=
nil
{
c
.
JSON
(
200
,
gin
.
H
{
"success"
:
false
,
"msg"
:
"修改失败,请检查用户名密码"
,
"data"
:
gin
.
H
{},
})
}
else
{
c
.
JSON
(
200
,
gin
.
H
{
"success"
:
true
,
"msg"
:
"修改成功"
,
"data"
:
gin
.
H
{},
})
}
}
QMPlusServer/docs/docs.go
浏览文件 @
8eae7f18
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at
// 2019-09-03
14:28:38.1089338 +0800 CST m=+0.0378992
01
// 2019-09-03
23:59:41.1295277 +0800 CST m=+0.0383629
01
package
docs
...
...
@@ -26,12 +26,77 @@ var doc = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/user/changePassWord": {
"post": {
"produces": [
"application/json"
],
"tags": [
"User"
],
"summary": "用户修改密码",
"parameters": [
{
"description": "用户修改密码",
"name": "data",
"in": "body",
"required": true,
"schema": {
"type": "object",
"$ref": "#/definitions/api.ChangePassWordStutrc"
}
}
],
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"修改成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/user/login": {
"post": {
"produces": [
"application/json"
],
"tags": [
"User"
],
"summary": "用户登录",
"parameters": [
{
"description": "用户登录接口",
"name": "data",
"in": "body",
"required": true,
"schema": {
"type": "object",
"$ref": "#/definitions/api.RegistAndLoginStuct"
}
}
],
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"登陆成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/user/regist": {
"post": {
"produces": [
"application/x-www-form-urlencoded"
"application/json"
],
"tags": [
"User"
],
"summary": "
创建用户
",
"summary": "
用户注册账号
",
"parameters": [
{
"description": "用户注册接口",
...
...
@@ -40,13 +105,13 @@ var doc = `{
"required": true,
"schema": {
"type": "object",
"$ref": "#/definitions/api.RegistStuct"
"$ref": "#/definitions/api.Regist
AndLogin
Stuct"
}
}
],
"responses": {
"200": {
"description": "{\"
code\":200,\"data\":{},\"msg\":\"ok
\"}",
"description": "{\"
success\":true,\"data\":{},\"msg\":\"注册成功
\"}",
"schema": {
"type": "string"
}
...
...
@@ -56,7 +121,21 @@ var doc = `{
}
},
"definitions": {
"api.RegistStuct": {
"api.ChangePassWordStutrc": {
"type": "object",
"properties": {
"newPassWord": {
"type": "string"
},
"passWord": {
"type": "string"
},
"userName": {
"type": "string"
}
}
},
"api.RegistAndLoginStuct": {
"type": "object",
"properties": {
"passWord": {
...
...
QMPlusServer/docs/swagger.json
浏览文件 @
8eae7f18
...
...
@@ -5,12 +5,77 @@
"license"
:
{}
},
"paths"
:
{
"/user/changePassWord"
:
{
"post"
:
{
"produces"
:
[
"application/json"
],
"tags"
:
[
"User"
],
"summary"
:
"用户修改密码"
,
"parameters"
:
[
{
"description"
:
"用户修改密码"
,
"name"
:
"data"
,
"in"
:
"body"
,
"required"
:
true
,
"schema"
:
{
"type"
:
"object"
,
"$ref"
:
"#/definitions/api.ChangePassWordStutrc"
}
}
],
"responses"
:
{
"200"
:
{
"description"
:
"{
\"
success
\"
:true,
\"
data
\"
:{},
\"
msg
\"
:
\"
修改成功
\"
}"
,
"schema"
:
{
"type"
:
"string"
}
}
}
}
},
"/user/login"
:
{
"post"
:
{
"produces"
:
[
"application/json"
],
"tags"
:
[
"User"
],
"summary"
:
"用户登录"
,
"parameters"
:
[
{
"description"
:
"用户登录接口"
,
"name"
:
"data"
,
"in"
:
"body"
,
"required"
:
true
,
"schema"
:
{
"type"
:
"object"
,
"$ref"
:
"#/definitions/api.RegistAndLoginStuct"
}
}
],
"responses"
:
{
"200"
:
{
"description"
:
"{
\"
success
\"
:true,
\"
data
\"
:{},
\"
msg
\"
:
\"
登陆成功
\"
}"
,
"schema"
:
{
"type"
:
"string"
}
}
}
}
},
"/user/regist"
:
{
"post"
:
{
"produces"
:
[
"application/x-www-form-urlencoded"
"application/json"
],
"tags"
:
[
"User"
],
"summary"
:
"
创建用户
"
,
"summary"
:
"
用户注册账号
"
,
"parameters"
:
[
{
"description"
:
"用户注册接口"
,
...
...
@@ -19,13 +84,13 @@
"required"
:
true
,
"schema"
:
{
"type"
:
"object"
,
"$ref"
:
"#/definitions/api.RegistStuct"
"$ref"
:
"#/definitions/api.Regist
AndLogin
Stuct"
}
}
],
"responses"
:
{
"200"
:
{
"description"
:
"{
\"
code
\"
:200,
\"
data
\"
:{},
\"
msg
\"
:
\"
ok
\"
}"
,
"description"
:
"{
\"
success
\"
:true,
\"
data
\"
:{},
\"
msg
\"
:
\"
注册成功
\"
}"
,
"schema"
:
{
"type"
:
"string"
}
...
...
@@ -35,7 +100,21 @@
}
},
"definitions"
:
{
"api.RegistStuct"
:
{
"api.ChangePassWordStutrc"
:
{
"type"
:
"object"
,
"properties"
:
{
"newPassWord"
:
{
"type"
:
"string"
},
"passWord"
:
{
"type"
:
"string"
},
"userName"
:
{
"type"
:
"string"
}
}
},
"api.RegistAndLoginStuct"
:
{
"type"
:
"object"
,
"properties"
:
{
"passWord"
:
{
...
...
QMPlusServer/docs/swagger.yaml
浏览文件 @
8eae7f18
definitions
:
api.RegistStuct
:
api.ChangePassWordStutrc
:
properties
:
newPassWord
:
type
:
string
passWord
:
type
:
string
userName
:
type
:
string
type
:
object
api.RegistAndLoginStuct
:
properties
:
passWord
:
type
:
string
...
...
@@ -10,6 +19,46 @@ info:
contact
:
{}
license
:
{}
paths
:
/user/changePassWord
:
post
:
parameters
:
-
description
:
用户修改密码
in
:
body
name
:
data
required
:
true
schema
:
$ref
:
'
#/definitions/api.ChangePassWordStutrc'
type
:
object
produces
:
-
application/json
responses
:
"
200"
:
description
:
'
{"success":true,"data":{},"msg":"修改成功"}'
schema
:
type
:
string
summary
:
用户修改密码
tags
:
-
User
/user/login
:
post
:
parameters
:
-
description
:
用户登录接口
in
:
body
name
:
data
required
:
true
schema
:
$ref
:
'
#/definitions/api.RegistAndLoginStuct'
type
:
object
produces
:
-
application/json
responses
:
"
200"
:
description
:
'
{"success":true,"data":{},"msg":"登陆成功"}'
schema
:
type
:
string
summary
:
用户登录
tags
:
-
User
/user/regist
:
post
:
parameters
:
...
...
@@ -18,14 +67,16 @@ paths:
name
:
data
required
:
true
schema
:
$ref
:
'
#/definitions/api.RegistStuct'
$ref
:
'
#/definitions/api.Regist
AndLogin
Stuct'
type
:
object
produces
:
-
application/
x-www-form-urlencoded
-
application/
json
responses
:
"
200"
:
description
:
'
{"
code":200,"data":{},"msg":"ok
"}'
description
:
'
{"
success":true,"data":{},"msg":"注册成功
"}'
schema
:
type
:
string
summary
:
创建用户
summary
:
用户注册账号
tags
:
-
User
swagger
:
"
2.0"
QMPlusServer/go.mod
浏览文件 @
8eae7f18
...
...
@@ -13,6 +13,7 @@ require (
github.com/lestrrat/go-envload v0.0.0-20180220120943-6ed08b54a570 // indirect
github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f
github.com/lestrrat/go-strftime v0.0.0-20180220042222-ba3bf9c1d042 // indirect
github.com/pkg/errors v0.8.1
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
github.com/satori/go.uuid v1.2.0
github.com/sirupsen/logrus v1.2.0
...
...
QMPlusServer/model/dbModel/user.go
浏览文件 @
8eae7f18
...
...
@@ -2,9 +2,10 @@ package dbModel
import
(
"github.com/jinzhu/gorm"
"github.com/pkg/errors"
uuid
"github.com/satori/go.uuid"
"main/init/mysql"
"main/
model/modelInterface
"
"main/
tools
"
)
type
User
struct
{
...
...
@@ -21,26 +22,43 @@ type User struct {
//type Propertie struct {
// gorm.Model
//}
func
NewUser
(
user
User
)
*
User
{
return
&
User
{
UserName
:
user
.
UserName
,
PassWord
:
user
.
PassWord
,
NickName
:
user
.
NickName
,
HeaderImg
:
user
.
HeaderImg
}
}
func
(
u
*
User
)
Create
()
(
err
error
,
user
modelInterface
.
CURD
)
{
//注册接口model方法
func
(
u
*
User
)
Regist
()
(
err
error
,
userInter
*
User
)
{
var
user
User
//判断用户名是否注册
findErr
:=
mysql
.
DEFAULTDB
.
Where
(
"user_name = ?"
,
u
.
UserName
)
.
First
(
&
user
)
.
Error
//err为nil表明读取到了 不能注册
if
findErr
==
nil
{
return
errors
.
New
(
"用户名已注册"
),
nil
}
else
{
// 否则 附加uuid 密码md5简单加密 注册
u
.
PassWord
=
tools
.
MD5V
(
u
.
PassWord
)
u
.
UUID
=
uuid
.
NewV4
()
err
=
mysql
.
DEFAULTDB
.
Create
(
u
)
.
Error
}
return
err
,
u
}
func
(
u
*
User
)
Delete
()
(
err
error
,
user
modelInterface
.
CURD
)
{
err
=
mysql
.
DEFAULTDB
.
Create
(
u
)
.
Error
//修改用户密码
func
(
u
*
User
)
ChangePassWord
(
newPassWord
string
)
(
err
error
,
userInter
*
User
)
{
var
user
User
//后期修改jwt+password模式
u
.
PassWord
=
tools
.
MD5V
(
u
.
PassWord
)
err
=
mysql
.
DEFAULTDB
.
Where
(
"user_name = ? AND pass_word = ?"
,
u
.
UserName
,
u
.
PassWord
)
.
First
(
&
user
)
.
Update
(
"pass_word"
,
tools
.
MD5V
(
newPassWord
))
.
Error
return
err
,
u
}
func
(
u
*
User
)
Updata
()
(
err
error
,
user
modelInterface
.
CURD
)
{
//用户更新接口
func
(
u
*
User
)
UpdataUser
()
(
err
error
,
userInter
*
User
)
{
err
=
mysql
.
DEFAULTDB
.
Create
(
u
)
.
Error
return
err
,
u
}
func
(
u
*
User
)
Read
()
(
err
error
,
user
modelInterface
.
CURD
)
{
err
=
mysql
.
DEFAULTDB
.
Create
(
u
)
.
Error
return
err
,
u
//用户登录
func
(
u
*
User
)
Login
()
(
err
error
,
userInter
*
User
)
{
var
user
User
u
.
PassWord
=
tools
.
MD5V
(
u
.
PassWord
)
err
=
mysql
.
DEFAULTDB
.
Where
(
"user_name = ? AND pass_word = ?"
,
u
.
UserName
,
u
.
PassWord
)
.
First
(
&
user
)
.
Error
return
err
,
&
user
}
QMPlusServer/model/modelInterface/interface.go
浏览文件 @
8eae7f18
package
modelInterface
// 因为我也不确定项目要不要多人维护 所以定义了CURD接口 凡是对数据库进行简单CURD操作 请实现此接口 默认首位返回 error
// 因为我也不确定项目要不要多人维护 所以定义了CURD接口 作为接口参考
// 由于很多接口使用Restful模式 暂时不用泛型 有需要可以iss提供示例
type
CURD
interface
{
Create
()
(
error
,
CURD
)
Updata
()
(
error
,
CURD
)
...
...
QMPlusServer/router/user.go
浏览文件 @
8eae7f18
...
...
@@ -9,5 +9,7 @@ func InitUserRouter(Router *gin.Engine) {
UserRouter
:=
Router
.
Group
(
"user"
)
{
UserRouter
.
POST
(
"regist"
,
api
.
Regist
)
UserRouter
.
POST
(
"login"
,
api
.
Login
)
UserRouter
.
POST
(
"changePassWord"
,
api
.
ChangePassWord
)
}
}
QMPlusServer/tools/hasGap.go
浏览文件 @
8eae7f18
...
...
@@ -10,19 +10,23 @@ import (
func
HasGap
(
input
interface
{})
error
{
getType
:=
reflect
.
TypeOf
(
input
)
fmt
.
Println
(
"获取类型 :"
,
getType
.
Name
())
getValue
:=
reflect
.
ValueOf
(
input
)
fmt
.
Println
(
"所有字段"
,
getValue
)
// 获取方法字段
for
i
:=
0
;
i
<
getType
.
NumField
();
i
++
{
field
:=
getType
.
Field
(
i
)
value
:=
getValue
.
Field
(
i
)
.
Interface
()
fmt
.
Printf
(
"%s: %v = %v
\n
"
,
field
.
Name
,
field
.
Type
,
value
)
switch
value
.
(
type
)
{
case
string
:
if
value
==
""
{
fmt
.
Printf
(
"%s为空"
,
field
.
Name
)
return
errors
.
New
(
fmt
.
Sprintf
(
"%s为空"
,
field
.
Name
))
}
default
:
if
value
==
nil
{
fmt
.
Printf
(
"%s为空"
,
field
.
Name
)
return
errors
.
New
(
fmt
.
Sprintf
(
"%s为空"
,
field
.
Name
))
}
}
}
// 获取方法
// 1. 先获取interface的reflect.Type,然后通过.NumMethod进行遍历
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录