Пример #1
0
 public function postSetInitial(Request $request)
 {
     $session_id = $request->input('session_id');
     $input = ['session_id' => $session_id];
     $validator = validator::make($request->all(), ['session_id' => 'required']);
     if ($validator->fails()) {
         return ApiResponseClass::errorResponse('You Have Some Input Errors. Please Try Again!!', $input, $validator->errors());
     } else {
         $user_registered_to_school = UsersRegisteredToSchool::where('user_id', Auth::user()->id)->get()->first();
         if ($user_registered_to_school) {
             $user_registered_to_session = UsersRegisteredToSession::where('session_id', $session_id)->where('user_id', Auth::user()->id)->get()->first();
             if ($user_registered_to_session) {
                 return ApiResponseClass::successResponse($user_registered_to_session, $input);
             }
             $user_registered_to_session = new UsersRegisteredToSession();
             $user_registered_to_session->session_id = $session_id;
             $user_registered_to_session->school_id = $user_registered_to_school->school_id;
             $user_registered_to_session->user_id = Auth::user()->id;
             $user_registered_to_session->save();
             if ($user_registered_to_session->save()) {
                 return ApiResponseClass::successResponse($user_registered_to_session, $input);
             }
         }
     }
     return ApiResponseClass::errorResponse('There is Something Wrong. Please Try Again!!', $input);
 }
 public function postGetAllTheTeachersRegisteredToSchool()
 {
     $query = 'SELECT user_details.id, user_details.first_name, user_details.last_name, user_details.user_id FROM user_details
               JOIN users_registered_to_school
               ON users_registered_to_school.user_id = user_details.user_id
               JOIN user_group
               ON user_group.user_id = user_details.user_id
               WHERE user_group.group_id = ? AND users_registered_to_school.school_id = ?';
     $all_school_teachers = DB::select($query, array(3, $this->getSchoolAndUserBasicInfo()->getSchoolId()));
     return ApiResponseClass::successResponse($all_school_teachers);
 }
Пример #3
0
 public function postCreate(Request $request)
 {
     $email = $request->input('email');
     $password = $request->input('password');
     $password_again = $request->input('password_again');
     $inputs = ['email' => $email, 'password' => $password, 'password_again' => $password_again];
     $validator = validator::make($request->all(), ['email' => 'required|unique:users|email', 'password' => 'required|max:16|min:6', 'password_again' => 'required|same:password']);
     if ($validator->fails()) {
         return ApiResponseClass::errorResponse('You Have Some Input Errors', $inputs, $validator->errors());
     }
     $isUrlUser = $request->is('user/*');
     $isUrlAdmin = $request->is('admin/*');
     $isUrlTeacher = $request->is('teacher/*');
     $group_id = null;
     if ($isUrlUser) {
         $group_id = Groups::Student_Group_Id;
     } elseif ($isUrlAdmin) {
         $group_id = Groups::Administrator_Group_ID;
     } elseif ($isUrlTeacher) {
         $group_id = Groups::Teacher_Group_Id_Group_ID;
     }
     DB::beginTransaction();
     try {
         Groups::findorFail($group_id);
         $user = new User();
         $user->email = $email;
         $user->password = Hash::make('password');
         $user->activated = 0;
         $user->email_updated_at = date("Y-m-d h:i:s");
         $user->password_updated_at = date("Y-m-d h:i:s");
         $user->activation_code = str_random(64);
         if (!$user->save()) {
             throw new \ErrorException();
         }
         $user_group = new UsersGroups();
         $user_group->user_id = $user->id;
         $user_group->groups_id = $group_id;
         if (!$user_group->save()) {
             throw new \ErrorException();
         }
         DB::commit();
     } catch (ModelNotFoundException $e) {
         DB::rollback();
         return ApiResponseClass::errorResponse('ModelNotFoundException', $inputs);
     } catch (\ErrorException $e) {
         DB::rollback();
         return ApiResponseClass::errorResponse('ModelNotSavedException', $inputs);
     }
     // Send mail to the user if not the test Shop Id.
     return ApiResponseClass::successResponse($user, $inputs);
 }
