Skip to content

Commit

Permalink
fixed the bug. where the theme setting was only working on theg on th…
Browse files Browse the repository at this point in the history
…e home page
  • Loading branch information
TimothyMee committed Mar 5, 2018
1 parent 9f91e08 commit a7957be
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
7 changes: 6 additions & 1 deletion app/Http/Controllers/AuthController.php
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use App\Department;
use App\UserSetting;
use Illuminate\Http\Request;
use App\User;
use Image;
Expand Down Expand Up @@ -57,13 +58,17 @@ public function login()
return view('auth.login', compact('title'));
}

public function postLogin(Request $request)
public function postLogin(Request $request, UserSetting $userSetting)
{
$data = $request->all();
try{
if (auth()->attempt(['email' => $data['email'], 'password' => $data['password'], 'is_active' => true])) {
if (auth()->user()->user_type == 1 || auth()->user()->user_type == 2)
{
//Saving the theme value into the session
$userSetting = $userSetting->view(auth()->id());
$userSetting = $userSetting[0]->theme;
session(['theme' => $userSetting]);
return redirect()->intended(route('home'));
}

Expand Down
5 changes: 0 additions & 5 deletions app/Http/Controllers/HomeController.php
Expand Up @@ -30,8 +30,6 @@ public function index(User $user, Course $course, Department $department, UserS
$courses = $course->viewAll();
$users = $user->viewAll();
$departments = $department->viewAll();
$userSetting = $userSetting->view(auth()->id());
$userSetting = $userSetting[0]->theme;

$admin = array();
$student = array();
Expand Down Expand Up @@ -83,9 +81,6 @@ public function index(User $user, Course $course, Department $department, UserS
'courseCount' => $courseCount,
];

// Saving the theme value into the session
session(['theme' => $userSetting]);


return view('home')->with('data',$data);
}
Expand Down
11 changes: 11 additions & 0 deletions app/UserSetting.php
Expand Up @@ -19,10 +19,21 @@ public function saveSetting($data)
if(! $existingData->exists()){
$data['user_id'] = auth()->id();
$this->create($data);

//Saving the theme value into the session
$userSetting = $this->view(auth()->id());
$userSetting = $userSetting[0]->theme;
session(['theme' => $userSetting]);
return true;
}
else{
$this->updateUserSettings($data);

//Saving the theme value into the session
$userSetting = $this->view(auth()->id());
$userSetting = $userSetting[0]->theme;
session(['theme' => '']);
session(['theme' => $userSetting]);
return true;
}
}
Expand Down

0 comments on commit a7957be

Please sign in to comment.