Commit a8eab4d4 authored by xiabin's avatar xiabin

添加登录注册

parent 0d02bb7a
......@@ -5,8 +5,9 @@ return [
'user.passwordResetTokenExpire' => 3600,
'captchaId' => '4d6ad870bf63a30be3d22c92925b04ca',
'privateKey' => 'a2ca5e5139d1f43ac4e1cd248f3e52e4',
'msg.host' => 'http://120.55.242.177/OpenPlatform/OpenApi',
'msg.ac' => '1001@800123450001',
'msg.authkey' => '0E9AEFC25E6A4816E7832755BC5CCA61',
'msg.cgid' => '222'
'msg.host' => 'http://114.55.132.75:7893/sms.aspx',
'msg.userid' => '78',
'msg.account' => '276147613x',
'msg.password' => '276147613',
'msg.signature' => '【最课堂】'
];
......@@ -10,8 +10,8 @@ class Geetest
{
const GT_SDK_VERSION = 'php_3.2.0';
public static $connectTimeout = 1;
public static $socketTimeout = 1;
public static $connectTimeout = 10;
public static $socketTimeout = 10;
private $response;
......
......@@ -28,10 +28,10 @@ class Message
$params = Yii::$app->params;
$this->hosts = $params['msg.host'];
$this->query = [
'action' => 'sendOnce',
'ac' => $params['msg.ac'],
'authkey' => $params['msg.authkey'],
'cgid' => $params['msg.cgid'],
'action' => 'send',
'userid' => $params['msg.userid'],
'account' => $params['msg.account'],
'password' => $params['msg.password'],
];
$this->httpClient = new Client();
}
......@@ -47,11 +47,13 @@ class Message
if (is_array($telephones)) {
$telephones = implode(',', $telephones);
}
$this->query['m'] = $telephones;
$this->query['c'] = $content;
$content .= ' ' . Yii::$app->params['msg.signature'];
$this->query['mobile'] = $telephones;
$this->query['content'] = $content;
return FALSE;
try {
$response = $this->httpClient->request('GET', $this->hosts, [
'query' => $this->query
'form_params' => $this->query
]);
} catch (ClientException $e) {
$response = $e->getResponse();
......@@ -59,14 +61,10 @@ class Message
throw $e;
Yii::getLogger()->log($e, Logger::LEVEL_ERROR, 'Message');
}
$return = new \SimpleXMLElement($response->getBody()->getContents());
if ((int)$return['result'] !== 1) {
Yii::getLogger()->log($return['result'], Logger::LEVEL_ERROR, 'Message');
if ((string)$return->returnstatus !== 'Success') {
Yii::getLogger()->log((string)$return->message, Logger::LEVEL_ERROR, 'Message');
}
}
......
......@@ -47,7 +47,7 @@ class Utils
* @param int $length
* @return int
*/
public function randomNumber($length = 6)
public static function randomNumber($length = 6)
{
if ($length < 4 or $length > 6) {
$length = 6;
......@@ -70,4 +70,18 @@ class Utils
return mt_rand($min, $max);
}
/**
* 判断是否为手机号码
* @param $telephone
* @return bool
*/
public static function isTelephone($telephone)
{
if (preg_match('/^1[34578]{1}\d{9}$/', $telephone)) {
return TRUE;
} else {
return FALSE;
}
}
}
\ No newline at end of file
<?php
return [
'adminEmail' => 'admin@example.com'
'adminEmail' => 'admin@example.com',
'signup.msg' => '您正在注册最课堂,验证码: xxxxxx,2小时内有效',
'resetpassword.msg' => '您正在找回密码,验证码: xxxxxx,2小时内有效',
];
......@@ -2,6 +2,7 @@
namespace frontend\controllers;
use common\libs\Geetest;
use common\libs\Message;
use common\libs\Utils;
use common\models\User;
use frontend\models\TokenInputForm;
......@@ -171,7 +172,9 @@ class SiteController extends Controller
$from = $request->get('from', 0);
$from = HtmlPurifier::process($from);
$model->from = (int)$from;
if ($model->load($request->post())) {
$token = $request->post('token');
$telephone = $request->post('telephone');
if ($model->load($request->post()) && $token . $telephone === Yii::$app->session->get(self::SIGNUP_TOKEN)) {
$geetestChallenge = $request->post('geetest_challenge');
$geetestSeccode = $request->post('geetest_seccode');
$geetestValidate = $request->post('geetest_validate');
......@@ -185,6 +188,8 @@ class SiteController extends Controller
$gtResult = $GtSdk->fail_validate($geetestChallenge, $geetestValidate, $geetestSeccode);
}
if ($gtResult && $user = $model->signup()) {
//删除短信验证码
Yii::$app->session->remove(self::SIGNUP_TOKEN);
if (Yii::$app->getUser()->login($user)) {
return $this->goHome();
}
......@@ -259,8 +264,7 @@ class SiteController extends Controller
* Resets password.
* @return mixed
*/
public
function actionResetPassword()
public function actionResetPassword()
{
if (!Yii::$app->session->has(self::RESET_PASSWORD_SECOND)) {
$this->redirect('request-password-reset');
......@@ -295,8 +299,7 @@ class SiteController extends Controller
* 极验证开始
* ajax
*/
public
function actionStartCaptcha()
public function actionStartCaptcha()
{
if (Yii::$app->request->isAjax) {
$type = Yii::$app->request->get('type');
......@@ -323,18 +326,28 @@ class SiteController extends Controller
public function actionSendSignupMsg()
{
if (TRUE || Yii::$app->request->isAjax) {
$key = self::REDIS_SIGNUP_MSG_PREFIX . '::' . Utils::getRealIP();
$redis = Yii::$app->redis;
$value = $redis->get($key);
if ($value === NULL) {
//sendMsg
$redis->setex($key, self::REDIS_SIGNUP_MSG_EXPIRE, 1);
$result = TRUE;
$msg = "";
$telephone = trim(Yii::$app->request->get('telephone'));
if (Utils::isTelephone($telephone)) {
$key = self::REDIS_SIGNUP_MSG_PREFIX . '::' . Utils::getRealIP();
$redis = Yii::$app->redis;
$value = $redis->get($key);
if ($value === NULL) {
$token = (string)Utils::randomNumber();
Yii::$app->session->set(self::SIGNUP_TOKEN, $token . $telephone);
$messgae = new Message();
$messgae->send($telephone, str_replace('xxxxxx', $token, Yii::$app->params['signup.msg']));
$redis->setex($key, self::REDIS_SIGNUP_MSG_EXPIRE, 1);
$result = TRUE;
$msg = "";
} else {
$result = FALSE;
$msg = '一分钟只有一次';
}
} else {
$result = FALSE;
$msg = '一分钟只有一次';
$msg = '手机格式不正确';
}
Utils::ajaxResponse($result, $msg);
} else {
throw new \yii\web\ForbiddenHttpException('非法请求');
......
......@@ -41,7 +41,7 @@ class UserCenterController extends Controller
public function actionTest()
{
$message = new Message();
$result = $message->send('15395081586','xiabin');
$result = $message->send('15395081586','xia12312321313213bin');
}
public function actionIndex()
......
<?php
namespace frontend\models;
use common\libs\Message;
use common\libs\SendMsg;
use Yii;
use yii\base\Model;
......@@ -53,8 +54,11 @@ class PasswordResetRequestForm extends Model
}
}
//存储发送的手机号码
$message = new Message();
$token = explode('_', $user->password_reset_token);
$token = $token[0];
$message->send($user->telephone, str_replace('xxxxxx', $token, Yii::$app->params['resetpassword.msg']));
//send_msg
return TRUE;
}
......
......@@ -32,8 +32,8 @@ $this->registerJsFile('http://static.geetest.com/static/tools/gt.js');
<label class="control-label" for="token">Token</label>
<input type="text" class="form-control" id="token">
<button class=""> send msg</button>
<input name="token" type="text" class="form-control" id="token">
<button id="send_msg" class=""> send msg</button>
<div style="margin-top: 20px;margin-bottom: 20px">
<div id="embed-captcha"></div>
......
/index.php
/index-test.php
/js/node_modules/
\ No newline at end of file
This diff is collapsed.
......@@ -51,7 +51,7 @@ webpackJsonp([1],[
});
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4)))
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(3)))
/***/ }
]);
\ No newline at end of file
webpackJsonp([2],[
/* 0 */
webpackJsonp([2],{
/***/ 0:
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(3);
module.exports = __webpack_require__(6);
/***/ },
/* 1 */,
/* 2 */,
/* 3 */
/***/ 6:
/***/ function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function($) {var handlerEmbed = function (captchaObj) {
......@@ -22,7 +22,7 @@ webpackJsonp([2],[
e.preventDefault();
}
});
// 将验证码加到id为captcha的元素里,同时会有三个input的值:geetest_challenge, geetest_validate, geetest_seccode
// 将验证码加到id为captcha的元素里,同时会有三个input的值:geetest_challenge, geetest_validate, geetest_seccode
captchaObj.appendTo("#embed-captcha");
captchaObj.onReady(function () {
$("#wait")[0].className = "hide";
......@@ -47,7 +47,29 @@ webpackJsonp([2],[
}, handlerEmbed);
}
});
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4)))
//发送短信呢
$('#send_msg').click(function () {
var telephone = $('#telephone').val();
$.ajax({
// 获取id,challenge,success(是否启用failback)
url: ("http://dev.zuiketang.com/") + "site/send-signup-msg?telephone=" + telephone, // 加随机数防止缓存
type: "get",
dataType: "json",
success: function (data) {
if (data.status === false) {
layer.alert(data.message, {'icon': 2, 'title': '提示'});
} else {
layer.alert('短信发送成功', {'icon': 1, 'title': '提示'})
}
}
}).error(function () {
layer.alert('发送短信服务出错', {'icon': 2, 'title': '提示'})
});
return false;
});
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(3)))
/***/ }
]);
\ No newline at end of file
});
\ No newline at end of file
......@@ -9,7 +9,7 @@ var handlerEmbed = function (captchaObj) {
e.preventDefault();
}
});
// 将验证码加到id为captcha的元素里,同时会有三个input的值:geetest_challenge, geetest_validate, geetest_seccode
// 将验证码加到id为captcha的元素里,同时会有三个input的值:geetest_challenge, geetest_validate, geetest_seccode
captchaObj.appendTo("#embed-captcha");
captchaObj.onReady(function () {
$("#wait")[0].className = "hide";
......@@ -33,4 +33,25 @@ $.ajax({
// 更多配置参数请参见:http://www.geetest.com/install/sections/idx-client-sdk.html#config
}, handlerEmbed);
}
});
//发送短信呢
$('#send_msg').click(function () {
var telephone = $('#telephone').val();
$.ajax({
// 获取id,challenge,success(是否启用failback)
url: __BASE_URL__ + "site/send-signup-msg?telephone=" + telephone, // 加随机数防止缓存
type: "get",
dataType: "json",
success: function (data) {
if (data.status === false) {
layer.alert(data.message, {'icon': 2, 'title': '提示'});
} else {
layer.alert('短信发送成功', {'icon': 1, 'title': '提示'})
}
}
}).error(function () {
layer.alert('发送短信服务出错', {'icon': 2, 'title': '提示'})
});
return false;
});
\ No newline at end of file
/**
* Created by xiabin on 2016/9/27.
*/
var layer = require('layer-js');
layer.config({
path: __CDN_URL__ + 'assets/layer/2.4/', //layer.js所在的目录,可以是绝对目录,也可以是相对目录
extend: ['extend/layer.ext.js']
});
module.exports = layer;
\ No newline at end of file
......@@ -2,17 +2,17 @@ var webpack = require('webpack');
var css_dir = __dirname + '/css';
var img_dir = __dirname + '/img';
var js_dir = __dirname + '/js';
var lib_dir = js_dir + '/lib';
var lib_dir = js_dir + '/libs';
var CommonsChunkPlugin = require("webpack/lib/optimize/CommonsChunkPlugin");
var path = require('path');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var entry = {
vendor: ["jquery", "vue"],
vendor: ["jquery", "vue", js_dir + "/utils/layer"],
signup: [js_dir + '/site/signup.js'],
login: [js_dir + '/site/login.js'],
request_password_reset :[js_dir + '/site/request_password_reset']
request_password_reset: [js_dir + '/site/request_password_reset']
};
......@@ -60,7 +60,7 @@ var config = {
}),
new CopyWebpackPlugin([
// {from: __dirname + '/resource', to: 'resource'},
// {from: lib_dir + '/layer', to: 'layer'},
{from: lib_dir + '/layer', to: 'layer'},
// {from: img_dir, to: 'img'},
// {from: manage_dir + '/dist', to: 'manage/dist'},
// {from: manage_dir + '/plugins', to: 'manage/plugins'},
......@@ -113,6 +113,8 @@ if (process.env.NODE_ENV === 'production') {
config.plugins = config.plugins.concat([
new webpack.DefinePlugin({
__BASE_URL__: JSON.stringify('http://dev.zuiketang.com/'),
__CDN_URL__: JSON.stringify('http://dev.zuiketang.com/')
}),
]);
// config.devtool = 'source-map'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment