|
1
|
|
|
<?php
|
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers;
|
|
4
|
|
|
use App\Creator;
|
|
5
|
|
|
use Illuminate\Foundation\Auth\User;
|
|
6
|
|
|
use Illuminate\Http\Request;
|
|
7
|
|
|
use App\Http\Requests;
|
|
8
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
9
|
|
|
use Illuminate\Support\Facades\Session;
|
|
10
|
|
|
use Illuminate\Support\Facades\DB;
|
|
11
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
12
|
|
|
|
|
13
|
|
|
class UserController extends Controller
|
|
14
|
|
|
{
|
|
15
|
|
|
/**
|
|
16
|
|
|
* Display a listing of the resource.
|
|
17
|
|
|
*
|
|
18
|
|
|
* @return \Illuminate\Http\Response
|
|
19
|
|
|
*/
|
|
20
|
|
|
public function index()
|
|
21
|
|
|
{
|
|
22
|
|
|
$user = Auth::user();
|
|
23
|
|
|
$creator = $user->creator;
|
|
24
|
|
|
$backer = $user->backer;
|
|
25
|
|
|
$zagladki = DB::select('select * from bookmarks where user_id = ?', [$user->id]);
|
|
26
|
|
|
return view('user.index',compact('creator','backer','zagladki'));
|
|
27
|
|
|
}
|
|
28
|
|
|
|
|
29
|
|
|
/**
|
|
30
|
|
|
* Show the form for creating a new resource.
|
|
31
|
|
|
*
|
|
32
|
|
|
* @return \Illuminate\Http\Response
|
|
33
|
|
|
*/
|
|
34
|
|
|
public function create()
|
|
35
|
|
|
{
|
|
36
|
|
|
//
|
|
37
|
|
|
}
|
|
38
|
|
|
|
|
39
|
|
|
/**
|
|
40
|
|
|
* Store a newly created resource in storage.
|
|
41
|
|
|
*
|
|
42
|
|
|
* @param \App\Http\Controllers\Request|Request $request
|
|
43
|
|
|
* @return \Illuminate\Http\Response
|
|
44
|
|
|
*/
|
|
45
|
|
|
public function store(Request $request)
|
|
|
|
|
|
|
46
|
|
|
{
|
|
47
|
|
|
//
|
|
48
|
|
|
}
|
|
49
|
|
|
|
|
50
|
|
|
/**
|
|
51
|
|
|
* Display the specified resource.
|
|
52
|
|
|
*
|
|
53
|
|
|
* @param int $id
|
|
54
|
|
|
* @return \Illuminate\Http\Response
|
|
55
|
|
|
*/
|
|
56
|
|
|
public function show($id)
|
|
|
|
|
|
|
57
|
|
|
{
|
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
}
|
|
61
|
|
|
|
|
62
|
|
|
/**
|
|
63
|
|
|
* Show the form for editing the specified resource.
|
|
64
|
|
|
*
|
|
65
|
|
|
* @param int $id
|
|
66
|
|
|
* @return \Illuminate\Http\Response
|
|
67
|
|
|
*/
|
|
68
|
|
|
public function edit($id)
|
|
|
|
|
|
|
69
|
|
|
{
|
|
70
|
|
|
//
|
|
71
|
|
|
}
|
|
72
|
|
|
|
|
73
|
|
|
/**
|
|
74
|
|
|
* Update the specified resource in storage.
|
|
75
|
|
|
*
|
|
76
|
|
|
* @param \App\Http\Controllers\Request|Request $request
|
|
77
|
|
|
* @param int $id
|
|
78
|
|
|
* @return \Illuminate\Http\Response
|
|
79
|
|
|
*/
|
|
80
|
|
|
public function update(Request $request, $id)
|
|
|
|
|
|
|
81
|
|
|
{
|
|
82
|
|
|
//
|
|
83
|
|
|
}
|
|
84
|
|
|
|
|
85
|
|
|
/**
|
|
86
|
|
|
* Remove the specified resource from storage.
|
|
87
|
|
|
*
|
|
88
|
|
|
* @param int $id
|
|
89
|
|
|
* @return \Illuminate\Http\Response
|
|
90
|
|
|
*/
|
|
91
|
|
|
public function destroy($id)
|
|
|
|
|
|
|
92
|
|
|
{
|
|
93
|
|
|
//
|
|
94
|
|
|
}
|
|
95
|
|
|
public function change(Request $request){
|
|
96
|
|
|
$pass = bcrypt($request['password']);
|
|
97
|
|
|
dd($pass);
|
|
98
|
|
|
$pw_c = Auth::user()->password;
|
|
99
|
|
|
if ($pass != $pw_c){
|
|
100
|
|
|
return "sorry";
|
|
101
|
|
|
}
|
|
102
|
|
|
return redirect('prof');
|
|
103
|
|
|
}
|
|
104
|
|
|
|
|
105
|
|
|
/**
|
|
106
|
|
|
* @param \App\Http\Controllers\Request|Request $request
|
|
107
|
|
|
* @param $id
|
|
108
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
109
|
|
|
*/
|
|
110
|
|
|
public function info(Request $request,$id){
|
|
111
|
|
|
$validator = Validator::make($request->all(), [
|
|
112
|
|
|
'image' => 'required|max:700|mimes:jpeg,bmp,png',
|
|
113
|
|
|
]);
|
|
114
|
|
|
if ($validator->fails()) {
|
|
115
|
|
|
return redirect('/profile')
|
|
116
|
|
|
->withInput()
|
|
117
|
|
|
->withErrors($validator);
|
|
118
|
|
|
}
|
|
119
|
|
|
if ($request->hasFile('image')){
|
|
120
|
|
|
$user = User::find($id);
|
|
121
|
|
|
$user->name = $request['username'];
|
|
122
|
|
|
$user->email = $request['email'];
|
|
123
|
|
|
|
|
124
|
|
|
$fileType1 = $request->file('image')->getClientOriginalExtension();
|
|
125
|
|
|
$fname = Auth::user()->name.$request->title;
|
|
126
|
|
|
$fileName1 = $fname.'.'.$fileType1;
|
|
127
|
|
|
$documentRoot = 'images/user/';
|
|
128
|
|
|
$request->file('image')->move($documentRoot,$fileName1);
|
|
129
|
|
|
$user->avatar = $fileName1;
|
|
130
|
|
|
$user->save();
|
|
131
|
|
|
Session::flash('message','Successfully updated!');
|
|
132
|
|
|
}
|
|
133
|
|
|
|
|
134
|
|
|
return redirect('profile');
|
|
135
|
|
|
}
|
|
136
|
|
|
public function upload()
|
|
137
|
|
|
{
|
|
138
|
|
|
// getting all of the post data
|
|
139
|
|
|
$file = array('image' => Input::file('image'));
|
|
140
|
|
|
// setting up rules
|
|
141
|
|
|
$rules = array('image' => 'required',); //mimes:jpeg,bmp,png and for max size max:10000
|
|
142
|
|
|
// doing the validation, passing post data, rules and the messages
|
|
143
|
|
|
$validator = Validator::make($file, $rules);
|
|
144
|
|
|
if ($validator->fails()) {
|
|
145
|
|
|
// send back to the page with the input data and errors
|
|
146
|
|
|
return Redirect::to('upload')->withInput()->withErrors($validator);
|
|
147
|
|
|
} else {
|
|
148
|
|
|
// checking file is valid.
|
|
149
|
|
|
if (Input::file('image')->isValid()) {
|
|
150
|
|
|
$destinationPath = 'uploads'; // upload path
|
|
151
|
|
|
$extension = Input::file('image')->getClientOriginalExtension(); // getting image extension
|
|
152
|
|
|
$fileName = rand(11111, 99999) . '.' . $extension; // renameing image
|
|
153
|
|
|
Input::file('image')->move($destinationPath, $fileName); // uploading file to given path
|
|
154
|
|
|
// sending back with message
|
|
155
|
|
|
Session::flash('success', 'Upload successfully');
|
|
156
|
|
|
return Redirect::to('upload');
|
|
157
|
|
|
} else {
|
|
158
|
|
|
// sending back with error message.
|
|
159
|
|
|
Session::flash('error', 'uploaded file is not valid');
|
|
160
|
|
|
return Redirect::to('upload');
|
|
161
|
|
|
}
|
|
162
|
|
|
}
|
|
163
|
|
|
}
|
|
164
|
|
|
}
|
|
165
|
|
|
|
|
166
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.