diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 5355fcd0..f5658645 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -29,21 +29,23 @@ class UserController extends Controller } /** - * Handle User Checking In + * Handle user signing in. * * @return void */ - public function checkIn() + public function signIn() { - if ($aquired_score = $this->user->checkIn()) { + if ($this->user->canSignIn()) { + $acuiredScore = $this->user->signIn(); + return json([ 'errno' => 0, - 'msg' => trans('user.checkin-success', ['score' => $aquired_score]), + 'msg' => trans('user.sign-in-success', ['score' => $acuiredScore]), 'score' => $this->user->getScore(), - 'remaining_time' => $this->user->canCheckIn(true) + 'remaining_time' => round($this->user->getSignInRemainingTime() / 3600) ]); } else { - return json(trans('user.cant-checkin-until', ['time' => $this->user->canCheckIn(true)]), 1); + return json(trans('user.cant-sign-in-until', ['time' => round($this->user->getSignInRemainingTime() / 3600)]), 1); } } @@ -53,7 +55,7 @@ class UserController extends Controller } /** - * Handle Changing Profile + * Handle changing user profile. * * @param Request $request * @return void @@ -130,7 +132,7 @@ class UserController extends Controller } /** - * Set Avatar for User + * Set user avatar. * * @param Request $request */ diff --git a/app/Http/Routes/web.php b/app/Http/Routes/web.php index c6ea2681..78a19dab 100644 --- a/app/Http/Routes/web.php +++ b/app/Http/Routes/web.php @@ -45,7 +45,7 @@ Route::group(['prefix' => 'auth'], function () Route::group(['middleware' => 'auth', 'prefix' => 'user'], function () { Route::any ('', 'UserController@index'); - Route::any ('/checkin', 'UserController@checkIn'); + Route::any ('/sign-in', 'UserController@signIn'); // Profile Route::get ('/profile', 'UserController@profile'); diff --git a/app/Models/User.php b/app/Models/User.php index 1dd20839..77223a66 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -275,52 +275,56 @@ class User extends Model } /** - * Check in for the user, return false if unavailable. + * Sign in for the user, return false if unavailable. * * @return int|bool */ - public function checkIn() + public function signIn() { - if ($this->canCheckIn()) { - $sign_score = explode(',', option('sign_score')); - $aquired_score = rand($sign_score[0], $sign_score[1]); - $this->setScore($aquired_score, 'plus'); + if ($this->canSignIn()) { + + $scoreLimits = explode(',', option('sign_score')); + $acquiredScore = rand($scoreLimits[0], $scoreLimits[1]); + + $this->setScore($acquiredScore, 'plus'); $this->last_sign_at = Utils::getTimeFormatted(); $this->save(); - return $aquired_score; + + return $acquiredScore; } else { return false; } } /** - * Check if checking in is available now. + * Get remaining time before next signing is available. * - * @param bool $return_remaining_time Return remaining time. - * @return int|bool + * @return int Time in seconds. */ - public function canCheckIn($return_remaining_time = false) + public function getSignInRemainingTime() { // convert to timestamp - $last_sign_at = strtotime($this->getLastSignTime()); + $lastSignInTime = strtotime($this->getLastSignInTime()); - if (option('sign_after_zero') == "1") { - $remaining_time = (Carbon::tomorrow()->timestamp - time()) / 3600; - $can_check_in = $last_sign_at <= Carbon::today()->timestamp; - } else { - $remaining_time = ($last_sign_at + option('sign_gap_time') * 3600 - time()) / 3600; - $can_check_in = $remaining_time <= 0; - } - - return $return_remaining_time ? round($remaining_time) : $can_check_in; + return option('sign_after_zero') ? (Carbon::tomorrow()->timestamp - time()) : ($lastSignInTime + option('sign_gap_time') * 3600 - time()); } /** - * Get the last time of checking in. + * Check if signing in is available now. + * + * @return bool + */ + public function canSignIn() + { + return ($this->getSignInRemainingTime() <= 0); + } + + /** + * Get the last time of signing in. * * @return string Formatted time string. */ - public function getLastSignTime() + public function getLastSignInTime() { return $this->last_sign_at; } diff --git a/app/helpers.php b/app/helpers.php index dd4dfe05..d3f7e07b 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -98,7 +98,7 @@ if (! function_exists('bs_footer')) { { $scripts = [ assets('js/app.min.js'), - assets('lang/'.session('locale', config('app.locale')).'/locale.js'), + assets('lang/'.config('app.locale').'/locale.js'), assets('js/general.js') ]; diff --git a/resources/assets/src/js/user.js b/resources/assets/src/js/user.js index 12f70361..a099f617 100644 --- a/resources/assets/src/js/user.js +++ b/resources/assets/src/js/user.js @@ -2,7 +2,7 @@ * @Author: printempw * @Date: 2016-07-16 10:02:24 * @Last Modified by: printempw - * @Last Modified time: 2017-01-02 11:15:33 + * @Last Modified time: 2017-01-17 22:35:58 */ 'use strict'; @@ -619,16 +619,16 @@ function deleteAccount() { }); } -function checkin() { +function signIn() { $.ajax({ type: "POST", - url: "./user/checkin", + url: "./user/sign-in", dataType: "json", success: function(json) { if (json.errno == 0) { $('#score').html(json.score); - var dom = '  ' + trans('user.checkinRemainTime', { time: String(json.remaining_time) }); - $('#checkin-button').attr('disabled', 'disabled').html(dom); + var dom = '  ' + trans('user.signInRemainingTime', { time: String(json.remaining_time) }); + $('#sign-in-button').attr('disabled', 'disabled').html(dom); swal({ type: 'success', diff --git a/resources/assets/src/js/utils.js b/resources/assets/src/js/utils.js index 8d406829..1eeaec0c 100644 --- a/resources/assets/src/js/utils.js +++ b/resources/assets/src/js/utils.js @@ -2,7 +2,7 @@ * @Author: printempw * @Date: 2016-07-16 09:02:32 * @Last Modified by: printempw - * @Last Modified time: 2016-09-26 22:35:35 + * @Last Modified time: 2017-01-17 22:51:55 */ $.locales = {}; @@ -115,6 +115,11 @@ function showMsg(msg, type) { * @return {void} */ function showAjaxError(json) { + if (!json.responseText) { + console.warn('Empty Ajax response body.'); + return; + } + showModal(json.responseText.replace(/\n/g, '
'), trans('utils.fatalError'), 'danger'); } diff --git a/resources/lang/en/locale.js b/resources/lang/en/locale.js index 404f1c77..426f0d59 100644 --- a/resources/lang/en/locale.js +++ b/resources/lang/en/locale.js @@ -65,7 +65,7 @@ deleteNotice: 'Are you sure to delete this texture? Scores will be returned.' }, user: { - checkinRemainTime: 'Available after :time hours', + signInRemainingTime: 'Available after :time hours', // Closet switch2dPreview: 'Switch to 2D Preview', @@ -94,13 +94,6 @@ changeEmail: 'Sure to change your email address to :new_email?', emptyDeletePassword: 'Please enter the current password:' }, - config: { - csl13_1Upper: 'v13.1 and upper (recommended)', - csl13_1Lower: 'lower than v13.1', - usm1_4Upper: 'v1.4 and upper (recommended)', - usm1_2To1_3: 'v1.2 to v1.3', - usm1_2Lower: 'lower than v1.2', - }, admin: { // Change User Profile newUserEmail: 'Please enter the new email:', diff --git a/resources/lang/en/user.yml b/resources/lang/en/user.yml index e067fa85..8f9fe0ca 100644 --- a/resources/lang/en/user.yml +++ b/resources/lang/en/user.yml @@ -5,11 +5,11 @@ used: cur-score: Current Score score-notice: Click the score to show introduction. -checkin: Check In -checkin-success: Checked in successfully. You got :score scores~ -cant-checkin-until: You can only check in after :time hours -last-checkin: Last checked in at :time -checkin-remain-time: Available after :time hours +sign-in: Sign In +sign-in-success: Signed in successfully. You got :score scores. +cant-sign-in-until: You can't sign in in :time hours +last-sign-in: Last signed in at :time +sign-in-remain-time: Available after :time hours announcement: Announcement score-intro: diff --git a/resources/lang/zh_CN/locale.js b/resources/lang/zh_CN/locale.js index 3c366315..0482e0da 100644 --- a/resources/lang/zh_CN/locale.js +++ b/resources/lang/zh_CN/locale.js @@ -65,7 +65,7 @@ deleteNotice: '真的要删除此材质吗?积分将会被返还' }, user: { - checkinRemainTime: ':time 小时后可签到', + signInRemainingTime: ':time 小时后可签到', // Closet switch2dPreview: '切换 2D 预览', @@ -94,13 +94,6 @@ changeEmail: '确定要将用户邮箱更改为 :new_email 吗?', emptyDeletePassword: '请先输入当前用户密码' }, - config: { - csl13_1Upper: '13.1 版及以上(推荐)', - csl13_1Lower: '13.1 版以下', - usm1_4Upper: '1.4 版及以上(推荐)', - usm1_2To1_3: '1.2 及 1.3 版', - usm1_2Lower: '1.2 版以下', - }, admin: { // Change User Profile newUserEmail: '请输入新邮箱:', diff --git a/resources/lang/zh_CN/user.yml b/resources/lang/zh_CN/user.yml index 8104a958..f6205a16 100644 --- a/resources/lang/zh_CN/user.yml +++ b/resources/lang/zh_CN/user.yml @@ -5,11 +5,11 @@ used: cur-score: 当前积分 score-notice: 点击积分查看说明 -checkin: 每日签到 -checkin-success: 签到成功,获得了 :score 积分~ -cant-checkin-until: :time 小时后才能再次签到哦~ -last-checkin: 上次签到于 :time -checkin-remain-time: :time 小时后可签到 +sign-in: 每日签到 +sign-in-success: 签到成功,获得了 :score 积分~ +cant-sign-in-until: :time 小时后才能再次签到哦~ +last-sign-in: 上次签到于 :time +sign-in-remain-time: :time 小时后可签到 announcement: 公告 score-intro: diff --git a/resources/views/user/index.tpl b/resources/views/user/index.tpl index a038cd77..5f504a55 100644 --- a/resources/views/user/index.tpl +++ b/resources/views/user/index.tpl @@ -73,13 +73,13 @@