From 63572afc28dc4550ae3c61ee9259ca9e205367c7 Mon Sep 17 00:00:00 2001 From: OldHawk Date: Thu, 26 Apr 2018 18:45:34 +0800 Subject: [PATCH] feat(home): add a cron job to check users account status to idle if for lang time no sign in --- config/env/torrents.js | 21 ++++++---- config/lib/cron-job.js | 41 +++++++++++++++++++ .../about/client/templates/score-rules-en.md | 2 +- .../about/client/templates/score-rules-zh.md | 2 +- .../client/templates/user-account-rules-en.md | 2 +- .../client/templates/user-account-rules-zh.md | 2 +- .../announces.server.controller.js | 12 +++--- modules/core/client/app/trans-string-en.js | 4 +- modules/core/client/app/trans-string-zh.js | 4 +- .../NotifycationService.client.service.js | 4 +- .../torrent-download.client.service.js | 7 ++-- .../authentication.client.controller.js | 5 ++- .../status/status.client.controller.js | 2 +- .../users/server/config/strategies/local.js | 12 +++--- .../users/users.profile.server.controller.js | 6 +-- 15 files changed, 89 insertions(+), 37 deletions(-) diff --git a/config/env/torrents.js b/config/env/torrents.js index 1bfe1506..adc0ac93 100644 --- a/config/env/torrents.js +++ b/config/env/torrents.js @@ -291,12 +291,15 @@ module.exports = { * @signUpActiveTokenExpires_str: string desc of @signUpActiveTokenExpires * @allowSocialSignin: meanTorrent can accept social account to signin, like google, twitter, facebook etc. * if you do not want them to login, please set it to false + * * @showMenuHeaderForGuest: set whether show menu header for guest user(not sign in) * @showFooterCountInfoForGuest: set whether show count info at home footer for guest user(not sign in) * @showDemoSignMessage: if true, will show demo sign in message in sign in page, if your site is not demo site, please set it to false - * @accountIdleForTime: setting for how many time not login then change account status to idle - * @accountIdleForTime_str: string desc of @accountIdleForTime - * @activeIdleAccountScore: user active idle account need score numbers + * + * @idle: setting for account status of idle + * @accountIdleForTime: setting for how many time not login then change account status to idle + * @accountIdleForTime_str: string desc of @accountIdleForTime + * @activeIdleAccountBasicScore: user active idle account need basic score numbers */ sign: { openSignup: true, @@ -304,12 +307,16 @@ module.exports = { signUpActiveTokenExpires: 60 * 60 * 1000 * 24, signUpActiveTokenExpires_str: '24h', allowSocialSignin: false, + showMenuHeaderForGuest: true, showFooterCountInfoForGuest: true, showDemoSignMessage: true, - accountIdleForTime: 60 * 60 * 1000 * 24 * 30, //30 days - accountIdleForTime_str: '30d', - activeIdleAccountScore: 50000 + + idle: { + accountIdleForTime: 60 * 60 * 1000 * 24 * 30, //30 days + accountIdleForTime_str: '30d', + activeIdleAccountBasicScore: 50000 + } }, /** @@ -402,7 +409,7 @@ module.exports = { postRequest: {name: 'postRequest', value: 0, enable: true}, //value used requests.scoreForAddRequest scoreExchangeInvitation: {name: 'scoreExchangeInvitation', value: 0, enable: true}, //value used invite.scoreExchange scoreToRemoveWarning: {name: 'scoreToRemoveWarning', value: 0, enable: true}, //value used hitAndRun.scoreToRemoveWarning - activeIdleAccount: {name: 'activeIdleAccountScore', value: 0, enable: true}, //value used sign.activeIdleAccountScore + activeIdleAccount: {name: 'activeIdleAccount', value: 0, enable: true}, //value used sign.idle.activeIdleAccountBasicScore seedUpDownload: { name: 'seedUpDownload', diff --git a/config/lib/cron-job.js b/config/lib/cron-job.js index 3983a6ea..01ac65c1 100644 --- a/config/lib/cron-job.js +++ b/config/lib/cron-job.js @@ -18,6 +18,7 @@ var appConfig = config.meanTorrentConfig.app; var supportConfig = config.meanTorrentConfig.support; var backupConfig = config.meanTorrentConfig.backup; var announceConfig = config.meanTorrentConfig.announce; +var signConfig = config.meanTorrentConfig.sign; var inbox = require('inbox'); var simpleParser = require('mailparser').simpleParser; @@ -66,6 +67,7 @@ module.exports = function (app) { } cronJobs.push(removeGhostPeers()); + cronJobs.push(checkUserAccountIdleStatus()); cronJobs.push(countUsersHnrWarning()); if (supportConfig.mailTicketSupportService) { @@ -179,6 +181,45 @@ function removeGhostPeers() { return cronJob; } +/** + * checkUserAccountIdleStatus + */ +function checkUserAccountIdleStatus() { + var cronJob = new CronJob({ + cronTime: '00 10 1 * * *', + // cronTime: '*/5 * * * * *', + onTick: function () { + console.log(chalk.green('checkUserAccountIdleStatus: process!')); + + User.update( + { + status: {$ne: 'idle'}, + last_signed: {$lt: Date.now() - signConfig.idle.accountIdleForTime} + }, + { + $set: { + status: 'idle' + } + }, + { + multi: true + }, function (err, numAffected) { + if (err) { + mtDebug.debugError(err); + } else { + mtDebug.debugGreen('checkUserAccountIdleStatus: ' + numAffected.nModified + ' users!'); + } + }); + }, + start: false, + timeZone: appConfig.cronTimeZone + }); + + cronJob.start(); + + return cronJob; +} + /** * countUsersHnrWarning */ diff --git a/modules/about/client/templates/score-rules-en.md b/modules/about/client/templates/score-rules-en.md index aba2f120..aaa8d517 100644 --- a/modules/about/client/templates/score-rules-en.md +++ b/modules/about/client/templates/score-rules-en.md @@ -49,7 +49,7 @@ For every seed, `%(scoreConfig.action.seedTimed.timedValue)d` scores per `%(scor   #### :white_small_square: Score deduction rules -* Reactivate a long unused user account, account status changed from idle to normal, deducted `%(signConfig.activeIdleAccountScore)d` scores. +* Reactivate a long unused user account, account status changed from idle to normal, deducted `%(signConfig.idle.activeIdleAccountBasicScore)d` scores. * Exchange an invitation, need to deduct `%(inviteConfig.scoreExchange)d` scores. * Each time a user post a request, the system will automatically reclaim `%(requestsConfig.scoreForAddRequest)d` scores. If the request is answered and accepted by the requester, the system will automatically deduct the scores the requester rewards. * Remove an H&R warning, need to deduct `%(hnrConfig.scoreToRemoveWarning)d` scores. diff --git a/modules/about/client/templates/score-rules-zh.md b/modules/about/client/templates/score-rules-zh.md index 46b655a6..29771177 100644 --- a/modules/about/client/templates/score-rules-zh.md +++ b/modules/about/client/templates/score-rules-zh.md @@ -47,7 +47,7 @@   #### :white_small_square: 积分扣除规则 -* 重新激活长时间未使用的用户帐户,帐户状态由 空闲 变为 正常, 扣除 `%(signConfig.activeIdleAccountScore)d` 积分。 +* 重新激活长时间未使用的用户帐户,帐户状态由 空闲 变为 正常, 扣除 `%(signConfig.idle.activeIdleAccountBasicScore)d` 积分。 * 兑换一张邀请函,需要扣除 `%(inviteConfig.scoreExchange)d` 积分。 * 用户每发布一条请求,系统会自动回收 `%(requestsConfig.scoreForAddRequest)d` 积分,如果请求被回应而且被请求者采纳,系统会自动扣除请求者悬赏的积分。 * 移除一条 H&R 警告,需要扣除 `%(hnrConfig.scoreToRemoveWarning)d` 积分。 diff --git a/modules/about/client/templates/user-account-rules-en.md b/modules/about/client/templates/user-account-rules-en.md index 35e129f7..4f1459f0 100644 --- a/modules/about/client/templates/user-account-rules-en.md +++ b/modules/about/client/templates/user-account-rules-en.md @@ -26,7 +26,7 @@ #### :white_small_square: Use account 1. If you forget your account password, you can recover your password by registering email, but `%(passwordConfig.resetTimeInterval_str)s` can only be recovered once in s hours, and the recovery email is valid for `%(passwordConfig.resetTokenExpires_str)s` hours. -1. If your account exceeds `%(signConfig.accountIdleForTime_str)s` days without signing in to the site,** we will not delete or block your account, but the account status will change to `idle`**, the idle accounts can log in, but You cannot upload or download any resources. If you need to reactivate your account, you must use the `%(signConfig.activeIdleAccountScore).2f` scores. +1. If your account exceeds `%(signConfig.idle.accountIdleForTime_str)s` days without signing in to the site,** we will not delete or block your account, but the account status will change to `idle`**, the idle accounts can log in, but You cannot upload or download any resources. If you need to reactivate your account, you must use the `%(signConfig.idle.activeIdleAccountBasicScore).2f` scores. 1. The system has a requirement of sharing rate for all downloading behaviors, but does not check the sharing rate for users who have newly registered `%(announceConfig.downloadCheck.checkAfterSignupDays)d` days, so the new user should be as much as possible during this time. Improve your own share. 1. If your account has too many H&R warnings, you will not be able to upload and download any resources. Please refer to [H&R rules detail](/about/manual/hnrRules)。 1. Please comply with the relevant provisions of the resource area, forums, chat rooms and other places, or your account may be banned. diff --git a/modules/about/client/templates/user-account-rules-zh.md b/modules/about/client/templates/user-account-rules-zh.md index af677b50..5600b718 100644 --- a/modules/about/client/templates/user-account-rules-zh.md +++ b/modules/about/client/templates/user-account-rules-zh.md @@ -26,7 +26,7 @@ #### :white_small_square: 使用帐户 1. 如果您忘记帐户密码,您可以通过注册邮件恢复密码,但 `%(passwordConfig.resetTimeInterval_str)s` 小时内只能恢复一次,且恢复邮件有效期为 `%(passwordConfig.resetTokenExpires_str)s` 小时。 -1. 如果您的帐户超过 `%(signConfig.accountIdleForTime_str)s` 天未登录网站,**我们不会删除或禁止您的帐户,但帐户状态会变为 `空闲`**,空闲帐户可以登录浏览,但不能上传下载任何资源,如您需要重新激活您的帐户,您必须使用 `%(signConfig.activeIdleAccountScore).2f` 积分。 +1. 如果您的帐户超过 `%(signConfig.idle.accountIdleForTime_str)s` 天未登录网站,**我们不会删除或禁止您的帐户,但帐户状态会变为 `空闲`**,空闲帐户可以登录浏览,但不能上传下载任何资源,如您需要重新激活您的帐户,您必须使用 `%(signConfig.idle.activeIdleAccountBasicScore).2f` 积分。 1. 系统对所有下载行为都有分享率的要求,但对新注册 `%(announceConfig.downloadCheck.checkAfterSignupDays)d` 天内的用户不做下载行为的分享率检查,所以新用户应该在此时间内尽可能的提高自已的分享率。 1. 如果帐户的 H&R 黑种警告数过多,您将不能上传下载任何资源,具体请参考 [H&R 黑种细则](/about/manual/hnrRules)。 1. 请遵守资源区、论坛、聊天室等场所的相关规定,否则您的帐号可能会被封禁。 diff --git a/modules/announce/server/controllers/announces.server.controller.js b/modules/announce/server/controllers/announces.server.controller.js index 46ec20eb..f1fa0df5 100644 --- a/modules/announce/server/controllers/announces.server.controller.js +++ b/modules/announce/server/controllers/announces.server.controller.js @@ -1200,12 +1200,12 @@ exports.userByPasskey = function (req, res, next, pk) { if (u) { req.passkeyuser = u; - if ((moment(Date.now()) - moment(req.passkeyuser.last_signed)) > signConfig.accountIdleForTime) { - req.passkeyuser.update({ - $set: {status: 'idle'} - }).exec(); - req.passkeyuser.status = 'idle'; - } + // if ((moment(Date.now()) - moment(req.passkeyuser.last_signed)) > signConfig.idle.accountIdleForTime) { + // req.passkeyuser.update({ + // $set: {status: 'idle'} + // }).exec(); + // req.passkeyuser.status = 'idle'; + // } } else { req.passkeyuser = undefined; } diff --git a/modules/core/client/app/trans-string-en.js b/modules/core/client/app/trans-string-en.js index cbe08a1b..e16ac99c 100644 --- a/modules/core/client/app/trans-string-en.js +++ b/modules/core/client/app/trans-string-en.js @@ -304,7 +304,7 @@ SIGNIN_ERROR: 'Signin Error!', SIGNUP_ERROR: 'Signup Error!', SIGNIN_WELCOME_NORMAL: 'Welcome, {{name}}', - SIGNIN_WELCOME_IDLE: 'Welcome, {{name}}, you not login for long time, your account is IDLE status, before download any things, you should active you account again in profile menu "account status"!', + SIGNIN_WELCOME_IDLE: 'Welcome, {{name}}, you not login for more than {{days}} days, your account is IDLE status, before download any things, you should active you account again in profile menu "account status"!', NEW_PASSWORD: 'New Password', NP_REQUIRED: 'Enter a new password.', @@ -1584,7 +1584,7 @@ ACCOUNT_IS_NOT_ACTIVATED: 'Your account is not activated, you should active first!', ONLY_VIP_CAN_DOWNLOAD: 'This torrent is only for Vip users', CAN_NOT_DOWNLOAD_BANNED: 'Download failed, you are banned from server', - CAN_NOT_DOWNLOAD_IDLE: 'Download failed, you are idle for long time, before download any things, you should active you account again in profile menu "account status"!', + CAN_NOT_DOWNLOAD_IDLE: 'Download failed, you not login for more than {{days}} days, your account is IDLE status, before download any things, you should active you account again in profile menu "account status"!', ALREADY_FOLLOWING: 'You have already following {{name}}', INVALID_OBJECTID: 'Invalid object id (SERVER)', REQUEST_STATUS_FINISHED: 'Status error! Request already finished.', diff --git a/modules/core/client/app/trans-string-zh.js b/modules/core/client/app/trans-string-zh.js index c33effed..80b01fd4 100644 --- a/modules/core/client/app/trans-string-zh.js +++ b/modules/core/client/app/trans-string-zh.js @@ -304,7 +304,7 @@ SIGNIN_ERROR: '登录失败!', SIGNUP_ERROR: '注册失败!', SIGNIN_WELCOME_NORMAL: '欢迎您, {{name}}', - SIGNIN_WELCOME_IDLE: '欢迎您, {{name}}, 您已经很长时间没有你登录, 帐户处于空闲状态, 在您下载任何种子前, 您必须进入帐户状态页再次激活您的帐户!', + SIGNIN_WELCOME_IDLE: '欢迎您, {{name}}, 您已经超过 {{days}} 天没有登录, 帐户处于空闲状态, 在您下载任何种子前, 您必须进入帐户状态页再次激活您的帐户!', NEW_PASSWORD: '新密码', NP_REQUIRED: '新密码不能为空.', @@ -1584,7 +1584,7 @@ ACCOUNT_IS_NOT_ACTIVATED: '您的帐户未激活, 请激活后再试!', ONLY_VIP_CAN_DOWNLOAD: '该种子只有VIP用户才可以下载', CAN_NOT_DOWNLOAD_BANNED: '下载失败, 您被服务器禁止(banned)', - CAN_NOT_DOWNLOAD_IDLE: '下载失败,您闲置了太长时间,在您下载任何种子前, 您必须进入帐户状态页再次激活您的帐户!', + CAN_NOT_DOWNLOAD_IDLE: '下载失败,您已经超过 {{days}} 天没有登录, 帐户处于空闲状态,在您下载任何种子前, 您必须进入帐户状态页再次激活您的帐户!', ALREADY_FOLLOWING: '您已经关注过 {{name}} 了', INVALID_OBJECTID: '无效的数据记录ID (SERVER)', REQUEST_STATUS_FINISHED: '状态错误! 求种请求已完成.', diff --git a/modules/core/client/services/NotifycationService.client.service.js b/modules/core/client/services/NotifycationService.client.service.js index a4f0c713..f9c64f7a 100644 --- a/modules/core/client/services/NotifycationService.client.service.js +++ b/modules/core/client/services/NotifycationService.client.service.js @@ -66,9 +66,9 @@ }); } - function showErrorNofity(msg, titleMsgId) { + function showErrorNofity(msg, titleMsgId, params = undefined) { var title_msg = titleMsgId ? $translate.instant(titleMsgId) : undefined; - msg = $translate.instant(msg); + msg = $translate.instant(msg, params); if (msg && titleMsgId) { Notification.error({ diff --git a/modules/torrents/client/services/torrent-download.client.service.js b/modules/torrents/client/services/torrent-download.client.service.js index bcaf222d..f5414141 100644 --- a/modules/torrents/client/services/torrent-download.client.service.js +++ b/modules/torrents/client/services/torrent-download.client.service.js @@ -5,9 +5,10 @@ .module('torrents.services') .factory('DownloadService', DownloadService); - DownloadService.$inject = ['$http', 'FileSaver', 'NotifycationService', 'DebugConsoleService']; + DownloadService.$inject = ['$http', 'FileSaver', 'NotifycationService', 'DebugConsoleService', 'MeanTorrentConfig']; - function DownloadService($http, FileSaver, NotifycationService, mtDebug) { + function DownloadService($http, FileSaver, NotifycationService, mtDebug, MeanTorrentConfig) { + var signConfig = MeanTorrentConfig.meanTorrentConfig.sign; return { downloadFile: downloadFile, @@ -37,7 +38,7 @@ NotifycationService.showErrorNotify('SERVER.CAN_NOT_DOWNLOAD_BANNED', 'TORRENT_DOWNLOAD_ERROR'); break; case 703: - NotifycationService.showErrorNotify('SERVER.CAN_NOT_DOWNLOAD_IDLE', 'TORRENT_DOWNLOAD_ERROR'); + NotifycationService.showErrorNotify('SERVER.CAN_NOT_DOWNLOAD_IDLE', 'TORRENT_DOWNLOAD_ERROR', {days: signConfig.idle.accountIdleForTime / (60 * 60 * 1000 * 24)}); break; case 704: NotifycationService.showErrorNotify('SERVER.TORRENT_STATUS_ERROR', 'TORRENT_DOWNLOAD_ERROR'); diff --git a/modules/users/client/controllers/authentication.client.controller.js b/modules/users/client/controllers/authentication.client.controller.js index 095bbc9c..1c1c222a 100644 --- a/modules/users/client/controllers/authentication.client.controller.js +++ b/modules/users/client/controllers/authentication.client.controller.js @@ -183,7 +183,10 @@ NotifycationService.showNotify('info', null, $translate.instant('SIGN.SIGNIN_WELCOME_NORMAL', {name: response.displayName})); } if (vm.authentication.user.status === 'idle') { - NotifycationService.showNotify('error', null, $translate.instant('SIGN.SIGNIN_WELCOME_IDLE', {name: response.displayName})); + NotifycationService.showNotify('error', null, $translate.instant('SIGN.SIGNIN_WELCOME_IDLE', { + name: response.displayName, + days: (vm.signConfig.idle.accountIdleForTime / (60 * 60 * 1000 * 24)) + })); } // And redirect to the previous or home page $state.go($state.previous.state.name || 'home', $state.previous.params); diff --git a/modules/users/client/controllers/status/status.client.controller.js b/modules/users/client/controllers/status/status.client.controller.js index 38f90168..53ed0f0c 100644 --- a/modules/users/client/controllers/status/status.client.controller.js +++ b/modules/users/client/controllers/status/status.client.controller.js @@ -24,7 +24,7 @@ closeButtonText: $translate.instant('ACTIVE_IDLE_CONFIRM_CANCEL'), actionButtonText: $translate.instant('ACTIVE_IDLE_CONFIRM_OK'), headerText: $translate.instant('ACTIVE_IDLE_CONFIRM_HEADER_TEXT'), - bodyText: $translate.instant('ACTIVE_IDLE_CONFIRM_BODY_TEXT', {score: vm.signConfig.activeIdleAccountScore}) + bodyText: $translate.instant('ACTIVE_IDLE_CONFIRM_BODY_TEXT', {score: vm.signConfig.idle.activeIdleAccountBasicScore}) }; ModalConfirmService.showModal({}, modalOptions) diff --git a/modules/users/server/config/strategies/local.js b/modules/users/server/config/strategies/local.js index 8a909dd7..32ef6c7f 100644 --- a/modules/users/server/config/strategies/local.js +++ b/modules/users/server/config/strategies/local.js @@ -54,12 +54,12 @@ module.exports = function () { }); } - if ((moment(Date.now()) - moment(user.last_signed)) > signConfig.accountIdleForTime) { - user.update({ - $set: {status: 'idle'} - }).exec(); - user.status = 'idle'; - } + // if ((moment(Date.now()) - moment(user.last_signed)) > signConfig.idle.accountIdleForTime) { + // user.update({ + // $set: {status: 'idle'} + // }).exec(); + // user.status = 'idle'; + // } user.updateSignedTime(); diff --git a/modules/users/server/controllers/users/users.profile.server.controller.js b/modules/users/server/controllers/users/users.profile.server.controller.js index 63de8bf4..abd11105 100644 --- a/modules/users/server/controllers/users/users.profile.server.controller.js +++ b/modules/users/server/controllers/users/users.profile.server.controller.js @@ -259,13 +259,13 @@ exports.unIdle = function (req, res, next) { var user = req.user; if (user) { - if (user.score < signConfig.activeIdleAccountScore) { + if (user.score < signConfig.idle.activeIdleAccountBasicScore) { return res.status(422).send({ message: 'SERVER.SCORE_NOT_ENOUGH' }); } else { //update score - scoreUpdate(req, user, scoreConfig.action.activeIdleAccount, -(signConfig.activeIdleAccountScore)); + scoreUpdate(req, user, scoreConfig.action.activeIdleAccount, -(signConfig.idle.activeIdleAccountBasicScore)); user.status = 'normal'; req.login(user, function (err) { @@ -279,7 +279,7 @@ exports.unIdle = function (req, res, next) { //create trace log traceLogCreate(req, traceConfig.action.userUnIdle, { user: req.user._id, - score: signConfig.activeIdleAccountScore + score: signConfig.idle.activeIdleAccountBasicScore }); } } else {