-
Notifications
You must be signed in to change notification settings - Fork 11
/
AuthController.php
98 lines (86 loc) · 3.06 KB
/
AuthController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
namespace App\Http\Controllers;
use App\Department;
use App\UserSetting;
use Illuminate\Http\Request;
use App\User;
use Image;
class AuthController extends Controller
{
public function registerStudent(Department $department)
{
$departments = $department->viewAll();
return view ('auth.register')->with('departments', $departments);
}
public function postStudentRegistration(Request $request, User $user,Department $department)
{
try
{
if($request->hasFile('photo')){
try{
$image = $request->file('photo');
$imageName = OptimiseImage($image, $request['identification_no']);
$request['image'] = $imageName;
}
catch (\Exception $e){
echo '<script>alert("Upload a valid image");</script>';
}
}
else
{
$departments = $department->viewAll();
return view ('auth.register')->with('departments', $departments);
}
if($request['password']!= $request['c_password']){
$request['password'] = '';
}
$result = $user->createNew($request->all());
if ($result){
return view('auth.login');
}
}
catch (\Exception $e)
{
echo '<script>alert("Try again later and fill all fields");</script>';
}
}
public function login()
{
$title = 'Login to your account';
return view('auth.login', compact('title'));
}
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'));
}
elseif(auth()->user()->user_type == 3)
{
return redirect()->intended(route('student.home'));
}
elseif(auth()->user()->user_type == 4)
{
return 'Professor';
}
}
return redirect()->back()->with('error', 'Identification No and Password Combination Incorrect')->withInput();
} catch (\Exception $e)
{
/*Send us a mail */
return redirect()->back()->with('error', 'Could not sign you in at the moment. Please try again...');
}
}
public function logout()
{
auth()->logout();
return redirect()->route('login');
}
}