diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index b0bf09ee..c45c0276 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -11,7 +11,6 @@ use Option; use Session; use App\Events; use App\Models\User; -use App\Models\UserModel; use Illuminate\Http\Request; use App\Exceptions\PrettyPageException; use App\Services\Repositories\UserRepository; @@ -256,7 +255,7 @@ class AuthController extends Controller return \Response::png(); } - private function checkCaptcha($request) + protected function checkCaptcha($request) { return (strtolower($request->input('captcha')) == strtolower(session('phrase'))); } diff --git a/app/Http/Middleware/CheckAuthenticated.php b/app/Http/Middleware/CheckAuthenticated.php index 9c38d9bb..f648c7a4 100644 --- a/app/Http/Middleware/CheckAuthenticated.php +++ b/app/Http/Middleware/CheckAuthenticated.php @@ -13,10 +13,17 @@ use App\Exceptions\PrettyPageException; class CheckAuthenticated { - public function handle($request, \Closure $next, $return_user = false) + public function handle($request, \Closure $next, $returnUser = false) { if (Session::has('uid')) { - $user = app('users')->get(session('uid')); + + if (!app()->bound('user.current')) { + // bind current user to container + $user = app('users')->get(session('uid')); + app()->instance('user.current', $user); + } else { + $user = app('user.current'); + } if (session('token') != $user->getToken()) return redirect('auth/login')->with('msg', trans('auth.check.token')); @@ -40,23 +47,20 @@ class CheckAuthenticated return $next($request); } else { - echo View::make('auth.bind')->with('msg', trans('auth.validation.email')); + return response()->view('auth.bind', ['msg' => trans('auth.bind.registered')]); } } else { - echo View::make('auth.bind')->with('msg', trans('auth.bind.registered')); + return response()->view('auth.bind', ['msg' => trans('auth.validation.email')]); } - exit; } - View::show('auth.bind'); - exit; + + return response()->view('auth.bind'); } event(new UserAuthenticated($user)); - if ($return_user) - return $user; + return $returnUser ? $user : $next($request); - return $next($request); } else { return redirect('auth/login')->with('msg', trans('auth.check.anonymous')); } diff --git a/app/Models/User.php b/app/Models/User.php index add5fc13..caf6d9f8 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -103,18 +103,16 @@ class User extends Model $user = static::firstOrNew(['email' => $email]); // if the email is already registered - if ($user->uid) - return false; - - // save to get uid - $user->save(); - - $user->password = static::encryptPassword($password, $user); + if ($user->uid) return false; // pass the user instance to the callback call_user_func($callback, $user); - // save again with password etc. + // save to get uid + $user->save(); + + // save again with password + $user->password = static::encryptPassword($password, $user); $user->save(); return $user;