1
|
|
|
<?php |
2
|
|
|
use LaravelRealtimeChat\Repositories\Team\TeamRepository; |
3
|
|
|
class AuthController extends \BaseController { |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
private $teamRepository; |
7
|
|
|
/** |
8
|
|
|
* @var LaravelRealtimeChat\Repositories\TaskRepository |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
public function __construct(TeamRepository $teamRepository) { |
13
|
|
|
$this->teamRepository = $teamRepository; |
14
|
|
|
|
15
|
|
|
} |
16
|
|
|
public function updateStatus() { |
17
|
|
|
$currentTimeStamp = Carbon\Carbon::now(); |
18
|
|
|
$currentTimeStamp = $currentTimeStamp->toDateTimeString(); |
19
|
|
|
|
20
|
|
|
$status = Input::get('data'); |
|
|
|
|
21
|
|
|
|
22
|
|
|
|
23
|
|
|
$exists = DB::table('login_status')->select('user_id')->where('user_id', Auth::user()->id)->get(); |
24
|
|
|
|
25
|
|
|
if ($status == "online" && count($exists) == 0) { |
26
|
|
|
|
27
|
|
|
$id = DB::table('login_status')->insertGetId( |
|
|
|
|
28
|
|
|
['user_id' => Auth::user()->id, 'status' => $status, 'created_at' => $currentTimeStamp, 'updated_at' => $currentTimeStamp] |
29
|
|
|
); |
30
|
|
|
} |
31
|
|
|
if ($status == "online" && count($exists) > 0) { |
32
|
|
|
DB::table('login_status') |
33
|
|
|
->where('user_id', Auth::user()->id) |
34
|
|
|
->update(array('status' => "online", 'created_at' => $currentTimeStamp, 'updated_at' => $currentTimeStamp)); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
if ($status == "offline") { |
38
|
|
|
DB::table('login_status') |
39
|
|
|
->where('user_id', Auth::user()->id) |
40
|
|
|
->update(array('status' => "offline", 'updated_at' => $currentTimeStamp)); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$this->notifyTeamMemebers($status); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function postLogin() { |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
// $input = Input::only(array( |
50
|
|
|
// 'email', |
51
|
|
|
// 'password' |
52
|
|
|
// )); |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
if(Input::get('token')!=''){ |
56
|
|
|
$rules = array( |
57
|
|
|
'email' => 'required|email', |
58
|
|
|
'password' => 'required|min:6|regex:/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{1,}$/' |
59
|
|
|
); |
60
|
|
|
$messages = array( |
61
|
|
|
'password.regex' => 'The password must containt atleast 1 Upper Case letters[A-Z],1 Lower Case Letter[a-z],1 numeric letter [0-9] and 1 special character.', |
62
|
|
|
|
63
|
|
|
);} |
64
|
|
|
else{ |
65
|
|
|
$rules = array( |
66
|
|
|
'email' => 'required|email', |
67
|
|
|
'password' => 'required' |
68
|
|
|
); |
69
|
|
|
$messages = array( |
70
|
|
|
'password.regex' => 'Invalid Username/Password', |
71
|
|
|
|
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
$validator = Validator::make(Input::all(), $rules,$messages); |
77
|
|
|
|
78
|
|
|
if ($validator->fails()) { |
79
|
|
|
return Response::json(array( |
80
|
|
|
'success' => false, |
81
|
|
|
'errors' => $validator->getMessageBag()->toArray(), |
82
|
|
|
400 |
83
|
|
|
)); // 400 being the HTTP code for an invalid request. |
84
|
|
|
} else { |
85
|
|
|
$token = Input::get('token'); // for invited account |
86
|
|
|
if ($token != '') { |
87
|
|
|
|
88
|
|
|
$result = DB::table('invitation_token')->where('token', '=', $token)->first(); |
89
|
|
|
if (count($result)>0) {//token was valid and was deleted |
90
|
|
|
//Create invited account |
91
|
|
|
$userInfo=explode('@',$result['email']); |
92
|
|
|
$id = DB::table('users')->insertGetId( |
93
|
|
|
['first_name' => $userInfo[0], 'last_name' => '', 'email' => $result['email'], 'password' => Hash::make(Input::get('password'))] |
94
|
|
|
); |
95
|
|
|
DB::table('user_roles')->insert( |
96
|
|
|
['user_id' => $id, 'role_id' => "3"] |
97
|
|
|
); |
98
|
|
|
DB::table('team_channel_users')->insert( |
99
|
|
|
['team_channel_name_id' => $result['team_id'], 'user_id' => $id] |
100
|
|
|
); |
101
|
|
|
//delete token from database before creating invited account |
102
|
|
|
DB::table('invitation_token')->where('token', '=', $token)->delete(); |
103
|
|
|
$this->teamRepository->updateNewMemberJoinNotification($result['team_id'],$id); |
104
|
|
|
} |
105
|
|
|
else{ |
106
|
|
|
return Response::json(array( |
107
|
|
|
'success' => false, |
108
|
|
|
'errors' => "Invalid Request", |
109
|
|
|
400 |
110
|
|
|
)); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
if (Auth::attempt(array('email' => Input::get('email'), 'password' => Input::get('password')))) { |
116
|
|
|
|
117
|
|
|
/* Store basic information in session of logged in user */ |
118
|
|
|
$role = DB::table('roles') |
119
|
|
|
->leftJoin('user_roles', 'roles.id', '=', 'user_roles.role_id') |
120
|
|
|
->where('user_id', '=', Auth::user()->id)->first(); |
121
|
|
|
|
122
|
|
|
|
123
|
|
|
$channelName = DB::table('channels') |
124
|
|
|
->where('author_id', '=', Auth::user()->id)->first(); |
125
|
|
|
|
126
|
|
|
Session::put('userId', Auth::user()->id); |
127
|
|
|
Session::put('firstName', Auth::user()->first_name); |
128
|
|
|
Session::put('lastName', Auth::user()->last_name); |
129
|
|
|
Session::put('profilePic', Auth::user()->profile_pic); |
130
|
|
|
Session::put('role', $role['role_id']); |
131
|
|
|
Session::put('channelId', $channelName['id']); |
132
|
|
|
|
133
|
|
|
return Response::json(array( |
134
|
|
|
'success' => true |
135
|
|
|
), 200); |
136
|
|
|
} |
137
|
|
|
else{ |
138
|
|
|
$errorMsg = array( |
139
|
|
|
'errormsg' => 'Invalid Email or Password' |
140
|
|
|
); |
141
|
|
|
return Response::json(array( |
142
|
|
|
'success' => false, |
143
|
|
|
'errors' => $errorMsg, |
144
|
|
|
400 |
145
|
|
|
)); // 400 being the HTTP code for an invalid request. |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function logout() { |
150
|
|
|
|
151
|
|
|
|
152
|
|
|
Auth::logout(); |
153
|
|
|
sleep(1); |
154
|
|
|
Auth::logout(); |
155
|
|
|
|
156
|
|
|
|
157
|
|
|
|
158
|
|
|
return Redirect::to('/'); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public function getSignup($email, $password, $token) { |
162
|
|
|
//Delete token |
163
|
|
|
//Create Account |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* called functions |
168
|
|
|
*/ |
169
|
|
|
public function notifyTeamMemebers($status) { |
170
|
|
|
/** |
171
|
|
|
* |
172
|
|
|
* Get all team details where the user is a memeber |
173
|
|
|
* |
174
|
|
|
* |
175
|
|
|
* |
176
|
|
|
*/ |
177
|
|
|
$teamArr = array(); |
|
|
|
|
178
|
|
|
$teamName = DB::table('team_channels') |
179
|
|
|
->select('team_channels.channel_view_name', 'team_channels.team_channel_id', 'team_channels.id') |
180
|
|
|
->leftJoin('team_channel_users', 'team_channel_users.team_channel_name_id', '=', 'team_channels.id') |
181
|
|
|
->where('team_channel_users.user_id', '=', Auth::user()->id)->get(); |
182
|
|
|
/** |
183
|
|
|
* Loothrough each team ids obtained and get team users where 'this user was a memeber' |
184
|
|
|
* |
185
|
|
|
* |
186
|
|
|
*/ |
187
|
|
|
foreach ($teamName as $values) { |
188
|
|
|
$teamMembers = DB::table('users') |
189
|
|
|
->select('users.first_name', 'users.id') |
190
|
|
|
->leftJoin('team_channel_users', 'team_channel_users.user_id', '=', 'users.id') |
191
|
|
|
->where('team_channel_users.team_channel_name_id', '=', $values["id"])->get(); |
192
|
|
|
|
193
|
|
|
foreach ($teamMembers as $memeber) { |
194
|
|
|
//Publish data to redis |
195
|
|
|
$channelId = $memeber["id"] . "_" . $values["team_channel_id"]; |
196
|
|
|
|
197
|
|
|
$teamChannelId = $values["team_channel_id"]; |
|
|
|
|
198
|
|
|
$data = array( |
199
|
|
|
'room' => $channelId, |
200
|
|
|
'message' => array('user_id' => Auth::user()->id, "status" => $status) |
201
|
|
|
); |
202
|
|
|
Event::fire(LoginStatusEventHandler::EVENT, array(json_encode($data))); |
203
|
|
|
} |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
public function updateTimeZone(){ |
208
|
|
|
$tzName=Input::get('tz'); |
209
|
|
|
|
210
|
|
|
|
211
|
|
|
storeUserTimeZone($tzName); |
212
|
|
|
|
213
|
|
|
} |
214
|
|
|
} |
215
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths