2018-01-24 01:36:47 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2018-01-24 19:26:00 +09:00
|
|
|
use App\Models\ForUser;
|
|
|
|
|
2018-01-24 05:33:53 +09:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2018-01-24 01:36:47 +09:00
|
|
|
use Illuminate\Http\Request;
|
2018-02-06 01:37:45 +09:00
|
|
|
use Illuminate\Http\Response;
|
2018-01-24 01:36:47 +09:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2018-02-07 00:58:54 +09:00
|
|
|
use Tymon\JWTAuth\Facades\JWTAuth;
|
|
|
|
use Tymon\JWTAuth\Exceptions\JWTException;
|
2018-01-24 01:36:47 +09:00
|
|
|
|
|
|
|
class UserController extends Controller {
|
2018-02-27 01:12:06 +09:00
|
|
|
public function __construct() {}
|
|
|
|
|
2018-02-07 16:21:15 +09:00
|
|
|
// User
|
2018-02-02 18:27:57 +09:00
|
|
|
public function getUsers() { // /api/rpc/user/user/getusers
|
2018-02-07 22:24:41 +09:00
|
|
|
return DB::table('users')
|
|
|
|
->join('usr_details', 'usr_details.user_id', '=', 'users.id')
|
|
|
|
->join('usr_profile', 'usr_profile.user_id', '=', 'users.id')
|
|
|
|
->join('usr_perm_id', 'usr_perm_id.user_id', '=', 'users.id')
|
2018-02-10 08:36:45 +09:00
|
|
|
->get(array(
|
2018-02-14 05:49:49 +09:00
|
|
|
'id',
|
|
|
|
'username',
|
|
|
|
'perm_id',
|
|
|
|
'email',
|
|
|
|
'reg_date',
|
|
|
|
'gender',
|
|
|
|
'ip_address',
|
|
|
|
'avatar',
|
|
|
|
'name_style',
|
|
|
|
'display_name',
|
|
|
|
'country'
|
2018-02-10 08:36:45 +09:00
|
|
|
));
|
2018-01-24 01:36:47 +09:00
|
|
|
}
|
|
|
|
|
2018-02-02 18:27:57 +09:00
|
|
|
public function getUser($id) { // /api/rpc/user/user/getuser/id
|
2018-02-07 22:24:41 +09:00
|
|
|
return DB::table('users')
|
|
|
|
->join('usr_details', 'usr_details.user_id', '=', 'users.id')
|
|
|
|
->join('usr_profile', 'usr_profile.user_id', '=', 'users.id')
|
|
|
|
->join('usr_perm_id', 'usr_perm_id.user_id', '=', 'users.id')
|
2018-01-30 18:38:55 +09:00
|
|
|
->where('id', $id)
|
2018-02-07 21:38:42 +09:00
|
|
|
->get(array(
|
2018-02-14 05:49:49 +09:00
|
|
|
'users.id',
|
2018-02-07 21:38:42 +09:00
|
|
|
'username',
|
|
|
|
'perm_id',
|
|
|
|
'member_title',
|
|
|
|
'reg_date',
|
|
|
|
'website_address',
|
|
|
|
'website_name',
|
|
|
|
'gender',
|
|
|
|
'location',
|
|
|
|
'birthday',
|
|
|
|
'bio',
|
|
|
|
'avatar',
|
|
|
|
'strikes',
|
|
|
|
'name_style',
|
|
|
|
'display_name',
|
|
|
|
'yt_channel',
|
|
|
|
'country',
|
|
|
|
// TODO: hide the following stuff away from unprivileaged users.
|
|
|
|
'email',
|
|
|
|
'ip_address',
|
|
|
|
'strikes'
|
|
|
|
));
|
2018-01-30 18:38:55 +09:00
|
|
|
}
|
|
|
|
|
2018-02-15 22:43:45 +09:00
|
|
|
public function getExist($username, $email) { // /api/rpc/user/user/getexist/username/email
|
|
|
|
$isExist = DB::table('users')
|
|
|
|
->select('username', 'email')
|
|
|
|
->where('username', mb_strtolower($username))
|
|
|
|
->orWhere('email', mb_strtolower($email))
|
|
|
|
->get();
|
|
|
|
|
|
|
|
return $isExist->count();
|
|
|
|
}
|
|
|
|
|
2018-02-06 19:51:43 +09:00
|
|
|
public function getPostStyle($id) { // /api/rpc/user/user/getpoststyle/id
|
2018-02-15 22:43:45 +09:00
|
|
|
return DB::table('users')
|
2018-02-06 19:51:43 +09:00
|
|
|
->select('header', 'footer')
|
|
|
|
->where('id', $id)
|
|
|
|
->get();
|
|
|
|
}
|
|
|
|
|
2018-02-15 00:54:43 +09:00
|
|
|
public function getGroupName($id) { // /api/rpc/user/user/getgroupname/id
|
|
|
|
return DB::table('usr_perm_module')
|
|
|
|
->join('usr_perm_id', 'usr_perm_id.perm_id', '=', 'usr_perm_module.id')
|
|
|
|
->where('user_id', $id)
|
|
|
|
->get(array(
|
|
|
|
'name',
|
|
|
|
// 'badge' (this is a pipeline feature, please don't uncomment for now!)
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2018-02-02 18:27:57 +09:00
|
|
|
public function getGroupColours() { // /api/rpc/user/user/getgroupcolours
|
2018-01-30 18:38:55 +09:00
|
|
|
return DB::table('usr_perm_module')
|
|
|
|
->select(
|
2018-01-30 18:43:30 +09:00
|
|
|
'id',
|
2018-01-30 18:38:55 +09:00
|
|
|
'colour_m',
|
|
|
|
'colour_f',
|
|
|
|
'colour_u'
|
|
|
|
)
|
|
|
|
->get();
|
2018-01-24 01:36:47 +09:00
|
|
|
}
|
2018-02-06 01:37:45 +09:00
|
|
|
|
2018-02-07 16:21:15 +09:00
|
|
|
// Owner
|
|
|
|
public function countOwnersOfEntry($file_id) { // /api/rpc/user/owner/countownersofentry/id
|
|
|
|
return DB::table('str_owners')
|
|
|
|
->where('file_id', $file_id)
|
|
|
|
->count();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOwnersOfEntry($file_id) { // /api/rpc/user/owner/getownersofentry/id
|
|
|
|
return DB::table('str_owners')
|
|
|
|
->join('str_file', 'str_owners.file_id', '=', 'str_file.id')
|
2018-02-07 22:24:41 +09:00
|
|
|
->join('users', 'str_owners.user_id', '=', 'users.id')
|
2018-02-07 21:38:42 +09:00
|
|
|
->join('usr_details', 'usr_details.user_id', '=', 'str_owners.user_id')
|
|
|
|
->join('usr_profile', 'usr_profile.user_id', '=', 'str_owners.user_id')
|
|
|
|
->join('usr_perm_id', 'usr_perm_id.user_id', '=', 'str_owners.user_id')
|
2018-02-07 16:21:15 +09:00
|
|
|
->where('file_id', $file_id)
|
|
|
|
->get(array(
|
2018-02-16 23:09:35 +09:00
|
|
|
'users.id',
|
|
|
|
'title',
|
|
|
|
'version',
|
|
|
|
'views',
|
|
|
|
'downloads',
|
|
|
|
'submit_date',
|
|
|
|
'last_date',
|
|
|
|
'username',
|
|
|
|
'avatar',
|
|
|
|
'perm_id',
|
|
|
|
'gender',
|
|
|
|
'display_name',
|
|
|
|
'name_style',
|
2018-02-07 16:21:15 +09:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function countEntriesOfOwner($user_id) { // /api/rpc/user/owner/countentriesofowner/id
|
|
|
|
return DB::table('str_owners')
|
|
|
|
->where('user_id', $user_id)
|
|
|
|
->count();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getEntriesOfOwner($user_id) { // /api/rpc/user/owner/getentriesofowner/id
|
|
|
|
return DB::table('str_owners')
|
|
|
|
->join('str_file', 'str_owners.file_id', '=', 'str_file.id')
|
2018-02-07 22:24:41 +09:00
|
|
|
->join('users', 'str_owners.user_id', '=', 'users.id')
|
2018-02-07 21:38:42 +09:00
|
|
|
->join('usr_details', 'usr_details.user_id', '=', 'str_owners.user_id')
|
|
|
|
->join('usr_profile', 'usr_profile.user_id', '=', 'str_owners.user_id')
|
|
|
|
->join('usr_perm_id', 'usr_perm_id.user_id', '=', 'str_owners.user_id')
|
2018-02-07 16:21:15 +09:00
|
|
|
->where('user_id', $user_id)
|
|
|
|
->get(array(
|
2018-02-16 23:09:35 +09:00
|
|
|
'users.id',
|
|
|
|
'title',
|
|
|
|
'version',
|
|
|
|
'views',
|
|
|
|
'downloads',
|
|
|
|
'submit_date',
|
|
|
|
'last_date',
|
|
|
|
'username',
|
|
|
|
'avatar',
|
|
|
|
'perm_id',
|
|
|
|
'gender',
|
|
|
|
'display_name',
|
|
|
|
'name_style',
|
2018-02-07 16:21:15 +09:00
|
|
|
));
|
|
|
|
}
|
2018-02-16 23:09:35 +09:00
|
|
|
|
|
|
|
public function getTotalPostCount($id) { // /api/rpc/user/user/gettotalpostcount/id
|
|
|
|
return DB::table('usr_details')
|
|
|
|
->select('total_posts')
|
|
|
|
->where('user_id', $id)
|
|
|
|
->first()->total_posts;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTotalTopicCount($id) { // /api/rpc/user/user/gettotaltopiccount/id
|
|
|
|
return DB::table('usr_details')
|
|
|
|
->select('total_threads')
|
|
|
|
->where('user_id', $id)
|
|
|
|
->first()->total_threads;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function updateTotalPostCount(Request $request) { // /api/rpc/user/user/updatetotalpostcount
|
|
|
|
$getPC = $this->getTotalPostCount($request->user_id);
|
|
|
|
$getPC++;
|
|
|
|
|
|
|
|
return DB::table('usr_details')
|
|
|
|
->where('user_id', $request->user_id)
|
|
|
|
->update([
|
|
|
|
'total_posts' => $getPC
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function updateTotalTopicCount(Request $request) { // /api/rpc/user/user/updatetotaltopiccount
|
|
|
|
$getPC = $this->getTotalPostCount($request->user_id);
|
|
|
|
$getTC = $this->getTotalTopicCount($request->user_id);
|
|
|
|
$getPC++;
|
|
|
|
$getTC++;
|
|
|
|
|
|
|
|
return DB::table('usr_details')
|
|
|
|
->where('user_id', $request->user_id)
|
|
|
|
->update([
|
|
|
|
'total_posts' => $getPC,
|
|
|
|
'total_threads' => $getTC
|
|
|
|
]);
|
|
|
|
}
|
2018-01-24 01:36:47 +09:00
|
|
|
}
|