Browse Source

login js function update

master
filesite 7 months ago
parent
commit
b437e3082a
  1. 13
      plugins/Common.php
  2. 23
      themes/tajian/controller/FrontapiController.php
  3. 5
      www/js/tajian.js

13
plugins/Common.php

@ -26,13 +26,13 @@ Class Common { @@ -26,13 +26,13 @@ Class Common {
//初始化用户数据目录
public static function initUserData($cellphone, $friends_code = '') {
$rootDir = __DIR__ . '/../www/' . FSC::$app['config']['content_directory'];
$userDir = "{$rootDir}{$cellphone}";
if (is_dir($userDir)) {
$userDir = self::getUserDataDir($cellphone);
if (!empty($userDir)) {
return true;
}
try {
$rootDir = __DIR__ . '/../www/' . FSC::$app['config']['content_directory'];
mkdir("{$userDir}/data/", 0755, true); //分享视频目录
mkdir("{$userDir}/tags/", 0700, true); //分类目录
copy("{$rootDir}README.md", "{$userDir}/README.md");
@ -48,6 +48,13 @@ Class Common { @@ -48,6 +48,13 @@ Class Common {
return true;
}
//判断用户数据目录是否存在
public static function getUserDataDir($cellphone) {
$rootDir = __DIR__ . '/../www/' . FSC::$app['config']['content_directory'];
$userDir = "{$rootDir}{$cellphone}";
return is_dir($userDir) ? $userDir : false;
}
//检查朋友的邀请码是否存在
public static function existFriendsCode($code) {
if (self::isFriendsCode($code) == false) {return false;}

23
themes/tajian/controller/FrontapiController.php

@ -473,14 +473,24 @@ eof; @@ -473,14 +473,24 @@ eof;
//TODO: 验证短信验证码是否正确
if (empty($err)) { //如果数据检查通过,尝试注册新用户
$userDataDir = Common::getUserDataDir($cellphone);
if (empty($userDataDir)) {
$newUser = Common::saveUserIntoSession($cellphone, $friends_code);
if (!empty($newUser)) {
Common::saveFriendsCode($cellphone);
Common::initUserData($cellphone, $friends_code);
$shareUrl = "/{$cellphone}/";
}
$msg = "注册完成,开始收藏你喜欢的视频吧,正在为你跳转到专属网址...";
$code = 1;
}else {
$err = '注册失败,请稍后再试';
}
}else {
$shareUrl = "/{$cellphone}/";
$msg = "已注册,正在为你跳转到专属网址...";
$code = 1;
}
}
}
@ -503,6 +513,7 @@ eof; @@ -503,6 +513,7 @@ eof;
$code = 0;
$msg = '';
$err = '';
$shareUrl = '';
//用户提交的数据检查
$postParams = $this->post();
@ -514,18 +525,26 @@ eof; @@ -514,18 +525,26 @@ eof;
$err = "请填写注册邀请码、手机号码和短信验证码哦";
}else if (Common::isCellphoneNumber($cellphone) == false) {
$err = "手机号码格式错误,请填写正确的手机号码";
}else if (Common::getUserDataDir($cellphone) == false) {
$err = "{$cellphone}还没注册哦,先去注册吧";
}
//TODO: 验证短信验证码是否正确
if (empty($err)) { //如果数据检查通过,尝试登录
$newUser = Common::saveUserIntoSession($cellphone);
if (!empty($newUser)) {
$shareUrl = "/{$cellphone}/";
$msg = "登录成功,开始收藏你喜欢的视频吧";
$code = 1;
}else {
$err = '登录失败,请稍后重试';
}
}
}
return $this->renderJson(compact('code', 'msg', 'err'));
return $this->renderJson(compact('code', 'msg', 'err', 'shareUrl'));
}
}

5
www/js/tajian.js

@ -288,9 +288,12 @@ if ($('#login_form').get(0)) { @@ -288,9 +288,12 @@ if ($('#login_form').get(0)) {
};
publicAjax(taJian.apis.login, 'POST', datas, function (data) {
btLoading.addClass('elementNone');
if (data.code == 1) {
if (data.code == 1 && data.shareUrl) {
btText.text('完成');
alert(data.msg);
setTimeout(function() {
location.href = data.shareUrl;
}, 100);
} else {
btText.text('登录');
bt.prop('disabled', false);

Loading…
Cancel
Save