154 行
5.5 KiB
PHP
154 行
5.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Http\Request;
|
|
// use Illuminate\Support\Facades\Log;
|
|
|
|
use App\Http\Controllers\AuthController;
|
|
|
|
use App\Http\Controllers\User\Login;
|
|
use App\Http\Controllers\User\Notification;
|
|
use App\Http\Controllers\User\Profile;
|
|
use App\Http\Controllers\User\Register;
|
|
|
|
class UserController extends Controller {
|
|
private $objAuth;
|
|
private $valid;
|
|
|
|
public function __construct () {
|
|
$this->objAuth = new AuthController();
|
|
$this->menu = getPagesInMenu();
|
|
$this->cook = (isset($_COOKIE['kero_token']) ? $_COOKIE['kero_token'] : '');
|
|
$this->id = checkLegit($this->cook);
|
|
$this->user = $this->getLoggedUser($this->id, $this->cook);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
public function login (Request $rr) {
|
|
$r = new Login($this->objAuth, $this->menu, $this->user);
|
|
return $r->index($rr);
|
|
}
|
|
|
|
public function register (Request $rr) {
|
|
$r = new Register($this->objAuth, $this->getCountries(), $this->menu, $this->user);
|
|
return $r->index($rr);
|
|
}
|
|
|
|
public function getNotification () {
|
|
$r = new Notification();
|
|
return $r->get();
|
|
}
|
|
|
|
public function addNotification ($uid, $aid, $txt, $sec, $goto) {
|
|
$r = new Notification();
|
|
return $r->add($uid, $aid, $txt, $sec, $goto);
|
|
}
|
|
|
|
public function delNotification ($id) {
|
|
$r = new Notification();
|
|
return $r->delete($id);
|
|
}
|
|
|
|
function getUser ($id, $kero) {
|
|
$check = checkLegit($kero);
|
|
|
|
$valid = $this->objAuth->getPermissions($kero);
|
|
$cols = $this->getGroupColours()->toArray();
|
|
|
|
$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'].'/img/noicon.webp';
|
|
}
|
|
else $get->profile->avatar = '/'.$get->profile->avatar;
|
|
|
|
$get->profile->gender_name = '不明';
|
|
if ($get->profile->gender == 1) $get->profile->gender_name = '男性';
|
|
else if ($get->profile->gender == 2) $get->profile->gender_name = '女性';
|
|
|
|
$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);
|
|
}
|
|
|
|
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);
|
|
|
|
return $get;
|
|
}
|
|
|
|
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);
|
|
$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;
|
|
}
|
|
}
|
|
}
|
|
|
|
$get->perm = $valid;
|
|
if (empty($get->profile->avatar) || $get->profile->avatar == '') $get->profile->avatar = 'img/noicon.webp';
|
|
$get->profile->avatar = '/'.$get->profile->avatar;
|
|
|
|
return $get;
|
|
}
|
|
|
|
function getCountries () {
|
|
$flags = DB::table('nhn_country')->orderBy('id', 'asc')->get();
|
|
$res = array();
|
|
|
|
foreach ($flags as $flag) {
|
|
$protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
|
|
|
|
$res[] = array(
|
|
'value' => $flag->nameEng,
|
|
'label' => $flag->name
|
|
);
|
|
}
|
|
|
|
return $res;
|
|
}
|
|
|
|
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'));
|
|
}
|
|
|
|
function getGroupColours() {
|
|
return DB::table('usr_perm_module')->select('id', 'colour_m', 'colour_f', 'colour_u')->get();
|
|
}
|
|
}
|