このリポジトリは2023-09-09にアーカイブされています。 ファイルの閲覧とクローンは可能ですが、プッシュ、イシューの作成、プルリクエストはできません。
076server/app/Http/Controllers/UserController.php

210 行
6.9 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\ForUser;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Log;
use Tymon\JWTAuth\Facades\JWTAuth;
use Tymon\JWTAuth\Exceptions\JWTException;
class UserController extends Controller {
public function __construct() {}
// User
public function getUsers() { // /api/rpc/user/user/getusers
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')
->get(array(
'id',
'username',
'perm_id',
'email',
'reg_date',
'gender',
'ip_address',
'avatar',
'name_style',
'display_name',
'country'
));
}
public function getUser($id) { // /api/rpc/user/user/getuser/id
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')
->where('id', $id)
->get(array(
'users.id',
'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'
));
}
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();
}
public function getPostStyle($id) { // /api/rpc/user/user/getpoststyle/id
return DB::table('users')
->select('header', 'footer')
->where('id', $id)
->get();
}
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!)
));
}
public function getGroupColours() { // /api/rpc/user/user/getgroupcolours
return DB::table('usr_perm_module')
->select(
'id',
'colour_m',
'colour_f',
'colour_u'
)
->get();
}
// 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')
->join('users', 'str_owners.user_id', '=', 'users.id')
->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')
->where('file_id', $file_id)
->get(array(
'users.id',
'title',
'version',
'views',
'downloads',
'submit_date',
'last_date',
'username',
'avatar',
'perm_id',
'gender',
'display_name',
'name_style',
));
}
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')
->join('users', 'str_owners.user_id', '=', 'users.id')
->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')
->where('user_id', $user_id)
->get(array(
'users.id',
'title',
'version',
'views',
'downloads',
'submit_date',
'last_date',
'username',
'avatar',
'perm_id',
'gender',
'display_name',
'name_style',
));
}
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
]);
}
}