✏️ 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
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function checkIn()
|
public function signIn()
|
||||||
{
|
{
|
||||||
if ($aquired_score = $this->user->checkIn()) {
|
if ($this->user->canSignIn()) {
|
||||||
|
$acuiredScore = $this->user->signIn();
|
||||||
|
|
||||||
return json([
|
return json([
|
||||||
'errno' => 0,
|
'errno' => 0,
|
||||||
'msg' => trans('user.checkin-success', ['score' => $aquired_score]),
|
'msg' => trans('user.sign-in-success', ['score' => $acuiredScore]),
|
||||||
'score' => $this->user->getScore(),
|
'score' => $this->user->getScore(),
|
||||||
'remaining_time' => $this->user->canCheckIn(true)
|
'remaining_time' => round($this->user->getSignInRemainingTime() / 3600)
|
||||||
]);
|
]);
|
||||||
} else {
|
} 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
|
* @param Request $request
|
||||||
* @return void
|
* @return void
|
||||||
|
|
@ -130,7 +132,7 @@ class UserController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Avatar for User
|
* Set user avatar.
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ Route::group(['prefix' => 'auth'], function ()
|
||||||
Route::group(['middleware' => 'auth', 'prefix' => 'user'], function ()
|
Route::group(['middleware' => 'auth', 'prefix' => 'user'], function ()
|
||||||
{
|
{
|
||||||
Route::any ('', 'UserController@index');
|
Route::any ('', 'UserController@index');
|
||||||
Route::any ('/checkin', 'UserController@checkIn');
|
Route::any ('/sign-in', 'UserController@signIn');
|
||||||
|
|
||||||
// Profile
|
// Profile
|
||||||
Route::get ('/profile', 'UserController@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
|
* @return int|bool
|
||||||
*/
|
*/
|
||||||
public function checkIn()
|
public function signIn()
|
||||||
{
|
{
|
||||||
if ($this->canCheckIn()) {
|
if ($this->canSignIn()) {
|
||||||
$sign_score = explode(',', option('sign_score'));
|
|
||||||
$aquired_score = rand($sign_score[0], $sign_score[1]);
|
$scoreLimits = explode(',', option('sign_score'));
|
||||||
$this->setScore($aquired_score, 'plus');
|
$acquiredScore = rand($scoreLimits[0], $scoreLimits[1]);
|
||||||
|
|
||||||
|
$this->setScore($acquiredScore, 'plus');
|
||||||
$this->last_sign_at = Utils::getTimeFormatted();
|
$this->last_sign_at = Utils::getTimeFormatted();
|
||||||
$this->save();
|
$this->save();
|
||||||
return $aquired_score;
|
|
||||||
|
return $acquiredScore;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
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 Time in seconds.
|
||||||
* @return int|bool
|
|
||||||
*/
|
*/
|
||||||
public function canCheckIn($return_remaining_time = false)
|
public function getSignInRemainingTime()
|
||||||
{
|
{
|
||||||
// convert to timestamp
|
// convert to timestamp
|
||||||
$last_sign_at = strtotime($this->getLastSignTime());
|
$lastSignInTime = strtotime($this->getLastSignInTime());
|
||||||
|
|
||||||
if (option('sign_after_zero') == "1") {
|
return option('sign_after_zero') ? (Carbon::tomorrow()->timestamp - time()) : ($lastSignInTime + option('sign_gap_time') * 3600 - time());
|
||||||
$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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
* @return string Formatted time string.
|
||||||
*/
|
*/
|
||||||
public function getLastSignTime()
|
public function getLastSignInTime()
|
||||||
{
|
{
|
||||||
return $this->last_sign_at;
|
return $this->last_sign_at;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ if (! function_exists('bs_footer')) {
|
||||||
{
|
{
|
||||||
$scripts = [
|
$scripts = [
|
||||||
assets('js/app.min.js'),
|
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')
|
assets('js/general.js')
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
* @Author: printempw
|
* @Author: printempw
|
||||||
* @Date: 2016-07-16 10:02:24
|
* @Date: 2016-07-16 10:02:24
|
||||||
* @Last Modified by: printempw
|
* @Last Modified by: printempw
|
||||||
* @Last Modified time: 2017-01-02 11:15:33
|
* @Last Modified time: 2017-01-17 22:35:58
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
@ -619,16 +619,16 @@ function deleteAccount() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkin() {
|
function signIn() {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: "./user/checkin",
|
url: "./user/sign-in",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function(json) {
|
success: function(json) {
|
||||||
if (json.errno == 0) {
|
if (json.errno == 0) {
|
||||||
$('#score').html(json.score);
|
$('#score').html(json.score);
|
||||||
var dom = '<i class="fa fa-calendar-check-o"></i> ' + trans('user.checkinRemainTime', { time: String(json.remaining_time) });
|
var dom = '<i class="fa fa-calendar-check-o"></i> ' + trans('user.signInRemainingTime', { time: String(json.remaining_time) });
|
||||||
$('#checkin-button').attr('disabled', 'disabled').html(dom);
|
$('#sign-in-button').attr('disabled', 'disabled').html(dom);
|
||||||
|
|
||||||
swal({
|
swal({
|
||||||
type: 'success',
|
type: 'success',
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
* @Author: printempw
|
* @Author: printempw
|
||||||
* @Date: 2016-07-16 09:02:32
|
* @Date: 2016-07-16 09:02:32
|
||||||
* @Last Modified by: printempw
|
* @Last Modified by: printempw
|
||||||
* @Last Modified time: 2016-09-26 22:35:35
|
* @Last Modified time: 2017-01-17 22:51:55
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$.locales = {};
|
$.locales = {};
|
||||||
|
|
@ -115,6 +115,11 @@ function showMsg(msg, type) {
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
function showAjaxError(json) {
|
function showAjaxError(json) {
|
||||||
|
if (!json.responseText) {
|
||||||
|
console.warn('Empty Ajax response body.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
showModal(json.responseText.replace(/\n/g, '<br />'), trans('utils.fatalError'), 'danger');
|
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.'
|
deleteNotice: 'Are you sure to delete this texture? Scores will be returned.'
|
||||||
},
|
},
|
||||||
user: {
|
user: {
|
||||||
checkinRemainTime: 'Available after :time hours',
|
signInRemainingTime: 'Available after :time hours',
|
||||||
|
|
||||||
// Closet
|
// Closet
|
||||||
switch2dPreview: 'Switch to 2D Preview',
|
switch2dPreview: 'Switch to 2D Preview',
|
||||||
|
|
@ -94,13 +94,6 @@
|
||||||
changeEmail: 'Sure to change your email address to :new_email?',
|
changeEmail: 'Sure to change your email address to :new_email?',
|
||||||
emptyDeletePassword: 'Please enter the current password:'
|
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: {
|
admin: {
|
||||||
// Change User Profile
|
// Change User Profile
|
||||||
newUserEmail: 'Please enter the new email:',
|
newUserEmail: 'Please enter the new email:',
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,11 @@ used:
|
||||||
|
|
||||||
cur-score: Current Score
|
cur-score: Current Score
|
||||||
score-notice: Click the score to show introduction.
|
score-notice: Click the score to show introduction.
|
||||||
checkin: Check In
|
sign-in: Sign In
|
||||||
checkin-success: Checked in successfully. You got :score scores~
|
sign-in-success: Signed in successfully. You got :score scores.
|
||||||
cant-checkin-until: You can only check in after :time hours
|
cant-sign-in-until: You can't sign in in :time hours
|
||||||
last-checkin: Last checked in at :time
|
last-sign-in: Last signed in at :time
|
||||||
checkin-remain-time: Available after :time hours
|
sign-in-remain-time: Available after :time hours
|
||||||
announcement: Announcement
|
announcement: Announcement
|
||||||
|
|
||||||
score-intro:
|
score-intro:
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@
|
||||||
deleteNotice: '真的要删除此材质吗?积分将会被返还'
|
deleteNotice: '真的要删除此材质吗?积分将会被返还'
|
||||||
},
|
},
|
||||||
user: {
|
user: {
|
||||||
checkinRemainTime: ':time 小时后可签到',
|
signInRemainingTime: ':time 小时后可签到',
|
||||||
|
|
||||||
// Closet
|
// Closet
|
||||||
switch2dPreview: '切换 2D 预览',
|
switch2dPreview: '切换 2D 预览',
|
||||||
|
|
@ -94,13 +94,6 @@
|
||||||
changeEmail: '确定要将用户邮箱更改为 :new_email 吗?',
|
changeEmail: '确定要将用户邮箱更改为 :new_email 吗?',
|
||||||
emptyDeletePassword: '请先输入当前用户密码'
|
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: {
|
admin: {
|
||||||
// Change User Profile
|
// Change User Profile
|
||||||
newUserEmail: '请输入新邮箱:',
|
newUserEmail: '请输入新邮箱:',
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,11 @@ used:
|
||||||
|
|
||||||
cur-score: 当前积分
|
cur-score: 当前积分
|
||||||
score-notice: 点击积分查看说明
|
score-notice: 点击积分查看说明
|
||||||
checkin: 每日签到
|
sign-in: 每日签到
|
||||||
checkin-success: 签到成功,获得了 :score 积分~
|
sign-in-success: 签到成功,获得了 :score 积分~
|
||||||
cant-checkin-until: :time 小时后才能再次签到哦~
|
cant-sign-in-until: :time 小时后才能再次签到哦~
|
||||||
last-checkin: 上次签到于 :time
|
last-sign-in: 上次签到于 :time
|
||||||
checkin-remain-time: :time 小时后可签到
|
sign-in-remain-time: :time 小时后可签到
|
||||||
announcement: 公告
|
announcement: 公告
|
||||||
|
|
||||||
score-intro:
|
score-intro:
|
||||||
|
|
|
||||||
|
|
@ -73,13 +73,13 @@
|
||||||
</div><!-- /.row -->
|
</div><!-- /.row -->
|
||||||
</div><!-- ./box-body -->
|
</div><!-- ./box-body -->
|
||||||
<div class="box-footer">
|
<div class="box-footer">
|
||||||
@if ($user->canCheckIn())
|
@if ($user->canSignIn())
|
||||||
<button id="checkin-button" class="btn btn-primary pull-left" onclick="checkin()">
|
<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.checkin') }}
|
<i class="fa fa-calendar-check-o" aria-hidden="true"></i> {{ trans('user.sign-in') }}
|
||||||
</button>
|
</button>
|
||||||
@else
|
@else
|
||||||
<button class="btn btn-primary pull-left" title="{{ trans('user.last-checkin', ['time' => $user->getLastSignTime()]) }}" disabled="disabled">
|
<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.checkin-remain-time', ['time' => $user->canCheckIn(true)]) }}
|
<i class="fa fa-calendar-check-o" aria-hidden="true"></i> {{ trans('user.sign-in-remain-time', ['time' => round($user->getSignInRemainingTime() / 3600)]) }}
|
||||||
</button>
|
</button>
|
||||||
@endif
|
@endif
|
||||||
</div><!-- /.box-footer -->
|
</div><!-- /.box-footer -->
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user