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

116 行
PHP
Raw 通常表示 履歴

2020-10-06 11:22:46 +09:00
<?php
namespace App\Http\Controllers\User;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
// use Illuminate\Support\Facades\Log;
class Profile {
private $auth;
private $get;
private $cntr;
private $menu;
private $user;
public function __construct ($a, $g, $c, $m, $u) {
$this->auth = $a;
$this->get = $g;
$this->cntr = $c;
$this->menu = $m;
$this->user = $u;
}
public function index ($id, $kero) {
2020-10-08 11:03:51 +09:00
if (!$this->get) return view('pages.site.notfound', ['menu' => $this->menu, 'user' => $this->user]);
2020-10-06 11:22:46 +09:00
return view('pages.site.profile', ['res' => $this->get, 'menu' => $this->menu, 'user' => $this->user]);
}
public function avatarUpload(Request $r) {
$check = checkLegit($r->kero_token);
if ($check == 0) return 'Err!';
else {
$valid = $this->auth->getPermissions($r->kero_token);
$user = 0;
if ($valid['usr_editother'] == 1) $user = $r->id;
else $user = $check;
if ($valid['usr_editprofile'] == 1) {
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.'/';
$image = $img_dir . $r->filename;
$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;
$data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $r->thefile));
Storage::disk('public')->put($fname, $data);
return $r->filename;
}
}
else return 'Permission denied.';
}
}
public function edit ($id, Request $r) {
$err = '';
$suc = '';
2020-10-08 11:03:51 +09:00
$valid = $this->auth->getPermissions($this->user->kero_token);
$user = $this->user->id;
if (($valid['usr_editother'] == 0 && $user != $id)) return view('pages.site.notallowed', ['menu' => $this->menu, 'user' => $this->user]);
2020-10-06 11:22:46 +09:00
if (isset($r->submit)) {
if (!is_null($r->password)) {
if ($r->password != $r->password_check) $err = '「パスワード」と「パスワード確認」が異なります。';
else {
$salt = dechex(mt_rand(0, 2147483647)) . dechex(mt_rand(0, 2147483647));
$passwd = hash('sha256', $r->password . $salt);
for ($round = 0; $round < 65536; $round++) { $passwd = hash('sha256', $passwd . $salt); }
$eduserp = DB::table('users')->where('id', $id)->update(['password' => $passwd, 'salt' => $salt]);
if (!$eduserp) $err = 'パスワードの編集失敗。';
}
}
$cheml = DB::table('users')->select('email')->where('id', $id)->first();
if ($err == '') {
if ($cheml->email != $r->email) {
$exeml = DB::table('users')->select('email')->where('email', $r->email)->count();
if ($exeml > 0) $err = '入力したメールアドレスはもう存在しています。';
else {
$edusere = DB::table('users')->where('id', $id)->update(['email' => $r->email]);
if (!$edusere) $err = 'メールアドレスの編集失敗。';
}
}
}
if ($err == '') {
$p = DB::table('usr_profile')->select('display_name', 'country', 'gender')->where('user_id', $id)->first();
$edprofile = 1;
if ($p->display_name != $r->display_name || $p->country != $r->country || $p->gender != $r->gender) {
$edprofile = DB::table('usr_profile')->where('user_id', $id)->update([
'display_name' => $r->display_name,
'country' => $r->country,
'gender' => $r->gender
]);
}
if (!$edprofile) $err = '表示名、お国、又は性別の編集失敗。';
else $suc = '編集しました!';
}
}
2020-10-08 11:03:51 +09:00
if (!$this->get) return view('pages.site.notfound', ['menu' => $this->menu, 'user' => $this->user]);
2020-10-06 11:22:46 +09:00
if ($this->user) return view('pages.site.profileedit', ['res' => $this->get, 'menu' => $this->menu, 'user' => $this->user, 'suc' => $suc, 'err' => $err, 'cnt' => $this->cntr]);
2020-10-08 11:03:51 +09:00
return view('pages.site.notfound', ['menu' => $this->menu, 'user' => $this->user]);
2020-10-06 11:22:46 +09:00
}
}