Browse Source

nickname save done

master
filesite 7 months ago
parent
commit
9f1f60ff9a
  1. 63
      themes/tajian/controller/FrontapiController.php
  2. 25
      themes/tajian/controller/MyController.php
  3. 16
      themes/tajian/controller/SiteController.php
  4. 7
      themes/tajian/views/layout/index.php
  5. 7
      themes/tajian/views/layout/main.php
  6. 2
      themes/tajian/views/my/index.php
  7. 30
      themes/tajian/views/my/setnickname.php
  8. 2
      themes/tajian/views/site/login.php
  9. 9
      themes/tajian/views/site/new.php
  10. 40
      www/js/tajian.js

63
themes/tajian/controller/FrontapiController.php

@ -638,13 +638,6 @@ eof; @@ -638,13 +638,6 @@ eof;
$err = "{$sms_code} 验证码已过期或错误,请检查是否输入正确";
}
if (empty($err)) {
$userDataDir = Common::getUserDataDir($cellphone);
if (empty($userDataDir)) {
$err = '你还没注册,请先注册';
}
}
if (empty($err)) { //如果数据检查通过,尝试登录
$newUser = Common::saveUserIntoSession($cellphone);
if (!empty($newUser)) {
@ -661,9 +654,63 @@ eof; @@ -661,9 +654,63 @@ eof;
return $this->renderJson(compact('code', 'msg', 'err', 'shareUrl'));
}
//昵称设置
public function actionSetnickname() {
$ip = $this->getUserIp();
$check_time = 120; //2 分钟内
$max_time_in_minutes = 5; //最多 5 次
$isUserGotRequestLimit = $this->requestLimit($ip, $max_time_in_minutes, $check_time);
if ($isUserGotRequestLimit) {
$this->logError("Request limit got, ip: {$ip}");
throw new Exception('Oops,操作太快了,请喝杯咖啡休息会吧...');
}
//只允许修改自己的昵称
$loginedUser = Common::getUserFromSession();
if (empty($loginedUser['username'])) {
throw new Exception('Oops,你还没登录哦');
}else if (
!empty(FSC::$app['config']['multipleUserUriParse'])
&& (empty(FSC::$app['user_id']) || FSC::$app['user_id'] != $loginedUser['username'])
) {
throw new Exception('Oops,请求地址有误');
}
//返回给视图的变量
$code = 0;
$msg = '';
$err = '';
//用户提交的数据检查
$postParams = $this->post();
if (!empty($postParams)) {
$nickname = $this->post('nickname', '');
if (empty($nickname)) {
$err = "请填写注册你的昵称";
}else if (mb_strlen($nickname, 'utf-8') < 2 || mb_strlen($nickname, 'utf-8') > 5) {
$err = "昵称至少 2 个汉字,最多 5 个汉字,请按规则填写";
}
if (empty($err)) { //如果数据检查通过,尝试保存
$saved = $this->saveNickname($nickname);
if (!empty($saved)) {
$msg = "昵称设置完成";
$code = 1;
}else {
$err = '昵称设置失败,请稍后重试';
}
}
}
return $this->renderJson(compact('code', 'msg', 'err'));
}
//TODO: 分类管理
//TODO: 昵称设置
//TODO: 视频管理

25
themes/tajian/controller/MyController.php

@ -61,6 +61,31 @@ Class MyController extends SiteController { @@ -61,6 +61,31 @@ Class MyController extends SiteController {
return $this->render($viewName, $params, $pageTitle);
}
//修改昵称
public function actionSetnickname() {
//判断是否已经登录
$loginedUser = Common::getUserFromSession();
if (empty($loginedUser['username'])) {
return $this->redirect('/site/login');
}else if (!empty(FSC::$app['config']['multipleUserUriParse']) && FSC::$app['user_id'] != $loginedUser['username']) {
$shareUrl = "/{$loginedUser['username']}/my/setnickname/";
return $this->redirect($shareUrl);
}
$scanner = new DirScanner();
$scanner->setWebRoot(FSC::$app['config']['content_directory']);
$dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 4);
$readmeFile = $scanner->getDefaultReadme();
$nickname = $this->getNickname($readmeFile);
$pageTitle = "修改昵称 | " . FSC::$app['config']['site_name'];
$this->layout = 'index';
$viewName = 'setnickname';
$params = compact(
'pageTitle', 'nickname'
);
return $this->render($viewName, $params, $pageTitle);
}
}

16
themes/tajian/controller/SiteController.php

