Commit a8eab4d4 authored by xiabin's avatar xiabin

添加登录注册

parent 0d02bb7a
...@@ -5,8 +5,9 @@ return [ ...@@ -5,8 +5,9 @@ return [
'user.passwordResetTokenExpire' => 3600, 'user.passwordResetTokenExpire' => 3600,
'captchaId' => '4d6ad870bf63a30be3d22c92925b04ca', 'captchaId' => '4d6ad870bf63a30be3d22c92925b04ca',
'privateKey' => 'a2ca5e5139d1f43ac4e1cd248f3e52e4', 'privateKey' => 'a2ca5e5139d1f43ac4e1cd248f3e52e4',
'msg.host' => 'http://120.55.242.177/OpenPlatform/OpenApi', 'msg.host' => 'http://114.55.132.75:7893/sms.aspx',
'msg.ac' => '1001@800123450001', 'msg.userid' => '78',
'msg.authkey' => '0E9AEFC25E6A4816E7832755BC5CCA61', 'msg.account' => '276147613x',
'msg.cgid' => '222' 'msg.password' => '276147613',
'msg.signature' => '【最课堂】'
]; ];
...@@ -10,8 +10,8 @@ class Geetest ...@@ -10,8 +10,8 @@ class Geetest
{ {
const GT_SDK_VERSION = 'php_3.2.0'; const GT_SDK_VERSION = 'php_3.2.0';
public static $connectTimeout = 1; public static $connectTimeout = 10;
public static $socketTimeout = 1; public static $socketTimeout = 10;
private $response; private $response;
......
...@@ -28,10 +28,10 @@ class Message ...@@ -28,10 +28,10 @@ class Message
$params = Yii::$app->params; $params = Yii::$app->params;
$this->hosts = $params['msg.host']; $this->hosts = $params['msg.host'];
$this->query = [ $this->query = [
'action' => 'sendOnce', 'action' => 'send',
'ac' => $params['msg.ac'], 'userid' => $params['msg.userid'],
'authkey' => $params['msg.authkey'], 'account' => $params['msg.account'],
'cgid' => $params['msg.cgid'], 'password' => $params['msg.password'],
]; ];
$this->httpClient = new Client(); $this->httpClient = new Client();
} }
...@@ -47,11 +47,13 @@ class Message ...@@ -47,11 +47,13 @@ class Message
if (is_array($telephones)) { if (is_array($telephones)) {
$telephones = implode(',', $telephones); $telephones = implode(',', $telephones);
} }
$this->query['m'] = $telephones; $content .= ' ' . Yii::$app->params['msg.signature'];
$this->query['c'] = $content; $this->query['mobile'] = $telephones;
$this->query['content'] = $content;
return FALSE;
try { try {
$response = $this->httpClient->request('GET', $this->hosts, [ $response = $this->httpClient->request('GET', $this->hosts, [
'query' => $this->query 'form_params' => $this->query
]); ]);
} catch (ClientException $e) { } catch (ClientException $e) {
$response = $e->getResponse(); $response = $e->getResponse();
...@@ -59,14 +61,10 @@ class Message ...@@ -59,14 +61,10 @@ class Message
throw $e; throw $e;
Yii::getLogger()->log($e, Logger::LEVEL_ERROR, 'Message'); Yii::getLogger()->log($e, Logger::LEVEL_ERROR, 'Message');
} }
$return = new \SimpleXMLElement($response->getBody()->getContents()); $return = new \SimpleXMLElement($response->getBody()->getContents());
if ((string)$return->returnstatus !== 'Success') {
if ((int)$return['result'] !== 1) { Yii::getLogger()->log((string)$return->message, Logger::LEVEL_ERROR, 'Message');
Yii::getLogger()->log($return['result'], Logger::LEVEL_ERROR, 'Message');
} }
} }
......
...@@ -47,7 +47,7 @@ class Utils ...@@ -47,7 +47,7 @@ class Utils
* @param int $length * @param int $length
* @return int * @return int
*/ */
public function randomNumber($length = 6) public static function randomNumber($length = 6)
{ {
if ($length < 4 or $length > 6) { if ($length < 4 or $length > 6) {
$length = 6; $length = 6;
...@@ -70,4 +70,18 @@ class Utils ...@@ -70,4 +70,18 @@ class Utils
return mt_rand($min, $max); 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 <?php
return [ return [
'adminEmail' => 'admin@example.com' 'adminEmail' => 'admin@example.com',
'signup.msg' => '您正在注册最课堂,验证码: xxxxxx,2小时内有效',
'resetpassword.msg' => '您正在找回密码,验证码: xxxxxx,2小时内有效',
]; ];
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace frontend\controllers; namespace frontend\controllers;
use common\libs\Geetest; use common\libs\Geetest;
use common\libs\Message;
use common\libs\Utils; use common\libs\Utils;
use common\models\User; use common\models\User;
use frontend\models\TokenInputForm; use frontend\models\TokenInputForm;
...@@ -171,7 +172,9 @@ class SiteController extends Controller ...@@ -171,7 +172,9 @@ class SiteController extends Controller
$from = $request->get('from', 0); $from = $request->get('from', 0);
$from = HtmlPurifier::process($from); $from = HtmlPurifier::process($from);
$model->from = (int)$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'); $geetestChallenge = $request->post('geetest_challenge');
$geetestSeccode = $request->post('geetest_seccode'); $geetestSeccode = $request->post('geetest_seccode');
$geetestValidate = $request->post('geetest_validate'); $geetestValidate = $request->post('geetest_validate');
...@@ -185,6 +188,8 @@ class SiteController extends Controller ...@@ -185,6 +188,8 @@ class SiteController extends Controller
$gtResult = $GtSdk->fail_validate($geetestChallenge, $geetestValidate, $geetestSeccode); $gtResult = $GtSdk->fail_validate($geetestChallenge, $geetestValidate, $geetestSeccode);
} }
if ($gtResult && $user = $model->signup()) { if ($gtResult && $user = $model->signup()) {
//删除短信验证码
Yii::$app->session->remove(self::SIGNUP_TOKEN);
if (Yii::$app->getUser()->login($user)) { if (Yii::$app->getUser()->login($user)) {
return $this->goHome(); return $this->goHome();
} }
...@@ -259,8 +264,7 @@ class SiteController extends Controller ...@@ -259,8 +264,7 @@ class SiteController extends Controller
* Resets password. * Resets password.
* @return mixed * @return mixed
*/ */
public public function actionResetPassword()
function actionResetPassword()
{ {
if (!Yii::$app->session->has(self::RESET_PASSWORD_SECOND)) { if (!Yii::$app->session->has(self::RESET_PASSWORD_SECOND)) {
$this->redirect('request-password-reset'); $this->redirect('request-password-reset');
...@@ -295,8 +299,7 @@ class SiteController extends Controller ...@@ -295,8 +299,7 @@ class SiteController extends Controller
* 极验证开始 * 极验证开始
* ajax * ajax
*/ */
public public function actionStartCaptcha()
function actionStartCaptcha()
{ {
if (Yii::$app->request->isAjax) { if (Yii::$app->request->isAjax) {
$type = Yii::$app->request->get('type'); $type = Yii::$app->request->get('type');
...@@ -323,11 +326,16 @@ class SiteController extends Controller ...@@ -323,11 +326,16 @@ class SiteController extends Controller
public function actionSendSignupMsg() public function actionSendSignupMsg()
{ {
if (TRUE || Yii::$app->request->isAjax) { if (TRUE || Yii::$app->request->isAjax) {
$telephone = trim(Yii::$app->request->get('telephone'));
if (Utils::isTelephone($telephone)) {
$key = self::REDIS_SIGNUP_MSG_PREFIX . '::' . Utils::getRealIP(); $key = self::REDIS_SIGNUP_MSG_PREFIX . '::' . Utils::getRealIP();
$redis = Yii::$app->redis; $redis = Yii::$app->redis;
$value = $redis->get($key); $value = $redis->get($key);
if ($value === NULL) { if ($value === NULL) {
//sendMsg $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); $redis->setex($key, self::REDIS_SIGNUP_MSG_EXPIRE, 1);
$result = TRUE; $result = TRUE;
$msg = ""; $msg = "";
...@@ -335,6 +343,11 @@ class SiteController extends Controller ...@@ -335,6 +343,11 @@ class SiteController extends Controller
$result = FALSE; $result = FALSE;
$msg = '一分钟只有一次'; $msg = '一分钟只有一次';
} }
} else {
$result = FALSE;
$msg = '手机格式不正确';
}
Utils::ajaxResponse($result, $msg); Utils::ajaxResponse($result, $msg);
} else { } else {
throw new \yii\web\ForbiddenHttpException('非法请求'); throw new \yii\web\ForbiddenHttpException('非法请求');
......
...@@ -41,7 +41,7 @@ class UserCenterController extends Controller ...@@ -41,7 +41,7 @@ class UserCenterController extends Controller
public function actionTest() public function actionTest()
{ {
$message = new Message(); $message = new Message();
$result = $message->send('15395081586','xiabin'); $result = $message->send('15395081586','xia12312321313213bin');
} }
public function actionIndex() public function actionIndex()
......
<?php <?php
namespace frontend\models; namespace frontend\models;
use common\libs\Message;
use common\libs\SendMsg; use common\libs\SendMsg;
use Yii; use Yii;
use yii\base\Model; use yii\base\Model;
...@@ -53,8 +54,11 @@ class PasswordResetRequestForm extends 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 //send_msg
return TRUE; return TRUE;
} }
......
...@@ -32,8 +32,8 @@ $this->registerJsFile('http://static.geetest.com/static/tools/gt.js'); ...@@ -32,8 +32,8 @@ $this->registerJsFile('http://static.geetest.com/static/tools/gt.js');
<label class="control-label" for="token">Token</label> <label class="control-label" for="token">Token</label>
<input type="text" class="form-control" id="token"> <input name="token" type="text" class="form-control" id="token">
<button class=""> send msg</button> <button id="send_msg" class=""> send msg</button>
<div style="margin-top: 20px;margin-bottom: 20px"> <div style="margin-top: 20px;margin-bottom: 20px">
<div id="embed-captcha"></div> <div id="embed-captcha"></div>
......
/index.php /index.php
/index-test.php /index-test.php
/js/node_modules/
\ No newline at end of file
This diff is collapsed.
...@@ -51,7 +51,7 @@ webpackJsonp([1],[ ...@@ -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],[ webpackJsonp([2],{
/* 0 */
/***/ 0:
/***/ function(module, exports, __webpack_require__) { /***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(3); module.exports = __webpack_require__(6);
/***/ }, /***/ },
/* 1 */,
/* 2 */, /***/ 6:
/* 3 */
/***/ function(module, exports, __webpack_require__) { /***/ function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function($) {var handlerEmbed = function (captchaObj) { /* WEBPACK VAR INJECTION */(function($) {var handlerEmbed = function (captchaObj) {
...@@ -47,7 +47,29 @@ webpackJsonp([2],[ ...@@ -47,7 +47,29 @@ webpackJsonp([2],[
}, handlerEmbed); }, 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
...@@ -34,3 +34,24 @@ $.ajax({ ...@@ -34,3 +34,24 @@ $.ajax({
}, handlerEmbed); }, 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'); ...@@ -2,17 +2,17 @@ var webpack = require('webpack');
var css_dir = __dirname + '/css'; var css_dir = __dirname + '/css';
var img_dir = __dirname + '/img'; var img_dir = __dirname + '/img';
var js_dir = __dirname + '/js'; 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 CommonsChunkPlugin = require("webpack/lib/optimize/CommonsChunkPlugin");
var path = require('path'); var path = require('path');
var CopyWebpackPlugin = require('copy-webpack-plugin'); var CopyWebpackPlugin = require('copy-webpack-plugin');
var ExtractTextPlugin = require("extract-text-webpack-plugin"); var ExtractTextPlugin = require("extract-text-webpack-plugin");
var entry = { var entry = {
vendor: ["jquery", "vue"], vendor: ["jquery", "vue", js_dir + "/utils/layer"],
signup: [js_dir + '/site/signup.js'], signup: [js_dir + '/site/signup.js'],
login: [js_dir + '/site/login.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 = { ...@@ -60,7 +60,7 @@ var config = {
}), }),
new CopyWebpackPlugin([ new CopyWebpackPlugin([
// {from: __dirname + '/resource', to: 'resource'}, // {from: __dirname + '/resource', to: 'resource'},
// {from: lib_dir + '/layer', to: 'layer'}, {from: lib_dir + '/layer', to: 'layer'},
// {from: img_dir, to: 'img'}, // {from: img_dir, to: 'img'},
// {from: manage_dir + '/dist', to: 'manage/dist'}, // {from: manage_dir + '/dist', to: 'manage/dist'},
// {from: manage_dir + '/plugins', to: 'manage/plugins'}, // {from: manage_dir + '/plugins', to: 'manage/plugins'},
...@@ -113,6 +113,8 @@ if (process.env.NODE_ENV === 'production') { ...@@ -113,6 +113,8 @@ if (process.env.NODE_ENV === 'production') {
config.plugins = config.plugins.concat([ config.plugins = config.plugins.concat([
new webpack.DefinePlugin({ new webpack.DefinePlugin({
__BASE_URL__: JSON.stringify('http://dev.zuiketang.com/'), __BASE_URL__: JSON.stringify('http://dev.zuiketang.com/'),
__CDN_URL__: JSON.stringify('http://dev.zuiketang.com/')
}), }),
]); ]);
// config.devtool = 'source-map' // 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