mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2024-12-27 06:29:19 +08:00
✏️ use signing in instead of checking in
This commit is contained in:
parent
a0494ce3d0
commit
9ff5bbfcaa
@ -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
|
||||
*/
|
||||
|
@ -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');
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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')
|
||||
];
|
||||
|
||||
|
@ -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 = '<i class="fa fa-calendar-check-o"></i> ' + trans('user.checkinRemainTime', { time: String(json.remaining_time) });
|
||||
$('#checkin-button').attr('disabled', 'disabled').html(dom);
|
||||
var dom = '<i class="fa fa-calendar-check-o"></i> ' + trans('user.signInRemainingTime', { time: String(json.remaining_time) });
|
||||
$('#sign-in-button').attr('disabled', 'disabled').html(dom);
|
||||
|
||||
swal({
|
||||
type: 'success',
|
||||
|
@ -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, '<br />'), trans('utils.fatalError'), 'danger');
|
||||
}
|
||||
|
||||
|
@ -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:',
|
||||
|
@ -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:
|
||||
|
@ -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: '请输入新邮箱:',
|
||||
|
@ -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:
|
||||
|
@ -73,13 +73,13 @@
|
||||
</div><!-- /.row -->
|
||||
</div><!-- ./box-body -->
|
||||
<div class="box-footer">
|
||||
@if ($user->canCheckIn())
|
||||
<button id="checkin-button" class="btn btn-primary pull-left" onclick="checkin()">
|
||||
<i class="fa fa-calendar-check-o" aria-hidden="true"></i> {{ trans('user.checkin') }}
|
||||
@if ($user->canSignIn())
|
||||
<button id="sign-in-button" class="btn btn-primary pull-left" onclick="signIn()">
|
||||
<i class="fa fa-calendar-check-o" aria-hidden="true"></i> {{ trans('user.sign-in') }}
|
||||
</button>
|
||||
@else
|
||||
<button class="btn btn-primary pull-left" title="{{ trans('user.last-checkin', ['time' => $user->getLastSignTime()]) }}" disabled="disabled">
|
||||
<i class="fa fa-calendar-check-o" aria-hidden="true"></i> {{ trans('user.checkin-remain-time', ['time' => $user->canCheckIn(true)]) }}
|
||||
<button class="btn btn-primary pull-left" title="{{ trans('user.last-sign-in', ['time' => $user->getLastSignInTime()]) }}" disabled="disabled">
|
||||
<i class="fa fa-calendar-check-o" aria-hidden="true"></i> {{ trans('user.sign-in-remain-time', ['time' => round($user->getSignInRemainingTime() / 3600)]) }}
|
||||
</button>
|
||||
@endif
|
||||
</div><!-- /.box-footer -->
|
||||
|
Loading…
Reference in New Issue
Block a user