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

208 行
7.1 KiB
PHP
Raw 通常表示 履歴

2018-01-24 01:36:47 +09:00
<?php
namespace App\Http\Controllers;
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-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')
->select('*')
2018-02-07 22:24:41 +09:00
->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();
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')
->where('id', $id)
->get(array(
2018-02-07 22:24:41 +09:00
"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'
));
}
2018-02-06 19:51:43 +09:00
public function getPostStyle($id) { // /api/rpc/user/user/getpoststyle/id
2018-02-07 22:24:41 +09:00
return DB:: table('users')
2018-02-06 19:51:43 +09:00
->select('header', 'footer')
->where('id', $id)
->get();
}
2018-02-02 18:27:57 +09:00
public function getGroupColours() { // /api/rpc/user/user/getgroupcolours
return DB::table('usr_perm_module')
->select(
2018-01-30 18:43:30 +09:00
'id',
'name',
'colour_m',
'colour_f',
'colour_u'
// 'badge' (this is a pipeline feature, please don't uncomment for now!)
)
->get();
2018-01-24 01:36:47 +09:00
}
2018-02-06 01:37:45 +09:00
public function isAuth(Request $request) { // /apt/rpc/user/auth/isauth
return $request->cookie('username');
}
public function login(Request $request) { // /api/rpc/user/auth/login
2018-02-07 22:24:41 +09:00
$getUser = DB::table('users')
->select('id', 'username', 'password', 'remember_token')
2018-02-06 01:37:45 +09:00
->where('username', $request->username)
->get();
$login_ok = false;
try {
2018-02-07 00:58:54 +09:00
$check_password = hash('sha256', $request->password . $getUser[0]->salt);
2018-02-06 01:37:45 +09:00
2018-02-07 00:58:54 +09:00
for ($round = 0; $round < 65536; $round++) {
$check_password = hash('sha256', $check_password . $getUser[0]->salt);
}
if ($check_password === $getUser[0]->password) {
$login_ok = true;
2018-02-06 01:37:45 +09:00
$credentials = array(
"username" => $request->username,
"password" => $check_password
);
//dd($credentials);
2018-02-07 00:58:54 +09:00
try {
if (!$token = JWTAuth::attempt($credentials)) {
2018-02-07 00:58:54 +09:00
return response()->json(['error' => 'invalid_credentials'], 401);
}
} catch (JWTException $e) {
return response()->json(['error' => 'could_not_create_token'], 500);
2018-02-07 00:58:54 +09:00
}
return response()->json(['token' => "Bearer $token"]);
2018-02-06 01:37:45 +09:00
//return $_SERVER['HTTP_HOST'];
// setcookie("username", $_POST['username'], time()+3600*24*30*72, "/", $_SERVER['HTTP_HOST'], false, true);
// setcookie("password", $check_password, time()+3600*24*30*72, "/", $_SERVER['HTTP_HOST'], false, true);
2018-02-07 00:58:54 +09:00
//$cookieU = $request->cookie('username', $request->username, time()+3600*24*30*72);
//$cookieP = $request->cookie('password', $check_password, time()+3600*24*30*72);
2018-02-06 01:37:45 +09:00
2018-02-06 05:10:52 +09:00
//dd($cookieP);
2018-02-06 01:37:45 +09:00
//dd($request);
//dd($cookie->name));
2018-02-07 16:33:03 +09:00
//return response('')
//->cookie('username', $cookieU)
//->cookie('password', $cookieP);
2018-02-06 01:37:45 +09:00
}
2018-02-07 00:58:54 +09:00
return "bad";
2018-02-06 01:37:45 +09:00
}
catch (Exception $e) {
return $e->getMessage();
}
}
public function register(Request $request) { // /api/rpc/user/auth/register
return;
}
public function logout(Request $request) { // /api/rpc/user/auth/logout
return;
}
// public function passwordReset() {}
// public function confirmReset() {}
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')
->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-07 22:24:41 +09:00
"users.id",
2018-02-07 16:21:15 +09:00
"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')
->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-07 22:24:41 +09:00
"users.id",
2018-02-07 16:21:15 +09:00
"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-01-24 01:36:47 +09:00
}