Пример #4
0
 public function postUpdateCoverPic(Request $request)
 {
     if ($request->hasFile('cover_image')) {
         $cover_image = $request->file('cover_image');
         if ($cover_image->isValid()) {
             if ($cover_image->getClientSize() <= RequiredConstants::MAXIMUM_COVER_IMAGE_SIZE) {
                 $allowed_file_types = ['jpg', 'png', 'jpeg'];
                 if (in_array($cover_image->guessClientExtension(), $allowed_file_types)) {
                     DB::beginTransaction();
                     try {
                         $now = date("Y-m-d H:i:s");
                         $pic_name = rand(1, 500000) . strtotime($now) . '.' . $cover_image->guessClientExtension();
                         $userDetails = UserDetails::where('user_id', $this->getUserId())->get()->first();
                         if ($userDetails->cover_pic) {
                             $path = public_path(RequiredConstants::USER_COVER_PICS_PATH . $userDetails->cover_pic);
                             if (!File::delete($path)) {
                                 throw new FileNotFoundException();
                             }
                         }
                         $userDetails->cover_pic = $pic_name;
                         $userDetails->cover_pic_updated_at = $now;
                         if (!$userDetails->save()) {
                             throw new ModelNotSavedException();
                         }
                         $cover_image->move(RequiredConstants::USER_COVER_PICS_PATH, $pic_name);
                         DB::commit();
                     } catch (ModelNotSavedException $e) {
                         DB::rollback();
                         return ApiResponseClass::errorResponse('File Could not be uploaded. Please Try Again!!', $request->all());
                     } catch (FileException $e) {
                         DB::rollback();
                         return ApiResponseClass::errorResponse('File Could not be uploaded. Please Try Again!!', $request->all());
                     } catch (FileNotFoundException $e) {
                         DB::rollback();
                         return ApiResponseClass::errorResponse('File Not Found. Please Try Again!!', $request->all());
                     }
                     return ApiResponseClass::successResponse($userDetails, $request->all());
                 } else {
                     return ApiResponseClass::errorResponse('This file type is not allowed to upload.!!', $request->all());
                 }
             } else {
                 return ApiResponseClass::errorResponse('Maximum file size limit is 5MB.!!', $request->all());
             }
         } else {
             return ApiResponseClass::errorResponse('Not a Valid File.!!', $request->all());
         }
     }
     return ApiResponseClass::errorResponse('There is Something Wrong. Please Try Again!!', $request->all());
 }
Пример #5
0
 /**
  * Api for Brief Registration
  */
 public function postBriefRegistration(Request $request)
 {
     $first_name = $request->input('first_name');
     $last_name = $request->input('last_name');
     $sex = $request->input('sex');
     $validator = validator::make($request->all(), ['first_name' => 'required', 'last_name' => 'required', 'sex' => 'required']);
     $input = ['first_name' => $first_name, 'last_name' => $last_name, 'sex' => $sex];
     if ($validator->fails()) {
         return ApiResponseClass::errorResponse('Some Problem Occured. Please Try again With Correct Values!!', $input);
     }
     $input = ['first_name' => $first_name, 'last_name' => $last_name, 'sex' => $sex];
     $user_details = UserDetails::where('user_id', Auth::user()->id)->get()->first();
     if (!$user_details) {
         $user_details = new UserDetails();
     }
     $user_details->first_name = $first_name;
     $user_details->last_name = $last_name;
     $user_details->sex = $sex;
     $user_details->user_id = Auth::user()->id;
     if ($user_details->save()) {
         $result = array('details' => $user_details);
         return ApiResponseClass::successResponse($result, $input);
     }
     return ApiResponseClass::errorResponse('Some Problem Occured. Please Try again With Correct Values!!', $input);
 }
Пример #6
0
 public function postDeleteSubject(Request $request)
 {
     $subject_id = $request->input('subject_id');
     $input = ['subject_id' => $subject_id];
     $validator = validator::make($request->all(), ['subject_id' => 'required']);
     if ($validator->fails()) {
         return ApiResponseClass::errorResponse('You Have Some Input Errors. Please Try Again!!', $input, $validator->errors());
     } else {
         try {
             $subject = Subjects::findOrFail($subject_id);
             if (!$subject->delete()) {
                 throw new ErrorException();
             }
         } catch (ModelNotFoundException $e) {
             return ApiResponseClass::errorResponse('There is Something Wrong. Please Try Again!!', $input);
         } catch (ErrorException $e) {
             return ApiResponseClass::errorResponse('There is Something Wrong. Please Try Again!!', $input);
         }
         return ApiResponseClass::successResponse($subject, $input);
     }
     return ApiResponseClass::errorResponse('There is Something Wrong. Please Try Again!!', $input);
 }
Пример #7
0
 public function postRetrievePasswordMobileApp(Request $request)
 {
     $email = $request->input('email');
     $inputs = ['email' => $email];
     $validator = validator::make($request->all(), ['email' => 'required']);
     if ($validator->fails()) {
         $flash_data = 'You have some errors !!';
         return ApiResponseClass::errorResponse($flash_data, $inputs, $validator->errors());
     } else {
         $user = User::where('email', $email)->get()->first();
         if ($user && $user->count() > 0) {
             if ($user->activated) {
                 // Send Email to that email address
                 $flash_data = 'Thank You. You have been sent an email to reset your password.!!';
                 return ApiResponseClass::successResponse(null, $inputs, $flash_data);
             } else {
                 $flash_data = 'User is not Activated !!';
                 return ApiResponseClass::errorResponse($flash_data, $inputs);
             }
         } else {
             $flash_data = 'Your Email is not Found. Retry with Correct Email Address!!';
             return ApiResponseClass::errorResponse($flash_data, $inputs);
         }
     }
 }
 public function checkIfCurrentSessionSet()
 {
     $school_session = SchoolSession::where('school_id', $this->getSchoolAndUserBasicInfo()->getSchoolId())->where('current_session', 1)->get()->first();
     return ApiResponseClass::successResponse($school_session->id);
 }