Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 73 |
| AuthController | |
0.00% |
0 / 1 |
|
0.00% |
0 / 5 |
210 | |
0.00% |
0 / 73 |
| login | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 30 |
|||
| logout | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| user | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| markattendance | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 11 |
|||
| getcheckincheckouttime | |
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 28 |
|||
| <?php | |
| namespace App\Http\Controllers\Auth; | |
| use App\Http\Controllers\Controller; | |
| use Illuminate\Http\Request; | |
| use App\Models\Dashboard\AttendanceDetail; | |
| use Illuminate\Support\Facades\Auth; | |
| use Carbon\Carbon; | |
| use App\User; | |
| use App\Http\Controllers\Dashboard\AttendanceDetailController; | |
| use GetShiftDetailHelper; | |
| class AuthController extends Controller | |
| { | |
| public function login(Request $request) | |
| { | |
| $request->validate([ | |
| 'email' => 'required|string|email', | |
| 'password' => 'required|string', | |
| 'remember_me' => 'boolean' | |
| ]); | |
| $credentials = request(['email', 'password']); | |
| if(!Auth::attempt($credentials)) | |
| return response()->json([ | |
| 'message' => 'Unauthorized', | |
| 'status' => '200' | |
| ]); | |
| $user = $request->user(); | |
| $timearr = $this->getcheckincheckouttime($request); | |
| $tokenResult = $user->createToken('Personal Access Token'); | |
| $token = $tokenResult->token; | |
| if ($request->remember_me) | |
| $token->expires_at = Carbon::now()->addWeeks(1); | |
| $token->save(); | |
| if(Auth::user()->profile_pic) | |
| $imageurl = url('storage/'. Auth::user()->profile_pic); | |
| else | |
| $imageurl = url('global_assets/images/placeholders/placeholder.jpg'); | |
| return response()->json([ | |
| 'status' => '200', | |
| 'message' => 'Login Successful', | |
| 'checkin' => $timearr[0], | |
| 'checkout' => $timearr[1], | |
| 'shiftStartTime' => $timearr[2], | |
| 'shiftEndTime' => $timearr[3], | |
| 'username' => $user->name, | |
| 'imageurl' => $imageurl, | |
| 'access_token' => $tokenResult->accessToken, | |
| 'token_type' => 'Bearer', | |
| 'expires_at' => Carbon::parse( | |
| $tokenResult->token->expires_at | |
| )->toDateTimeString() | |
| ]); | |
| } | |
| /** | |
| * Logout user (Revoke the token) | |
| * | |
| * @return [string] message | |
| */ | |
| public function logout(Request $request) | |
| { | |
| $request->user()->token()->revoke(); | |
| return response()->json([ | |
| 'message' => 'Successfully logged out' | |
| ]); | |
| } | |
| /** | |
| * Get the authenticated User | |
| * | |
| * @return [json] user object | |
| */ | |
| public function user(Request $request) | |
| { | |
| return response()->json($request->user()); | |
| } | |
| public function markattendance(Request $request) | |
| { | |
| $attendanceeDetail = new AttendanceDetailController(); | |
| $attendanceeDetail->processAttendanceSelfService($request); | |
| $timearr = $this->getcheckincheckouttime($request); | |
| if($request->has('reasonTitle')) | |
| { | |
| $message = $request->input('reasonTitle').' Attendance updated'; | |
| }else{ | |
| $message = 'Attendance updated'; | |
| } | |
| return response()->json([ | |
| 'status' => '200', | |
| 'message' => $message, | |
| 'checkin' => $timearr[0], | |
| 'checkout' => $timearr[1] | |
| ]); | |
| } | |
| public function getcheckincheckouttime(Request $request) | |
| { | |
| $user = Auth::user(); | |
| $today_date_time = Carbon::now(); | |
| $attendanceDetail = AttendanceDetail::where('user_id', '=', $user->id) | |
| ->whereDate('check_in', '=', $today_date_time) | |
| ->first(); | |
| $dcheck_in = ''; | |
| $dcheck_out = ''; | |
| if(isset($attendanceDetail) && !empty($attendanceDetail)) | |
| { | |
| if ($attendanceDetail->check_in != null) { | |
| $dcheck_in = Carbon::parse($attendanceDetail->check_in); | |
| $dcheck_in->setTimezone(config('settings.time_zone')); | |
| $dcheck_in = $dcheck_in->format(config('settings.php_date_format') .' '. config('settings.time_format')); | |
| } | |
| if ($attendanceDetail->check_out != null) { | |
| $dcheck_out = Carbon::parse($attendanceDetail->check_out); | |
| $dcheck_out->setTimezone(config('settings.time_zone')); | |
| $dcheck_out = $dcheck_out->format(config('settings.php_date_format') .' '. config('settings.time_format')); | |
| } | |
| } | |
| $startDate = Carbon::parse(Carbon::now(config('settings.time_zone'))->toDateString().'00:00:00', config('settings.time_zone'))->setTimezone(config('app.time_zone')); | |
| $endDate = Carbon::parse(Carbon::now(config('settings.time_zone'))->addDay()->toDateString().'00:00:00', config('settings.time_zone'))->setTimezone(config('app.time_zone')); | |
| $todayShiftTime = GetShiftDetailHelper::getShiftDetail(auth()->id(),$startDate,$endDate); | |
| $todayShiftStartTime = ''; | |
| $todayShiftEndTime=''; | |
| if( $todayShiftTime != null ) { | |
| $todayShiftStartTime = $todayShiftTime['shiftStartTime']; | |
| $todayShiftStartTime = date(Config('settings.time_format'), strtotime($todayShiftStartTime)); | |
| $todayShiftEndTime = $todayShiftTime['shiftEndTime']; | |
| $todayShiftEndTime = date(Config('settings.time_format'), strtotime($todayShiftEndTime)); | |
| } | |
| $timearr = array($dcheck_in,$dcheck_out,$todayShiftStartTime,$todayShiftEndTime); | |
| /* end of get checkin value */ | |
| return $timearr; | |
| } | |
| } |