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

157 行
5.6 KiB
PHP
Raw 通常表示 履歴

2018-01-24 01:36:47 +09:00
<?php
namespace App\Http\Controllers;
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;
2020-10-06 11:22:46 +09:00
// use Illuminate\Support\Facades\Log;
2018-01-24 01:36:47 +09:00
use App\Http\Controllers\AuthController;
2018-03-02 00:59:26 +09:00
2020-10-06 11:22:46 +09:00
use App\Http\Controllers\User\Login;
use App\Http\Controllers\User\Notification;
use App\Http\Controllers\User\Profile;
use App\Http\Controllers\User\Register;
2018-01-24 01:36:47 +09:00
class UserController extends Controller {
private $objAuth;
2020-10-06 11:22:46 +09:00
private $valid;
2020-10-06 11:22:46 +09:00
public function __construct () {
2021-03-06 00:07:37 +09:00
if (isset($_COOKIE['language'])) app()->setLocale($_COOKIE['language']);
$this->objAuth = new AuthController();
2020-09-23 14:15:07 +09:00
$this->menu = getPagesInMenu();
$this->cook = (isset($_COOKIE['kero_token']) ? $_COOKIE['kero_token'] : '');
2020-10-06 11:22:46 +09:00
$this->id = checkLegit($this->cook);
2020-09-23 14:15:07 +09:00
$this->user = $this->getLoggedUser($this->id, $this->cook);
}
2020-10-06 11:22:46 +09:00
public function profile ($id) {
$r = new Profile($this->objAuth, $this->getUser($id, $this->cook), $this->getCountries(), $this->menu, $this->user);
return $r->index($id, $this->cook);
}
2020-02-02 13:39:53 +09:00
2020-10-06 11:22:46 +09:00
public function editProfile ($id, Request $rr) {
$r = new Profile($this->objAuth, $this->getUser($id, $this->cook), $this->getCountries(), $this->menu, $this->user);
return $r->edit($id, $rr);
}
2020-01-06 18:24:32 +09:00
2020-10-06 11:22:46 +09:00
public function login (Request $rr) {
$r = new Login($this->objAuth, $this->menu, $this->user);
return $r->index($rr);
}
2020-01-06 18:24:32 +09:00
2020-10-06 11:22:46 +09:00
public function register (Request $rr) {
$r = new Register($this->objAuth, $this->getCountries(), $this->menu, $this->user);
return $r->index($rr);
2020-02-02 13:39:53 +09:00
}
2020-01-06 18:24:32 +09:00
2020-10-06 11:22:46 +09:00
public function getNotification () {
$r = new Notification();
return $r->get();
2020-02-02 14:21:33 +09:00
}
2020-10-06 11:22:46 +09:00
public function addNotification ($uid, $aid, $txt, $sec, $goto) {
$r = new Notification();
return $r->add($uid, $aid, $txt, $sec, $goto);
2020-02-02 14:21:33 +09:00
}
2020-10-06 11:22:46 +09:00
public function delNotification ($id) {
$r = new Notification();
return $r->delete($id);
}
function getUser ($id, $kero) {
$check = 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();
2020-10-08 11:03:51 +09:00
if (!$get) return false;
2020-02-02 13:39:53 +09:00
$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'].'/img/noicon.jpg';
}
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-10-07 19:53:50 +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-02-02 13:39:53 +09:00
2020-01-06 18:24:32 +09:00
return $get;
}
2020-10-06 11:22:46 +09:00
function getLoggedUser ($id, $kero) {
$check = checkLegit($kero);
if ($check == 0) return 0;
$valid = $this->objAuth->getPermissions($kero);
$cols = $this->getGroupColours()->toArray();
$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);
2020-10-06 15:53:26 +09:00
$perm_id = DB::table('usr_perm_id')->select('perm_id')->where('user_id', $get->id)->first()->perm_id;
$ucol = DB::table('usr_perm_module')->select('id', 'colour_m', 'colour_f', 'colour_u')->get();
if (!empty($get->profile->name_style)) $get->profile->name_style = $get->profile->name_style;
else {
foreach ($ucol as $j3) {
if ($j3->id == $perm_id) {
if ($get->profile->gender == 1) $get->profile->name_style = $j3->colour_m;
else if ($get->profile->gender == 2) $get->profile->name_style = $j3->colour_f;
else $get->profile->name_style = $j3->colour_u;
}
}
}
2020-10-06 11:22:46 +09:00
$get->perm = $valid;
if (empty($get->profile->avatar) || $get->profile->avatar == '') $get->profile->avatar = 'img/noicon.jpg';
2020-10-06 15:53:26 +09:00
$get->profile->avatar = '/'.$get->profile->avatar;
2020-10-06 11:22:46 +09:00
return $get;
}
function getCountries () {
2020-03-01 22:12:50 +09:00
$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-10-06 11:22:46 +09:00
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'));
2019-03-17 07:00:22 +09:00
}
2020-10-06 11:22:46 +09:00
function getGroupColours() {
return DB::table('usr_perm_module')->select('id', 'colour_m', 'colour_f', 'colour_u')->get();
2019-03-17 07:00:22 +09:00
}
2018-01-24 01:36:47 +09:00
}