Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zuiketang
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
zuiketang
Commits
3b38a40b
Commit
3b38a40b
authored
Oct 20, 2016
by
xiabin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加注册的图片验证码
parent
086aae58
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
45 additions
and
88 deletions
+45
-88
main.php
src/frontend/config/main.php
+0
-1
SiteController.php
src/frontend/controllers/SiteController.php
+8
-16
SignupForm.php
src/frontend/models/SignupForm.php
+14
-1
resetPassword.php
src/frontend/views/site/resetPassword.php
+5
-3
signup.php
src/frontend/views/site/signup.php
+11
-6
request_password_reset.js
src/frontend/web/js/site/request_password_reset.js
+3
-1
signup.js
src/frontend/web/js/site/signup.js
+4
-60
No files found.
src/frontend/config/main.php
View file @
3b38a40b
...
@@ -21,7 +21,6 @@ return [
...
@@ -21,7 +21,6 @@ return [
],
],
'assetManager'
=>
[
'assetManager'
=>
[
'appendTimestamp'
=>
TRUE
,
'appendTimestamp'
=>
TRUE
,
//'baseUrl' => 'http://www.baidu.com/',
'bundles'
=>
[
'bundles'
=>
[
'yii\web\JqueryAsset'
=>
FALSE
,
'yii\web\JqueryAsset'
=>
FALSE
,
]
]
...
...
src/frontend/controllers/SiteController.php
View file @
3b38a40b
...
@@ -81,8 +81,13 @@ class SiteController extends Controller
...
@@ -81,8 +81,13 @@ class SiteController extends Controller
],
],
'captcha'
=>
[
'captcha'
=>
[
'class'
=>
'yii\captcha\CaptchaAction'
,
'class'
=>
'yii\captcha\CaptchaAction'
,
'fixedVerifyCode'
=>
YII_ENV_TEST
?
'testme'
:
NULL
,
'fixedVerifyCode'
=>
false
?
'testme'
:
NULL
,
'maxLength'
=>
6
,
'minLength'
=>
6
,
'transparent'
=>
TRUE
,
'padding'
=>
10
,
],
],
];
];
}
}
...
@@ -171,19 +176,7 @@ class SiteController extends Controller
...
@@ -171,19 +176,7 @@ class SiteController extends Controller
if
(
$model
->
load
(
$request
->
post
()))
{
if
(
$model
->
load
(
$request
->
post
()))
{
//token 错误
//token 错误
if
(
$token
.
$telephone
===
Yii
::
$app
->
session
->
get
(
self
::
SIGNUP_TOKEN
))
{
if
(
$token
.
$telephone
===
Yii
::
$app
->
session
->
get
(
self
::
SIGNUP_TOKEN
))
{
$geetestChallenge
=
$request
->
post
(
'geetest_challenge'
);
if
(
$user
=
$model
->
signup
())
{
$geetestSeccode
=
$request
->
post
(
'geetest_seccode'
);
$geetestValidate
=
$request
->
post
(
'geetest_validate'
);
$GtSdk
=
new
Geetest
(
Yii
::
$app
->
params
[
'captchaId'
],
Yii
::
$app
->
params
[
'privateKey'
]);
$user_id
=
Yii
::
$app
->
session
->
get
(
self
::
GT_USER_ID
);
if
(
Yii
::
$app
->
session
->
get
(
self
::
GT_SERVER
)
==
1
)
{
//服务器正常
$gtResult
=
$GtSdk
->
success_validate
(
$geetestChallenge
,
$geetestValidate
,
$geetestSeccode
,
$user_id
);
}
else
{
//服务器宕机,走failback模式
$gtResult
=
$GtSdk
->
fail_validate
(
$geetestChallenge
,
$geetestValidate
,
$geetestSeccode
);
}
if
(
$gtResult
&&
$user
=
$model
->
signup
())
{
//删除短信验证码
//删除短信验证码
Yii
::
$app
->
session
->
remove
(
self
::
SIGNUP_TOKEN
);
Yii
::
$app
->
session
->
remove
(
self
::
SIGNUP_TOKEN
);
if
(
Yii
::
$app
->
getUser
()
->
login
(
$user
))
{
if
(
Yii
::
$app
->
getUser
()
->
login
(
$user
))
{
...
@@ -195,7 +188,6 @@ class SiteController extends Controller
...
@@ -195,7 +188,6 @@ class SiteController extends Controller
}
}
}
}
return
$this
->
render
(
'signup'
,
[
return
$this
->
render
(
'signup'
,
[
'model'
=>
$model
,
'model'
=>
$model
,
]);
]);
...
@@ -356,7 +348,7 @@ class SiteController extends Controller
...
@@ -356,7 +348,7 @@ class SiteController extends Controller
$msg
=
""
;
$msg
=
""
;
}
else
{
}
else
{
$result
=
FALSE
;
$result
=
FALSE
;
$msg
=
'
一分钟只有一次
'
;
$msg
=
'
您发送的太过频繁
'
;
}
}
}
else
{
}
else
{
$result
=
FALSE
;
$result
=
FALSE
;
...
...
src/frontend/models/SignupForm.php
View file @
3b38a40b
...
@@ -20,6 +20,7 @@ class SignupForm extends Model
...
@@ -20,6 +20,7 @@ class SignupForm extends Model
public
$password
;
public
$password
;
public
$rePassword
;
public
$rePassword
;
public
$from
;
public
$from
;
public
$verifyCode
;
/**
/**
* @inheritdoc
* @inheritdoc
...
@@ -35,7 +36,19 @@ class SignupForm extends Model
...
@@ -35,7 +36,19 @@ class SignupForm extends Model
[
'password'
,
'string'
,
'min'
=>
6
],
[
'password'
,
'string'
,
'min'
=>
6
],
[
'rePassword'
,
'string'
,
'min'
=>
6
],
[
'rePassword'
,
'string'
,
'min'
=>
6
],
[
'rePassword'
,
'compare'
,
'compareAttribute'
=>
'rePassword'
],
[
'rePassword'
,
'compare'
,
'compareAttribute'
=>
'rePassword'
],
[
'from'
,
'integer'
]
[
'from'
,
'integer'
],
[
'verifyCode'
,
'required'
],
[
'verifyCode'
,
'captcha'
]
];
}
/**
* @return mixed
*/
public
function
attributeLabels
()
{
return
[
'verifyCode'
=>
''
];
];
}
}
...
...
src/frontend/views/site/resetPassword.php
View file @
3b38a40b
...
@@ -10,8 +10,10 @@ use yii\bootstrap\ActiveForm;
...
@@ -10,8 +10,10 @@ use yii\bootstrap\ActiveForm;
$this
->
title
=
'Reset password'
;
$this
->
title
=
'Reset password'
;
$jsString
=
<<<JS
$jsString
=
<<<JS
$("#submit").click(function() {
$("#submit").unbind().click(function() {
if($("#password").val() !== $("#repassword").val()){
console.log($("#password").val());
console.log($("#repassword").val());
if($("#password").val() != $("#repassword").val()){
$("#repassword_tips").html('两次密码不一致');
$("#repassword_tips").html('两次密码不一致');
return false;
return false;
}
}
...
@@ -47,7 +49,7 @@ $this->registerJs($jsString);
...
@@ -47,7 +49,7 @@ $this->registerJs($jsString);
</div>
</div>
<div
class=
"check-password input-wrapper last-wrapper"
>
<div
class=
"check-password input-wrapper last-wrapper"
>
<input
value=
"
<?=
$model
->
rePassword
?>
"
id
id=
"repassword"
name=
"rePassword"
type=
"password"
class=
""
placeholder=
"重复输入密码"
required=
""
>
<input
value=
"
<?=
$model
->
rePassword
?>
"
id=
"repassword"
name=
"rePassword"
type=
"password"
class=
""
placeholder=
"重复输入密码"
required=
""
>
<span
id=
"repassword_tips"
class=
"tips"
>
<?=
$model
->
getFirstError
(
'rePassword'
)
?>
</span>
<span
id=
"repassword_tips"
class=
"tips"
>
<?=
$model
->
getFirstError
(
'rePassword'
)
?>
</span>
</div>
</div>
</div>
</div>
...
...
src/frontend/views/site/signup.php
View file @
3b38a40b
<?php
<?php
use
yii\captcha\Captcha
;
use
yii\widgets\ActiveForm
;
use
yii\widgets\ActiveForm
;
/* @var $this yii\web\View */
/* @var $this yii\web\View */
...
@@ -50,14 +51,18 @@ $this->registerJsFile('http://static.geetest.com/static/tools/gt.js');
...
@@ -50,14 +51,18 @@ $this->registerJsFile('http://static.geetest.com/static/tools/gt.js');
<span
class=
"tips tip-vcode"
>
<?=
$model
->
getFirstError
(
'rePassword'
)
?>
</span>
<span
class=
"tips tip-vcode"
>
<?=
$model
->
getFirstError
(
'rePassword'
)
?>
</span>
<span
id=
"repassword_tips"
class=
"tips"
>
<?=
$model
->
getFirstError
(
'rePassword'
)
?>
</span>
<span
id=
"repassword_tips"
class=
"tips"
>
<?=
$model
->
getFirstError
(
'rePassword'
)
?>
</span>
</div>
</div>
</div>
<div
class=
"password input-wrapper"
>
<?=
$form
->
field
(
$model
,
'verifyCode'
)
->
widget
(
Captcha
::
className
(),[
'template'
=>
"
{
image
}
"
,
'imageOptions'
=>
[
'alt'
=>
'验证码'
],
'captchaAction'
=>
'site/captcha'
,
])
->
error
(
FALSE
);
?>
<input
id=
"verifyCode"
name=
"verifyCode"
type=
"text"
placeholder=
"输入验证码"
required=
""
>
<span
id=
"verifyCode"
class=
"tips"
>
<?=
$model
->
getFirstError
(
'verifyCode'
)
?>
</span>
<div
class=
"v-geetest"
>
</div>
<div
id=
"embed-captcha"
></div>
<p
id=
"wait"
class=
"show"
>
正在加载验证码......
</p>
<p
id=
"notice"
class=
"hide"
>
请先拖动验证码到相应位置
</p>
</div>
</div>
<div
id=
"submit"
class=
"foot-reg-btn"
>
<div
id=
"submit"
class=
"foot-reg-btn"
>
<button
class=
"btn btn-reg"
type=
"submit"
>
注册
</button>
<button
class=
"btn btn-reg"
type=
"submit"
>
注册
</button>
</div>
</div>
...
...
src/frontend/web/js/site/request_password_reset.js
View file @
3b38a40b
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
* Created by xiabin on 2016/9/26.
* Created by xiabin on 2016/9/26.
*/
*/
var
handlerEmbed
=
function
(
captchaObj
)
{
var
handlerEmbed
=
function
(
captchaObj
)
{
$
(
"#submit"
).
click
(
function
(
e
)
{
$
(
"#submit"
).
unbind
().
click
(
function
(
e
)
{
var
validate
=
captchaObj
.
getValidate
();
var
validate
=
captchaObj
.
getValidate
();
if
(
!
validate
)
{
if
(
!
validate
)
{
$
(
"#notice"
)[
0
].
className
=
"show"
;
$
(
"#notice"
)[
0
].
className
=
"show"
;
...
@@ -10,6 +10,8 @@ var handlerEmbed = function (captchaObj) {
...
@@ -10,6 +10,8 @@ var handlerEmbed = function (captchaObj) {
$
(
"#notice"
)[
0
].
className
=
"hide"
;
$
(
"#notice"
)[
0
].
className
=
"hide"
;
},
2000
);
},
2000
);
return
false
;
return
false
;
}
else
{
$
(
"#request-password-reset-form"
).
submit
();
}
}
});
});
// 将验证码加到id为captcha的元素里,同时会有三个input的值:geetest_challenge, geetest_validate, geetest_seccode
// 将验证码加到id为captcha的元素里,同时会有三个input的值:geetest_challenge, geetest_validate, geetest_seccode
...
...
src/frontend/web/js/site/signup.js
View file @
3b38a40b
var
handlerEmbed
=
function
(
captchaObj
)
{
// $('#verifycode-image').click(function () {
$
(
"#submit"
).
click
(
function
()
{
//
var
validate
=
captchaObj
.
getValidate
();
// $(this).attr('src',__BASE_URL__+'site/captcha?v='+Date.parse(new Date()));
if
(
!
validate
)
{
// });
$
(
"#notice"
)[
0
].
className
=
"show"
;
setTimeout
(
function
()
{
$
(
"#notice"
)[
0
].
className
=
"hide"
;
},
2000
);
return
false
;
}
var
telephone
=
$
(
"#telephone"
).
val
();
if
(
telephone
.
length
===
0
)
{
$
(
'#telephone_tips'
).
html
(
'手机号码不能为空'
);
return
false
;
}
var
token
=
$
(
"#token"
).
val
();
if
(
token
.
length
===
0
)
{
$
(
'#token_tips'
).
html
(
'验证码不能为空'
);
return
false
;
}
var
password
=
$
(
"#password"
).
val
();
if
(
password
.
length
===
0
)
{
$
(
'#password_tips'
).
html
(
'密码不能为空'
);
return
false
;
}
var
repassword
=
$
(
"#repassword"
).
val
();
if
(
repassword
!==
password
)
{
$
(
'#repassword_tips'
).
html
(
'两次密码输入不一致'
);
return
false
;
}
});
// 将验证码加到id为captcha的元素里,同时会有三个input的值:geetest_challenge, geetest_validate, geetest_seccode
captchaObj
.
appendTo
(
"#embed-captcha"
);
captchaObj
.
onReady
(
function
()
{
$
(
"#wait"
)[
0
].
className
=
"hide"
;
});
// 更多接口参考:http://www.geetest.com/install/sections/idx-client-sdk.html
};
$
.
ajax
({
// 获取id,challenge,success(是否启用failback)
url
:
__BASE_URL__
+
"site/start-captcha?type=pc&t="
+
(
new
Date
()).
getTime
(),
// 加随机数防止缓存
type
:
"get"
,
dataType
:
"json"
,
success
:
function
(
data
)
{
// 使用initGeetest接口
// 参数1:配置参数
// 参数2:回调,回调的第一个参数验证码对象,之后可以使用它做appendTo之类的事件
initGeetest
({
gt
:
data
.
gt
,
challenge
:
data
.
challenge
,
product
:
"float"
,
// 产品形式,包括:float,embed,popup。注意只对PC版验证码有效
offline
:
!
data
.
success
// 表示用户后台检测极验服务器是否宕机,一般不需要关注
// 更多配置参数请参见:http://www.geetest.com/install/sections/idx-client-sdk.html#config
},
handlerEmbed
);
}
});
//发送短信呢
//发送短信呢
$
(
'#send_msg'
).
click
(
function
()
{
$
(
'#send_msg'
).
click
(
function
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment