Skip to content

Commit

Permalink
Fix master redirect after login
Browse files Browse the repository at this point in the history
#208 issue. Master was not redirecting to `/masters` page after login in some cases. #208 (comment) this patch is made in this commit.
  • Loading branch information
changeweb committed Oct 31, 2019
1 parent dd7de32 commit d5a11c0
Showing 1 changed file with 73 additions and 68 deletions.
141 changes: 73 additions & 68 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,75 +23,80 @@ public function __construct()
*/
public function index()
{
$minutes = 1440;// 24 hours = 1440 minutes

This comment has been minimized.

Copy link
@JuanVqz

JuanVqz Feb 16, 2020

Contributor

Hi @changeweb!, Why did you do this?

This comment has been minimized.

Copy link
@changeweb

changeweb Feb 20, 2020

Author Owner

@JuanVqz for some users it seems 'Login redirection' middleware doesn't work properly. So I did this change as a fail safe.
I mentioned this in Commit Description also.

Do you have any suggestion?

This comment has been minimized.

Copy link
@JuanVqz

JuanVqz Feb 20, 2020

Contributor

yes, we need to check more confident what is the reason for redirect to the /home route.
For example this one:

<a class="navbar-brand" href="{{ url('/home') }}" style="color: #000;">
{{ (Auth::check() && (Auth::user()->role == 'student' || Auth::user()->role == 'teacher' ||
Auth::user()->role == 'admin' || Auth::user()->role == 'accountant' || Auth::user()->role ==
'librarian'))?Auth::user()->school->name:config('app.name') }}
</a>

Another reason is the test is passing and the test doesn't lie, maybe we need the exact steps to reproduce what the user did

by the way, nice to writing to you! I hope you are really good at this new year

This comment has been minimized.

Copy link
@changeweb

changeweb Feb 21, 2020

Author Owner

@JuanVqz Nice to hear from you too after a long time. Time passes so fast! I also wish you a happy new year.

Yes, tests are passing. The software needs to be updated regularly. But sadly I can't work on it right now. Hope we can make it more stable.

This comment has been minimized.

Copy link
@JuanVqz

JuanVqz Feb 21, 2020

Contributor

@changeweb, Thank you!
I'd like to work on it but I can't though
Happy path to you! 😎

$school_id = \Auth::user()->school->id;
$classes = \Cache::remember('classes-'.$school_id, $minutes, function () use($school_id) {
return \App\Myclass::bySchool($school_id)
->pluck('id')
->toArray();
});
$totalStudents = \Cache::remember('totalStudents-'.$school_id, $minutes, function () use($school_id) {
return \App\User::bySchool($school_id)
->where('role','student')
->where('active', 1)
->count();
});
$totalTeachers = \Cache::remember('totalTeachers-'.$school_id, $minutes, function () use($school_id) {
return \App\User::bySchool($school_id)
->where('role','teacher')
->where('active', 1)
->count();
});
$totalBooks = \Cache::remember('totalBooks-'.$school_id, $minutes, function () use($school_id) {
return \App\Book::bySchool($school_id)->count();
});
$totalClasses = \Cache::remember('totalClasses-'.$school_id, $minutes, function () use($school_id) {
return \App\Myclass::bySchool($school_id)->count();
});
$totalSections = \Cache::remember('totalSections-'.$school_id, $minutes, function () use ($classes) {
return \App\Section::whereIn('class_id', $classes)->count();
});
$notices = \Cache::remember('notices-'.$school_id, $minutes, function () use($school_id) {
return \App\Notice::bySchool($school_id)
->where('active',1)
->get();
});
$events = \Cache::remember('events-'.$school_id, $minutes, function () use($school_id) {
return \App\Event::bySchool($school_id)
->where('active',1)
->get();
});
$routines = \Cache::remember('routines-'.$school_id, $minutes, function () use($school_id) {
return \App\Routine::bySchool($school_id)
->where('active',1)
->get();
});
$syllabuses = \Cache::remember('syllabuses-'.$school_id, $minutes, function () use($school_id) {
return \App\Syllabus::bySchool($school_id)

if (\Auth::user()->role != 'master') {
$minutes = 1440;// 24 hours = 1440 minutes
$school_id = \Auth::user()->school->id;
$classes = \Cache::remember('classes-'.$school_id, $minutes, function () use($school_id) {
return \App\Myclass::bySchool($school_id)
->pluck('id')
->toArray();
});
$totalStudents = \Cache::remember('totalStudents-'.$school_id, $minutes, function () use($school_id) {
return \App\User::bySchool($school_id)
->where('role','student')
->where('active', 1)
->count();
});
$totalTeachers = \Cache::remember('totalTeachers-'.$school_id, $minutes, function () use($school_id) {
return \App\User::bySchool($school_id)
->where('role','teacher')
->where('active', 1)
->count();
});
$totalBooks = \Cache::remember('totalBooks-'.$school_id, $minutes, function () use($school_id) {
return \App\Book::bySchool($school_id)->count();
});
$totalClasses = \Cache::remember('totalClasses-'.$school_id, $minutes, function () use($school_id) {
return \App\Myclass::bySchool($school_id)->count();
});
$totalSections = \Cache::remember('totalSections-'.$school_id, $minutes, function () use ($classes) {
return \App\Section::whereIn('class_id', $classes)->count();
});
$notices = \Cache::remember('notices-'.$school_id, $minutes, function () use($school_id) {
return \App\Notice::bySchool($school_id)
->where('active',1)
->get();
});
$events = \Cache::remember('events-'.$school_id, $minutes, function () use($school_id) {
return \App\Event::bySchool($school_id)
->where('active',1)
->get();
});
$exams = \Cache::remember('exams-'.$school_id, $minutes, function () use($school_id) {
return \App\Exam::bySchool($school_id)
->where('active',1)
->get();
});
// if(\Auth::user()->role == 'student')
// $messageCount = \App\Notification::where('student_id',\Auth::user()->id)->count();
// else
// $messageCount = 0;
return view('home',[
'totalStudents'=>$totalStudents,
'totalTeachers'=>$totalTeachers,
'totalBooks'=>$totalBooks,
'totalClasses'=>$totalClasses,
'totalSections'=>$totalSections,
'notices'=>$notices,
'events'=>$events,
'routines'=>$routines,
'syllabuses'=>$syllabuses,
'exams'=>$exams,
//'messageCount'=>$messageCount,
]);
});
$routines = \Cache::remember('routines-'.$school_id, $minutes, function () use($school_id) {
return \App\Routine::bySchool($school_id)
->where('active',1)
->get();
});
$syllabuses = \Cache::remember('syllabuses-'.$school_id, $minutes, function () use($school_id) {
return \App\Syllabus::bySchool($school_id)
->where('active',1)
->get();
});
$exams = \Cache::remember('exams-'.$school_id, $minutes, function () use($school_id) {
return \App\Exam::bySchool($school_id)
->where('active',1)
->get();
});
// if(\Auth::user()->role == 'student')
// $messageCount = \App\Notification::where('student_id',\Auth::user()->id)->count();
// else
// $messageCount = 0;
return view('home',[
'totalStudents'=>$totalStudents,
'totalTeachers'=>$totalTeachers,
'totalBooks'=>$totalBooks,
'totalClasses'=>$totalClasses,
'totalSections'=>$totalSections,
'notices'=>$notices,
'events'=>$events,
'routines'=>$routines,
'syllabuses'=>$syllabuses,
'exams'=>$exams,
//'messageCount'=>$messageCount,
]);
} else {
return redirect('/masters');
}
}
}

0 comments on commit d5a11c0

Please sign in to comment.