diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 54f14c11..2488a467 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -48,4 +48,9 @@ class LoginController extends Controller session(['current_user' => $user]); return redirect()->route('dash'); } + + public function autologin($uuid) + { + + } } diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index a26b0d83..93991244 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -42,25 +42,30 @@ class UserController extends Controller $validatedData = $request->validate([ 'name' => 'required|max:255', 'email' => 'required|email', - 'password' => 'nullable', - 'password_confirmation' => 'nullable|confirmed' + 'password' => 'nullable|confirmed', + 'password_confirmation' => 'nullable' ]); - //die(print_r($request->all())); + $user = new User; + $user->name = $request->input('name'); + $user->email = $request->input('email'); + $user->public_front = $request->input('public_front'); + + $password = $request->input('password'); + if(!empty($password)) { + $user->password = bcrypt(); + } + if($request->hasFile('file')) { $path = $request->file('file')->store('avatars'); - $request->merge([ - 'avatar' => $path - ]); + $user->avatar = $path; } if ((bool)$request->input('autologin_allow') === true) { - $request->merge([ - 'autologin' => (string)Str::uuid() - ]); + $user->autologin = (string)Str::uuid(); } - $user = User::create($request->all()); + $user->save(); $route = route('dash', [], false); return redirect($route) @@ -103,28 +108,34 @@ class UserController extends Controller $validatedData = $request->validate([ 'name' => 'required|max:255', 'email' => 'required|email', - 'password' => 'nullable', - 'password_confirmation' => 'nullable|confirmed' + 'password' => 'nullable|confirmed', + 'password_confirmation' => 'nullable' ]); //die(print_r($request->all())); + + $user->name = $request->input('name'); + $user->email = $request->input('email'); + $user->public_front = $request->input('public_front'); + + $password = $request->input('password'); + if(!empty($password)) { + $user->password = bcrypt($password); + } elseif($password == 'null') { + $user->password = null; + } + if($request->hasFile('file')) { $path = $request->file('file')->store('avatars'); - $request->merge([ - 'avatar' => $path - ]); + $user->avatar = $path; } + if ((bool)$request->input('autologin_allow') === true) { - $autologin = (is_null($user->autologin)) ? (string)Str::uuid() : $user->autologin; + $user->autologin = (is_null($user->autologin)) ? (string)Str::uuid() : $user->autologin; } else { - $autologin = null; + $user->autologin = null; } - $request->merge([ - 'autologin' => $autologin - ]); - $input = $request->except(['password_confirmation', 'autologin_allow']); - //die(print_r($input)); - - $user->update($input); + + $user->save(); $route = route('dash', [], false); return redirect($route) diff --git a/database/migrations/2018_10_12_122907_create_users_table.php b/database/migrations/2018_10_12_122907_create_users_table.php index d8a7d645..6f462806 100644 --- a/database/migrations/2018_10_12_122907_create_users_table.php +++ b/database/migrations/2018_10_12_122907_create_users_table.php @@ -19,7 +19,7 @@ class CreateUsersTable extends Migration $table->string('email')->unique(); $table->string('avatar')->nullable(); $table->string('password')->nullable(); - $table->string('autologin')->nullable(); + $table->string('autologin')->nullable()->index(); $table->boolean('public_front')->default(false); $table->rememberToken(); $table->timestamps(); diff --git a/resources/views/users/form.blade.php b/resources/views/users/form.blade.php index 01d14cea..5a081a9d 100644 --- a/resources/views/users/form.blade.php +++ b/resources/views/users/form.blade.php @@ -56,7 +56,7 @@