public function sendOtp()
 {
     $this->autoRender = false;
     $json = $this->request->input();
     $userOtp = DTO\ClsUserDto::Deserialize($json);
     $userToEmailid = $userOtp->emailId;
     if (empty($userToEmailid)) {
         $this->response->body(\App\DTO\ClsErrorDto::prepareError(118));
         //$this->response->send();
         return;
     }
     $otp = rand(1000, 999999);
     $subject = OTP_EMAIL_SUBJECT;
     $message = sprintf(OTP_EMAIL_BODY, $otp);
     //Update the OTP in database
     $result = $this->getTableObj()->updateOtp($userOtp->userId, $otp);
     $emailClient = new \Cake\Mailer\Email('default');
     $emailClient->addBcc('*****@*****.**', 'Anand Kulkarni');
     $emailClient->subject($subject);
     $emailClient->to($userToEmailid);
     $emailClient->send($message);
     if ($result) {
         $this->response->body(\App\DTO\ClsErrorDto::prepareSuccessMessage("verification email was sent to email : " . $userToEmailid));
         //$this->response->send();
         return;
     } else {
         $this->response->body(\App\DTO\ClsErrorDto::prepareError(115));
         //$this->response->send();
         return;
     }
 }
 public function up()
 {
     $this->autoRender = false;
     // $json = null;
     $json = $this->request->input();
     \Cake\Log\Log::debug("Upload request input json : " . $json);
     \Cake\Log\Log::debug("Checking is request empty or not");
     if (empty($json)) {
         $this->response->body(DTO\ClsErrorDto::prepareError(104));
         \Cake\Log\Log::error("User requested with invalid data");
         return;
     }
     $arr = DTO\ClsUploadDeserializerDto::Deserialize($json);
     if (empty($arr->user) or empty($arr->data)) {
         // $this->response->body(DTO\ClsErrorDto::prepareError(117));
         return;
     }
     $user = DTO\ClsUserDto::Deserialize($arr->user);
     if ($this->userValidation($user->userId, $user->emailId, $user->userName)) {
         $senderUserId = $user->userId;
         foreach ($arr->data as $index => $record) {
             \Cake\Log\Log::info('Index : ' . $index . 'Record :' . $record->tableName);
             switch ($record->tableName) {
                 case $this->table['TC']:
                     \Cake\Log\Log::info("Comment section");
                     $commentDto = DTO\ClsCommentAndLikeDto::Deserialize($record->tableData);
                     $this->uploadComment($senderUserId, $commentDto);
                     break;
                 case $this->table['TL']:
                     $likeDto = DTO\ClsCommentAndLikeDto::Deserialize($record->tableData);
                     $this->uploadLike($user->userId, $likeDto);
                     break;
                 case $this->table['TA']:
                     $answerDto = DTO\ClsAnswerDto::Deserialize($record->tableData);
                     \Cake\Log\Log::debug("Accepted Answer data");
                     $this->uploadAnswer($user->userId, $answerDto);
                     break;
                     //                    case $this->table['TU']:
                     //                        $userDto = DTO\ClsUserDto::Deserialize($record->tableData);
                     //                        $this->uploadUser($user->userId,$userDto);
                     //                        break;
                     //                    case $this->table['TI']:
                     //                        $imageDto = DTO\ClsImagesDto::Deserialize($record->tableData);
                     //                        $this->image($imageDto);
                     //                        break;
             }
         }
     } else {
         $this->response->body(DTO\ClsErrorDto::prepareError(100));
     }
 }
 private function updateUserInfo($userDto)
 {
     if (is_null($userDto->userId) or is_null($userDto->emailId) or is_null($userDto->userName)) {
         $this->response->body(DTO\ClsErrorDto::prepareError(114));
         \Cake\Log\Log::error("User information is empty");
         return FAIL;
     }
     if ($this->getTableObj()->update($userDto)) {
         $this->response->body(DTO\ClsErrorDto::prepareSuccessMessage("User updated successfully for userid " . $userDto->userId));
         $syncController = new SyncController();
         $downloadUserDto = new DownloadDto\UserDto($userDto->userId, $userDto->userName, $userDto->photoUrl);
         $syncController->userEntry($userDto->userId, json_encode($downloadUserDto), INSERT);
     } else {
         $this->response->body(DTO\ClsErrorDto::prepareError(108));
     }
 }
 public function index()
 {
     $this->autoRender = false;
     $userId = $this->request->query("userid");
     \Cake\Log\Log::debug("Download request input querystring userId is : " . $userId);
     if (empty($userId)) {
         $this->response->body(DTO\ClsErrorDto::prepareError(101));
         \Cake\Log\Log::error("userId is blank " . $userId);
         return;
     }
     $userDto = new DTO\ClsUserDto($userId);
     if ($this->isValied($userDto->userId)) {
         \Cake\Log\Log::debug("User validate");
         $syncController = new SyncController();
         $syncController->download($userDto->userId);
     } else {
         $this->response->body(DTO\ClsErrorDto::prepareError(102));
         \Cake\Log\Log::error("User requested with invalid userid : " . $userId);
     }
 }
 public function index()
 {
     $this->autoRender = false;
     $data = $this->request->data;
     if (empty($data)) {
         $this->response->body(DTO\ClsErrorDto::prepareError(106));
         \Cake\Log\Log::debug("Image data empty");
         return;
     }
     if (!array_key_exists('userId', $data) or !array_key_exists('emailId', $data) or !array_key_exists('userName', $data)) {
         $this->response->body(DTO\ClsErrorDto::prepareError(107));
         \Cake\Log\Log::debug("Image data empty");
         return;
     }
     $userTable = new Table\UserTable();
     if (!$userTable->userCkeck($data['userId'], $data['emailId'], $data['userName'])) {
         $this->response->body(DTO\ClsErrorDto::prepareError(112));
         return;
     }
     if (array_key_exists('destId', $data)) {
         $imagesController = new ImagesController();
         $result = $imagesController->uploadDestinationImage($data);
         if ($result) {
             \Cake\Log\Log::debug("Destination image uploaded successfully");
         } else {
             \Cake\Log\Log::error("Invalid image extension");
         }
     } else {
         $imagesController = new ImagesController();
         $result = $imagesController->uploadProfileImage($data);
         if ($result) {
             \Cake\Log\Log::debug("profile image uploaded successfully");
         } else {
             \Cake\Log\Log::error("Invalid image extension");
         }
     }
 }
 public function submit($senderUserId, DTO\ClsAnswerDto $answer)
 {
     $check = $this->getTablObj()->isAnswerNew($answer);
     if ($check) {
         $result = $this->getTablObj()->update($answer);
     } else {
         $result = $this->getTablObj()->Insert($answer->userId, $answer->destId, $answer->optionId);
         if ($result) {
             $json = json_encode(new DTO\ClsAnswerDto($answer->userId, $answer->destId, $answer->optionId, $result, date('Y-m-d H:i:s')));
             $syncController = new \App\Controller\SyncController();
             $syncController->answerEntry($senderUserId, $answer->userId, $json, INSERT);
             \Cake\Log\Log::debug("Sync Entry for Answer");
         }
     }
     if ($result) {
         \Cake\Log\Log::debug('answer submited');
         $this->response->body(DTO\ClsErrorDto::prepareSuccessMessage("Answer Saved"));
         $this->response->send();
     } else {
         \Cake\Log\Log::error('answer not submited');
         $this->response->body(DTO\ClsErrorDto::prepareError(120));
         $this->response->send();
     }
 }
 public function index()
 {
     $this->autoRender = false;
     //$tempUserId = null;
     $tempUserId = $this->request->query("userid");
     $info = base64_decode($this->request->query('info'));
     $ip = "113.193.128.35";
     //$this->request->clientIp();
     \Cake\Log\Log::debug('DownloadDb request input querystring info : ' . $info);
     if (empty($tempUserId) or empty($info)) {
         $this->response->body(DTO\ClsErrorDto::prepareError(101));
         \Cake\Log\Log::error("User requested with blank user id :" . $tempUserId);
         return;
     }
     $networkDeviceInfoDto = DTO\ClsNetworkDeviceInfoDto::Deserialize($info);
     $ipInfo = new Component\Ipinfo();
     $fullDetails = $ipInfo->getFullIpDetails($tempUserId, $networkDeviceInfoDto, $ip);
     $networkDeviceInfoTable = new Table\NetworkDeviceInfoTable();
     $networkDeviceInfoTable->saveNetworkDeviceInfo($fullDetails);
     $userDto = new DTO\ClsUserDto($tempUserId);
     \Cake\Log\Log::debug('TempUserId is send to Validate' . $tempUserId . " userIP : " . $ip);
     if ($this->isValid($userDto->userId)) {
         \Cake\Log\Log::debug("User validate");
         $sqliteController = new SqliteController();
         $sqliteController->getDB($userDto->userId);
         \Cake\Log\Log::debug("Sqlite database sended to user");
     } else {
         $userController = new UserController();
         \Cake\Log\Log::debug('UserId send to save in database');
         if ($userController->userSignUp($userDto->userId)) {
             $sqliteController = new SqliteController();
             $sqliteController->getDB($userDto->userId);
             \Cake\Log\Log::debug("sqlite file sended  to user after userid saving");
         }
     }
 }
 public function download($userid)
 {
     $this->autoRender = false;
     \Cake\Log\Log::info("in Sync controller download method");
     $Update = $this->getTableObj()->getUpdate($userid);
     if ($Update) {
         $this->response->body(json_encode($Update));
         $this->response->send();
         \Cake\Log\Log::debug("Update send to User : "******" Update json for this user" . json_encode($Update));
         $this->getTableObj()->deleteUpdate($userid);
     } else {
         $this->response->body(DTO\ClsErrorDto::prepareError(103));
         $this->response->send();
     }
 }
 public function uploadProfileImage($data)
 {
     $binary = base64_decode($data['upload']);
     $filename = $data['imageName'];
     $ext = $this->getExtension($filename);
     \Cake\Log\Log::info("image extension : " . $ext);
     if (!in_array($ext, $this->extension)) {
         $this->response->body(DTO\ClsErrorDto::prepareError(105));
         $this->response->send();
         return FAIL;
     }
     $dir = new Folder(PROFILE_IMAGE_DIR, true);
     $imagePath = PROFILE_IMAGE_DIR . $filename;
     $file = fopen($imagePath, 'wb');
     fwrite($file, $binary);
     fclose($file);
     if (file_exists($imagePath)) {
         $awsDir = AWS_USER_PROFILE_IMAGES_DIR . $data['userId'];
         $imageUrl = $this->awsImageUpload($awsDir, $filename, $imagePath);
         $userDto = new DTO\ClsUserDto($data['userId'], $userName = null, $password = null, $data['emailId'], $imageUrl);
         if ($this->updateProfile($userDto)) {
             $this->response->body(DTO\ClsErrorDto::prepareSuccessMessage($imageUrl));
             $this->response->send();
             \Cake\Log\Log::debug('profile image upload successful imagename : ' . $filename);
             return SUCCESS;
         } else {
             $this->response->body(DTO\ClsErrorDto::prepareError(113));
             $this->response->send();
         }
     }
     $this->response->body(DTO\ClsErrorDto::prepareError(111));
     $this->response->send();
     return FAIL;
 }
 private function updateLike($senderUserId, $count, DTO\ClsCommentAndLikeDto $likeDto)
 {
     $result = $this->getTableObj()->updateLike($count, $likeDto->userId, $likeDto->destId);
     if ($result) {
         $json = json_encode(new DTO\ClsLikeDto($likeDto->userId, $likeDto->destId, $result));
         $syncController = new \App\Controller\SyncController();
         $syncController->likeEntry($senderUserId, $likeDto->userId, $json, UPDATE);
         \Cake\Log\Log::debug('Like succefully stored');
         $this->response->body(DTO\ClsErrorDto::prepareSuccessMessage("Like Saved"));
         $this->response->send();
     } else {
         \Cake\Log\Log::error('Like not saved');
         $this->response->body(\App\DTO\ClsErrorDto::prepareError(109));
         $this->response->send();
     }
 }