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

180 行
6.4 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-06-23 19:22:16 +09:00
use Illuminate\Support\Facades\File;
2018-06-22 19:43:14 +09:00
use Illuminate\Support\Facades\Storage;
2019-12-05 18:32:20 +09:00
use Illuminate\Support\Facades\Cache;
2018-01-24 01:36:47 +09:00
use Illuminate\Http\Request;
2018-03-06 21:34:19 +09:00
use Illuminate\Contracts\Routing\ResponseFactory;
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
use App\Http\Controllers\AuthController;
2018-03-02 00:59:26 +09:00
2018-01-24 01:36:47 +09:00
class UserController extends Controller {
private $objAuth;
public function __construct() {
$this->objAuth = new AuthController();
}
2020-02-02 13:39:53 +09:00
public function getLoggedUser ($id, $kero) {
2020-01-06 18:24:32 +09:00
$check = $this->objAuth->checkLegit($kero);
2020-02-02 13:39:53 +09:00
if ($check == 0) return 0;
2020-01-06 18:24:32 +09:00
$valid = $this->objAuth->getPermissions($kero);
$cols = $this->getGroupColours()->toArray();
2020-02-02 13:39:53 +09:00
$get = DB::table('users')->where('id', $id)->first();
$get->profile = DB::table('usr_profile')->where('user_id', $id)->first();
$get->profile->showname = (!empty($get->profile->display_name) && !is_null($get->profile->display_name) ? $get->profile->display_name : $get->username);
if (empty($get->avatar) || $get->avatar == '') $get->avatar = '/usericon/haznoavaz.png';
2020-01-06 18:24:32 +09:00
2020-02-02 13:39:53 +09:00
return $get;
}
2020-01-06 18:24:32 +09:00
2020-02-02 14:21:33 +09:00
public function 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'));
}
public function getGroupColours() {
return DB::table('usr_perm_module')->select('id', 'colour_m', 'colour_f', 'colour_u')->get();
}
public function getUser ($id, $kero) {
2020-02-02 13:39:53 +09:00
$check = $this->objAuth->checkLegit($kero);
2020-01-06 18:24:32 +09:00
2020-02-02 13:39:53 +09:00
$valid = $this->objAuth->getPermissions($kero);
$cols = $this->getGroupColours()->toArray();
2020-01-06 18:24:32 +09:00
2020-02-02 13:39:53 +09:00
$get = DB::table('users')->where('id', $id)->first();
$get->details = DB::table('usr_details')->where('user_id', $id)->first();
$get->profile = DB::table('usr_profile')->where('user_id', $id)->first();
$get->contacts = DB::table('usr_contacts')->where('user_id', $id)->first();
$get->perm_id = DB::table('usr_perm_id')->where('user_id', $id)->first();
$get->perm_module = DB::table('usr_perm_module')->where('usr_perm_id', $get->perm_id->usr_per_id)->first();
if (is_null($get->profile->avatar) || empty($get->profile->avatar) || $get->profile->avatar == '') {
$get->profile->avatar = 'http'.(isset($_SERVER['HTTPS']) ? 's' : '').'://'.$_SERVER['HTTP_HOST'].'/usericon/haznoavaz.png';
}
else $get->profile->avatar = '/'.$get->profile->avatar;
2020-01-06 18:24:32 +09:00
2020-02-02 13:39:53 +09:00
$get->profile->gender_name = '不明';
if ($get->profile->gender == 1) $get->profile->gender_name = '男性';
else if ($get->profile->gender == 2) $get->profile->gender_name = '女性';
2020-01-07 22:48:29 +09:00
2020-02-02 13:39:53 +09:00
$get->details->reg_date = strftime('%Y年%m月%d日(%a)', $get->details->reg_date);
$get->profile->showname = (!empty($get->profile->display_name) && !is_null($get->profile->display_name) ? $get->profile->display_name : $get->username);
if ($id != $check) {
unset($get->password);
unset($get->kero_token);
unset($get->salt);
2020-01-06 18:24:32 +09:00
}
2020-02-02 13:39:53 +09:00
if ($valid['usr_emailshow'] == 0 || $id != $check) unset($get->email);
if ($valid['usr_ipshow'] == 0 || $id != $check) unset($get->profile->ip_address);
if ($valid['usr_canwarn'] == 0 || $id != $check) unset($get->details->strikes);
2020-01-06 18:24:32 +09:00
return $get;
}
2020-03-01 22:12:50 +09:00
public function getCountries () {
$flags = DB::table('nhn_country')->orderBy('id', 'asc')->get();
$res = array();
2018-03-02 00:59:26 +09:00
foreach ($flags as $flag) {
$protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
2018-03-02 00:59:26 +09:00
$res[] = array(
2020-03-01 22:12:50 +09:00
'value' => $flag->nameEng,
'label' => $flag->name
);
}
return $res;
}
2018-02-15 22:43:45 +09:00
2020-02-02 14:21:33 +09:00
public function avatarUpload(Request $r) {
2019-05-25 09:52:37 +09:00
$check = $this->objAuth->checkLegit($r->kero_token);
2018-02-15 22:43:45 +09:00
2020-02-02 14:21:33 +09:00
if ($check == 0) return 'Err!';
else {
2019-05-25 09:52:37 +09:00
$valid = $this->objAuth->getPermissions($r->kero_token);
$user = 0;
2019-05-25 09:52:37 +09:00
if ($valid['usr_editother'] == 1) $user = $r->id;
else $user = $check;
if ($valid['usr_editprofile'] == 1) {
2019-05-25 09:52:37 +09:00
if (isset($r->filename)) {
if (!is_dir('/usericon/'.$check)) {
if (!mkdir('/usericon/'.$check, 0755, true)) return 'Could not make folder '.$check.'<br />';
}
$img_dir = '/usericon/'.$check.'/';
2019-05-25 09:52:37 +09:00
$image = $img_dir . $r->filename;
2020-02-02 14:21:33 +09:00
$imageFileType = array('image/png', 'image/jpeg', 'image/gif');
if (!in_array($r->filetype, $imageFileType)) return "Only JPG, PNG, JPEG, and GIF are allowed.";
$fname = '/usericon/'.$user.'/'.$r->filename;
2019-05-25 09:52:37 +09:00
$data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $r->thefile));
Storage::disk('public')->put($fname, $data);
2019-05-25 09:52:37 +09:00
return $r->filename;
}
}
2020-02-02 14:21:33 +09:00
else return 'Permission denied.';
2018-08-03 14:28:41 +09:00
}
}
2019-03-17 07:00:22 +09:00
2019-12-05 18:32:20 +09:00
public function getNotification (Request $r) { // /api/rpc/user/notification/get
2019-05-25 09:52:37 +09:00
$check = $this->objAuth->checkLegit($r->kero_token);
2019-12-05 18:32:20 +09:00
$res = null;
2019-03-17 07:00:22 +09:00
if ($check != 0) {
2019-12-05 18:32:20 +09:00
if (Cache::has('getNotification')) $get = Cache::get('getNotification');
else {
2020-02-02 14:21:33 +09:00
$get = DB::table('usr_notification')->select('id', 'app_id', 'text', 'section', 'goto')->where('user_id', $check)->get();
2019-12-05 18:32:20 +09:00
$res = array();
2019-03-17 07:00:22 +09:00
2019-12-05 18:32:20 +09:00
foreach ($get as $g) {
$prot = DB::table('sys_settings')->select('protocol')->first()->protocol;
$goto = DB::table('sys_apps')->select('url')->where('id', $g->app_id)->first()->url;
2019-03-17 07:00:22 +09:00
2020-02-02 14:21:33 +09:00
$res[] = array('id' => $g->id, 'text' => $g->text, 'url' => 'http'.($prot == 1 ? 's' : '').'://'.$goto.'/#/'.$g->section);
2019-12-05 18:32:20 +09:00
Cache::put('getNotification', $get);
}
2019-03-17 07:00:22 +09:00
}
return $res;
}
2019-12-05 18:32:20 +09:00
else return array();
2019-03-17 07:00:22 +09:00
}
2020-02-02 14:21:33 +09:00
public function addNotification(Request $r, $uid, $aid, $txt, $sec, $goto) {
2019-05-25 09:52:37 +09:00
$check = $this->objAuth->checkLegit($r->kero_token);
2019-03-17 07:00:22 +09:00
if ($check != 0) {
2020-02-02 14:21:33 +09:00
$add = DB::table('usr_notification')->insert(['user_id' => $uid, 'app_id' => $aid, 'text' => $txt, 'section' => $sec, 'goto' => $goto]);
2019-12-05 18:32:20 +09:00
if (Cache::has('getNotification')) Cache::forget('getNotification');
2019-03-17 07:00:22 +09:00
return 1;
}
}
2020-02-02 14:21:33 +09:00
public function delNotification(Request $r) {
2019-05-25 09:52:37 +09:00
$check = $this->objAuth->checkLegit($r->kero_token);
2019-03-17 07:00:22 +09:00
if ($check != 0) {
2020-02-02 14:21:33 +09:00
$del = DB::table('usr_notification')->where('id', $r->id)->where('user_id', $check)->delete();
2019-12-05 18:32:20 +09:00
if (Cache::has('getNotification')) Cache::forget('getNotification');
2020-02-02 14:21:33 +09:00
return $del;
2019-03-17 07:00:22 +09:00
}
}
2018-01-24 01:36:47 +09:00
}