@ -180,6 +180,22 @@ Class SiteController extends Controller { @@ -180,6 +180,22 @@ Class SiteController extends Controller {
return $nickname;
}
protected function saveNickname($nickname) {
$done = false;
try {
$filename = FSC::$app['config']['content_directory'] . 'README_nickname.txt';
$savedBytes = file_put_contents($filename, $nickname);
if ($savedBytes !== false) {
$done = true;
}
}catch(Exception $e) {
$this->logError('Save nickname failed: ' . $e->getMessage());
}
return $done;
}
//添加新视频
//增加必须登录才能使用限制
public function actionNew() {

7
themes/tajian/views/layout/index.php

@ -56,6 +56,13 @@ if (!empty($viewFile) && file_exists($viewFile)) { @@ -56,6 +56,13 @@ if (!empty($viewFile) && file_exists($viewFile)) {
<img src="/img/bg/ice_3.jpeg" alt="水面上的冰山一角">
</div>
<?php
$user_id = '';
if (!empty(FSC::$app['config']['multipleUserUriParse']) && !empty(FSC::$app['user_id'])) {
$user_id = FSC::$app['user_id'];
}
?>
<script>var current_user_id = '<?=$user_id?>';</script>
<script src="/js/jquery-3.6.0.min.js"></script>
<script src="/js/lazyload.js"></script>
<script src="/js/tajian.js?v<?=Html::getStaticFileVersion('tajian.js', 'js')?>"></script>

7
themes/tajian/views/layout/main.php

@ -154,6 +154,13 @@ eof; @@ -154,6 +154,13 @@ eof;
</div>
<?php } ?>
<?php
$user_id = '';
if (!empty(FSC::$app['config']['multipleUserUriParse']) && !empty(FSC::$app['user_id'])) {
$user_id = FSC::$app['user_id'];
}
?>
<script>var current_user_id = '<?=$user_id?>';</script>
<script src="/js/jquery-3.6.0.min.js"></script>
<script src="/js/lazyload.js"></script>
<script src="/js/tajian.js?v<?=Html::getStaticFileVersion('tajian.js', 'js')?>"></script>

2
themes/tajian/views/my/index.php

@ -13,7 +13,7 @@ if (!empty(FSC::$app['config']['multipleUserUriParse']) && !empty(FSC::$app['use @@ -13,7 +13,7 @@ if (!empty(FSC::$app['config']['multipleUserUriParse']) && !empty(FSC::$app['use
<div class="g_form_style">
<div class="vercenter">
<strong class="nickname"><?=htmlspecialchars($viewData['nickname'], ENT_QUOTES)?></strong>
(<a href="###">修改</a>)
(<a href="<?=$linkPrefix?>/my/setnickname">修改</a>)
<p class="mt10">
<a href="/site/logout">退出登录</a>
</p>

30
themes/tajian/views/my/setnickname.php

@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
<?php
$linkPrefix = '';
//多用户路径支持
if (!empty(FSC::$app['config']['multipleUserUriParse']) && !empty(FSC::$app['user_id'])) {
$linkPrefix = '/' . FSC::$app['user_id'];
}
?><main class="g_main_lay g_main_border">
<form class="add_video_form g_form_style mt65" id="nickname_form" action="" method="POST">
<div class="mb-3 pt20">
<label for="text_input_nickname" class="form-label">昵称</label>
<input id="text_input_nickname" name="nickname" placeholder="请填写 2 - 5 个汉字" value="<?=$viewData['nickname']?>">
<p class="mt10">请填写 2 - 5 个汉字</p>
</div>
<div class="avform_bt vercenter">
<button class="jsbtn" aria-label="保存" type="button">
<div class="loading_bt bt_class_JS elementNone verMiddle">
<svg viewBox="25 25 50 50">
<circle cx="50" cy="50" r="20"></circle>
</svg>
</div>
<span class="bt_text_JS">保存</span>
<div class="bt_loading_cover bt_class_JS elementNone"></div>
</button>
<span class="ml20">
<a href="<?=$linkPrefix?>/my/">返回</a>
</span>
</div>
</form>
</main>

2
themes/tajian/views/site/login.php

@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
<button disabled="disabled" class="smsbtn bt_sms_JS">发送验证码</button>
</div>
<div class="avform_bt vercenter">
<button class="jsbtn" aria-label="注册" type="button">
<button class="jsbtn" aria-label="登录" type="button">
<div class="loading_bt bt_class_JS elementNone verMiddle">
<svg viewBox="25 25 50 50">
<circle cx="50" cy="50" r="20"></circle>

9
themes/tajian/views/site/new.php

@ -32,12 +32,3 @@ eof; @@ -32,12 +32,3 @@ eof;
</div>
</form>
</main>
<?php
$user_id = '';
if (!empty(FSC::$app['config']['multipleUserUriParse']) && !empty(FSC::$app['user_id'])) {
$user_id = FSC::$app['user_id'];
}
?>
<script>
var current_user_id = '<?=$user_id?>';
</script>

40
www/js/tajian.js

@ -7,6 +7,7 @@ var taJian = { @@ -7,6 +7,7 @@ var taJian = {
domain: 'https://tajian.tv',
apis: {
addVideos: '/frontapi/addfav', //添加视频
setNickname: '/frontapi/setnickname', //设置昵称
sendSmsCode: '/frontapi/sendsmscode', //发送短信验证码
register: '/frontapi/createuser', //注册
login: '/frontapi/loginuser' //登入
@ -356,4 +357,43 @@ if ($('#login_form').get(0)) { @@ -356,4 +357,43 @@ if ($('#login_form').get(0)) {
});
}
// 设置昵称
if ($('#nickname_form').get(0)) {
$('#nickname_form .jsbtn').click(function(e) {
e.preventDefault();
var nickname = $('input[name=nickname]').val();
if (!nickname) {
alert('请填写 2 - 5 个汉字的昵称!');
return false;
}
var bt = $(this), btLoading = bt.children('.bt_class_JS'), btText = bt.children('.bt_text_JS');
btLoading.removeClass('elementNone');
bt.prop('disabled', true);
btText.text('提交中...');
var datas = {
'nickname': nickname
};
publicAjax(taJian.apis.setNickname, 'POST', datas, function (data) {
btLoading.addClass('elementNone');
bt.prop('disabled', false);
btText.text('保存');
if (data.code == 1) {
alert(data.msg);
} else {
alert(data.err);
}
}, function (jqXHR, textStatus, errorThrown) {
bt.prop('disabled', false);
btText.text('保存');
btLoading.addClass('elementNone');
alert('网络请求失败,请重试。');
});
});
}
})();

Loading…
Cancel
Save