Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
FLIPPED-AURORA
gin-vue-admin
提交
2160b283
G
gin-vue-admin
项目概览
FLIPPED-AURORA
/
gin-vue-admin
大约 1 年 前同步成功
通知
333
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,发现更多精彩内容 >>
提交
2160b283
编写于
6月 20, 2020
作者:
Mr.奇淼(
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
二维码模式更换
上级
6ff5cfe5
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
22 addition
and
80 deletion
+22
-80
server/api/v1/sys_captcha.go
server/api/v1/sys_captcha.go
+17
-19
server/api/v1/sys_user.go
server/api/v1/sys_user.go
+1
-2
server/go.mod
server/go.mod
+1
-0
server/router/sys_base.go
server/router/sys_base.go
+0
-1
server/utils/captcha.go
server/utils/captcha.go
+0
-55
web/src/view/login/login.vue
web/src/view/login/login.vue
+3
-3
未找到文件。
server/api/v1/sys_captcha.go
浏览文件 @
2160b283
package
v1
import
(
"
gin-vue-admin/global
"
"
fmt
"
"gin-vue-admin/global/response"
resp
"gin-vue-admin/model/response"
"gin-vue-admin/utils"
"github.com/dchest/captcha"
"github.com/gin-gonic/gin"
"github.com/mojocn/base64Captcha"
)
var
store
=
base64Captcha
.
DefaultMemStore
// @Tags base
// @Summary 生成验证码
// @Security ApiKeyAuth
...
...
@@ -17,20 +18,17 @@ import (
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /base/captcha [post]
func
Captcha
(
c
*
gin
.
Context
)
{
captchaId
:=
captcha
.
NewLen
(
global
.
GVA_CONFIG
.
Captcha
.
KeyLong
)
response
.
OkDetailed
(
resp
.
SysCaptchaResponse
{
CaptchaId
:
captchaId
,
PicPath
:
"/base/captcha/"
+
captchaId
+
".png"
,
},
"验证码获取成功"
,
c
)
}
// @Tags base
// @Summary 生成验证码图片路径
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /base/captcha/:captchaId [get]
func
CaptchaImg
(
c
*
gin
.
Context
)
{
utils
.
GinCaptchaServeHTTP
(
c
.
Writer
,
c
.
Request
)
//字符,公式,验证码配置
// 生成默认数字的driver
driver
:=
base64Captcha
.
NewDriverDigit
(
80
,
240
,
5
,
0.7
,
80
)
cp
:=
base64Captcha
.
NewCaptcha
(
driver
,
store
)
id
,
b64s
,
err
:=
cp
.
Generate
()
if
err
!=
nil
{
response
.
FailWithMessage
(
fmt
.
Sprintf
(
"获取数据失败,%v"
,
err
),
c
)
}
else
{
response
.
OkDetailed
(
resp
.
SysCaptchaResponse
{
CaptchaId
:
id
,
PicPath
:
b64s
,
},
"验证码获取成功"
,
c
)
}
}
server/api/v1/sys_user.go
浏览文件 @
2160b283
...
...
@@ -10,7 +10,6 @@ import (
resp
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/dchest/captcha"
"github.com/dgrijalva/jwt-go"
"github.com/gin-gonic/gin"
"github.com/go-redis/redis"
...
...
@@ -67,7 +66,7 @@ func Login(c *gin.Context) {
response
.
FailWithMessage
(
UserVerifyErr
.
Error
(),
c
)
return
}
if
captcha
.
VerifyString
(
L
.
CaptchaId
,
L
.
Captcha
)
{
if
store
.
Verify
(
L
.
CaptchaId
,
L
.
Captcha
,
true
)
{
U
:=
&
model
.
SysUser
{
Username
:
L
.
Username
,
Password
:
L
.
Password
}
if
err
,
user
:=
service
.
Login
(
U
);
err
!=
nil
{
response
.
FailWithMessage
(
fmt
.
Sprintf
(
"用户名密码错误或%v"
,
err
),
c
)
...
...
server/go.mod
浏览文件 @
2160b283
...
...
@@ -26,6 +26,7 @@ require (
github.com/lib/pq v1.3.0 // indirect
github.com/mailru/easyjson v0.7.1 // indirect
github.com/mitchellh/mapstructure v1.2.2 // indirect
github.com/mojocn/base64Captcha v1.3.1
github.com/onsi/ginkgo v1.7.0 // indirect
github.com/onsi/gomega v1.4.3 // indirect
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
...
...
server/router/sys_base.go
浏览文件 @
2160b283
...
...
@@ -11,7 +11,6 @@ func InitBaseRouter(Router *gin.RouterGroup) (R gin.IRoutes) {
BaseRouter
.
POST
(
"register"
,
v1
.
Register
)
BaseRouter
.
POST
(
"login"
,
v1
.
Login
)
BaseRouter
.
POST
(
"captcha"
,
v1
.
Captcha
)
BaseRouter
.
GET
(
"captcha/:captchaId"
,
v1
.
CaptchaImg
)
}
return
BaseRouter
}
server/utils/captcha.go
已删除
100644 → 0
浏览文件 @
6ff5cfe5
package
utils
import
(
"bytes"
"fmt"
"gin-vue-admin/global"
"github.com/dchest/captcha"
"net/http"
"path"
"strings"
"time"
)
// 这里需要自行实现captcha 的gin模式
func
GinCaptchaServeHTTP
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
dir
,
file
:=
path
.
Split
(
r
.
URL
.
Path
)
ext
:=
path
.
Ext
(
file
)
id
:=
file
[
:
len
(
file
)
-
len
(
ext
)]
if
ext
==
""
||
id
==
""
{
http
.
NotFound
(
w
,
r
)
return
}
fmt
.
Println
(
"reload : "
+
r
.
FormValue
(
"reload"
))
if
r
.
FormValue
(
"reload"
)
!=
""
{
captcha
.
Reload
(
id
)
}
lang
:=
strings
.
ToLower
(
r
.
FormValue
(
"lang"
))
download
:=
path
.
Base
(
dir
)
==
"download"
if
Serve
(
w
,
r
,
id
,
ext
,
lang
,
download
,
global
.
GVA_CONFIG
.
Captcha
.
ImgWidth
,
global
.
GVA_CONFIG
.
Captcha
.
ImgHeight
)
==
captcha
.
ErrNotFound
{
http
.
NotFound
(
w
,
r
)
}
}
func
Serve
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
id
,
ext
,
lang
string
,
download
bool
,
width
,
height
int
)
error
{
w
.
Header
()
.
Set
(
"Cache-Control"
,
"no-cache, no-store, must-revalidate"
)
w
.
Header
()
.
Set
(
"Pragma"
,
"no-cache"
)
w
.
Header
()
.
Set
(
"Expires"
,
"0"
)
var
content
bytes
.
Buffer
switch
ext
{
case
".png"
:
w
.
Header
()
.
Set
(
"Content-Type"
,
"image/png"
)
_
=
captcha
.
WriteImage
(
&
content
,
id
,
width
,
height
)
case
".wav"
:
w
.
Header
()
.
Set
(
"Content-Type"
,
"audio/x-wav"
)
_
=
captcha
.
WriteAudio
(
&
content
,
id
,
lang
)
default
:
return
captcha
.
ErrNotFound
}
if
download
{
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/octet-stream"
)
}
http
.
ServeContent
(
w
,
r
,
id
+
ext
,
time
.
Time
{},
bytes
.
NewReader
(
content
.
Bytes
()))
return
nil
}
web/src/view/login/login.vue
浏览文件 @
2160b283
...
...
@@ -52,7 +52,9 @@
<div
class=
"vPic"
>
<img
v-if=
"picPath"
:src=
"path + picPath"
:src=
"picPath"
width=
"100%"
height=
"100%"
alt=
"请输入验证码"
@
click=
"loginVefify()"
/>
...
...
@@ -92,7 +94,6 @@
<
script
>
import
{
mapActions
}
from
"
vuex
"
;
import
{
captcha
}
from
"
@/api/user
"
;
const
path
=
process
.
env
.
VUE_APP_BASE_API
;
export
default
{
name
:
"
Login
"
,
data
()
{
...
...
@@ -123,7 +124,6 @@ export default {
username
:
[{
validator
:
checkUsername
,
trigger
:
"
blur
"
}],
password
:
[{
validator
:
checkPassword
,
trigger
:
"
blur
"
}],
},
path
:
path
,
logVerify
:
""
,
picPath
:
""
,
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录