HEX
Server: Apache/2.4.46 (Ubuntu)
System: Linux localhost 5.11.0-49-generic #55-Ubuntu SMP Wed Jan 12 17:36:34 UTC 2022 x86_64
User: root (0)
PHP: 7.4.16
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/html/fieldsblaze-heroku/app/Http/Controllers/APIUserController.php
<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Validator;
use DB;
use App\Library\UserLib;
use App\Models\User;
use App\Models\UserProfile;
use App\Models\Profiles;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\File;

class APIUserController extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    protected $userLib;
    protected $TeamList = array();
    public function __construct(UserLib $userLib)
	{
		$this->userLib = $userLib;
	}



//User get getUserRoleList

public function getUserRoleList($ManagerId='') {

    //Check Memeber is exist or not
    $users = User::select('UserId', 'FirstName', 'LastName', 'Email','Mobile', 'ManagerId', 'ProfileId')
                   ->where('ManagerId',$ManagerId)
                   ->get();
    if ($users->count() > 0)
    {   //email is exist
        foreach ($users as $key => $UValue)
        {
            $UserId = $UValue['UserId'];
            $FirstName = $UValue['FirstName'];
            $LastName = $UValue['LastName'];
            $ManagerId = $UValue['ManagerId'];

            $this->TeamList[] = $UValue;
            //echo 'UserId - '.$UserId .'('.$FirstName.') '.', ManagerId - '.$ManagerId."\n";
            if($UserId){
            $this->getUserRoleList($UserId);
            }
        }
    }
   return $responseData = $this->TeamList;
    //return response()->json($responseData);
}


public function getUserRoleListHtml($ManagerId='') {

    //Check Memeber is exist or not

    // $Order = Customer::select('tbl_order.*')
    //         ->leftJoin('tbl_order', 'tbl_customer.CustomerId', '=', 'tbl_order.CustomerId')
    //         ->where('tbl_customer.IsDeleted', '=', '0')
    //         ->where('tbl_order.IsDeleted', '=', '0')
    //         ->where('tbl_order.Created_at', 'like', '%'. $today.'%')
    //         ->where('tbl_order.Created_by',$UserId)
    //         ->orderBy('tbl_order.id', 'desc')
    //         ->get();



        $users = User::select('UserId', 'FirstName', 'LastName', 'Email','Mobile', 'ManagerId', 'tbl_user.ProfileId', 'ProfileName')
                ->leftJoin('tbl_profiles', 'tbl_user.ProfileId', '=', 'tbl_profiles.ProfileId')
                ->where('tbl_user.ManagerId',$ManagerId)
                ->orderBy('tbl_profiles.InOrder', 'ASC')
                ->get();
    if ($users->count() > 0)
    {   //email is exist
        foreach ($users as $key => $UValue)
        {
            $UserId = $UValue['UserId'];
            $FirstName = $UValue['FirstName'];
            $LastName = $UValue['LastName'];
            $ManagerId = isset($UValue['ManagerId']) ? $UValue['ManagerId'] : '';
            $ProfileName = $UValue['ProfileName'];
            $UValue['IsTeam'] = 'false';

            $userTeamCount = User::select('UserId', 'FirstName', 'LastName', 'Email','Mobile', 'ManagerId', 'ProfileId')
                   ->where('ManagerId',$UserId)
                   ->get();
            $teamCount = $userTeamCount->count();


            if($teamCount > 0)
            {
                $UValue['IsTeam'] = 'true';
            }


            $this->TeamList[] = $UValue;
            //echo 'UserId - '.$UserId .'('.$FirstName.') - ('.$ProfileName.') '.', ManagerId - '.$ManagerId."\n";
            $this->getUserRoleListHtml($UserId);
        }
    }
   return $responseData = $this->TeamList;
    //return response()->json($responseData);
}

//Manager team list
public function getManagerTeamList(Request $request, $ManagerId =''){


    $data = $request->json()->all();

    $UserId = $request->header('UserId');
    $AuthToken = $request->header('AuthToken');

    //check auth token
    if($this->userLib->tokenChecker($request) == FALSE)
    {
        $response = [
            'success' => false,
            'ResponseMessage' => "Authentication Failed",
            'ResponseCode' => "301",
            'ApiVersion' => env('APP_VERSION'),
        ];
        return response()->json($response);
    }
    if($ManagerId)
    {
        $TeamList = $this->getUserRoleListHtml($ManagerId);
    }
    else
    {
        $TeamList = $this->getUserRoleListHtml($UserId);
    }
    $response = [
        'Success' => true,
        'ResponseMessage' => "Success",
        'ResponseCode' => "200",
        'AuthToken' => $AuthToken,
        'TeamList' => $TeamList,
        'ApiUrl' => env('APP_URL'),
        'ApiVersion' => env('APP_VERSION'),
    ];
    return response()->json($response);
}


//Team List
public function getTeamList(Request $request, $CustomerTypeId =''){


    $data = $request->json()->all();

    $UserId = $request->header('UserId');
    $AuthToken = $request->header('AuthToken');

    //check auth token
    if($this->userLib->tokenChecker($request) == FALSE)
    {
        $response = [
            'success' => false,
            'ResponseMessage' => "Authentication Failed",
            'ResponseCode' => "301",
            'ApiVersion' => env('APP_VERSION'),
        ];
        return response()->json($response);
    }
    $TeamList = $this->getUserRoleList($UserId);
    $response = [
        'Success' => true,
        'ResponseMessage' => "Success",
        'ResponseCode' => "200",
        'AuthToken' => $AuthToken,
        'TeamList' => $TeamList,
        'ApiUrl' => env('APP_URL'),
        'ApiVersion' => env('APP_VERSION'),
    ];
    return response()->json($response);
}


    //User Registration
    public function createUserWithOtp(Request $request) {
		//TODO What is device_token
        $data = $request->json()->all();

        $UserId = $this->userLib->useridGenrator();
        $OtpPassword = $this->userLib->otpGenrator();

        $tblData = array();

        $CreatedDate = date('Y-m-d H:i:s',time());
        $UpdatedDate = date('Y-m-d H:i:s',time());
        $ModifiedDate = date('Y-m-d H:i:s',time());

		$validator = Validator::make($data, [
			'Mobile' => 'required|string|max:255',
        ]);
        //check validation
        if ($validator->fails())
        {
            $response = [
                'Success' => false,
                'ResponseMessage' => "Mobile is required!",
                'ResponseCode' => '220',
                'ApiVersion' => env('APP_VERSION'),
            ];
            return response()->json($response);
        }

        //Check Memeber is exist or not
        $user = User::where('Mobile', $data['Mobile'])->get();
        if ($user->count() > 0)
        {   //email is not exist

            $user = $user->first();
            $UserId = $user->UserId;
            $OtpPassword = $user->OtpPassword;
            $OtpCreatedDate = $user->OtpCreatedDate;
            $OtpVerified = $user->OtpVerified;
            $UpdatedDate = $user->Updated_at;
            $ModifiedDate = $user->ModifiedDate;

            $data['UserId'] = $UserId;
            $data['OtpPassword'] = (string) $OtpPassword;
            $data['OtpCreatedDate'] = $OtpCreatedDate;
            $data['OtpVerified'] = $OtpVerified;
            $data['Updated_at'] = $UpdatedDate;
            $data['ModifiedDate'] = $ModifiedDate;

            $response = [
                'Success' => false,
                'ResponseMessage' => "Mobile number already exist!",
                'ResponseCode' => "200",
                'UserId' => $UserId,
                'User' => $data,
                'ApiUrl' => env('APP_URL'),
                'ApiVersion' => env('APP_VERSION'),
            ];
            return response()->json($response);


        }
        else
        {   //get user data
            $data['UserId'] = $UserId;
            $data['OtpPassword'] = $OtpPassword;
            $data['OtpCreatedDate'] = $CreatedDate;
            $data['Created_at'] = $CreatedDate;
            $data['Updated_at'] = $UpdatedDate;
            $data['ModifiedDate'] = $ModifiedDate;
            $data['OtpVerified'] = 0;
            $data['ProfileId'] = '8nYmY3jNKheU8Bq4Ho11CgsBW0LhFw8O3YcJI';
            // print_r($data);exit;
            $user_insert = DB::connection('DBD')->table('tbl_user')->insert($data);
            if($user_insert)
            {
                //get user details

                $FirstName = '';
                $LastName = '';
                $TemPassword = '';
                $Password = '';
                $CompanyName = '';
                $Mobile =  $data['Mobile'];
                $Department = '';
                $AboutMe = '';
                $CommunityNickname = '';
                $Address = '';
                $City = '';
                $Country = '';
                $State = '';
                $PostalCode = '';
                $OtpCreatedDate = $CreatedDate;
                $OtpVerified = '0';
                $ProfileId = '';
                $AssignExpenseAmount = '';
                $IsDeleted = '';
                $Status = '';
                $CrmId = $data['CrmId'];
                $ProfileId = $data['ProfileId'];



                $queryPG = "insert into salesforce.User__c (UserId__c,Mobile__c,Otp_Created_Date__c, CrmId__c, Otp_Password__c, ProfileId__c) values ('$UserId','$Mobile','$OtpCreatedDate','$CrmId', '$OtpPassword', '$ProfileId')";

                DB::connection('pgsql')->insert($queryPG);


                $response = [
                    'Success' => true,
                    'ResponseMessage' => "Mobile number has been registered",
                    'ResponseCode' => "200",
                    'UserId' => $UserId,
                    'User' => $data,
                    'ApiUrl' => env('APP_URL'),
                    'ApiVersion' => env('APP_VERSION'),
                    'queryPG'=>$queryPG
                ];
                return response()->json($response);
            }
            else
            {
                // fail
                $response = [
                    'Success' => false,
                    'ResponseMessage' => "Invalid data",
                    'ResponseCode' => "202",
                    'ApiVersion' => env('APP_VERSION'),
                ];
                return response()->json($response);
            }
        }
    }

    //User Login
    public function loginUser(Request $request) {
		//TODO What is device_token
        $data = $request->json()->all();
        $token = $this->userLib->tokenGenrator();
        $UserId = $this->userLib->useridGenrator();
        $OtpPassword = $this->userLib->otpGenrator();

        $tblData = array();

        $CreatedDate = date('Y-m-d H:i:s',time());
        $UpdatedDate = date('Y-m-d H:i:s',time());
        $ModifiedDate = date('Y-m-d H:i:s',time());
        //$UserId = $data['UserId'];
		$validator = Validator::make($data, [
			'Mobile' => 'required|string|max:255',

        ]);
        //check validation
        if ($validator->fails())
        {
            $response = [
                'Success' => false,
                'ResponseMessage' => "Mobile / Password is required!",
                'ResponseCode' => '220',
                'ApiVersion' => env('APP_VERSION'),
            ];
            return response()->json($response);
        }

        //Check Memeber is exist or not
        $user = User::where('Mobile', $data['Mobile'])->get();

        $CrmId = isset($data['CrmId']) ? $data['CrmId'] : '';
        if($user->count() == 0)
        {
            if(!$CrmId)
            {
                $response = [
                    'success' => false,
                    'error_message' => "Please enter compnay code",
                    'error_code' => "308",
                    'ApiVersion' => env('APP_VERSION'),
                ];
                return response()->json($response);
            }
        }
        if ($user->count() > 0)
        {   //user is exist
            $user = $user->first();
            $UserId = $user->UserId;
            $isActive = $user->isActive;
            $OtpVerified = $user->OtpVerified;
            $Password = $user->Password;
            $ProfileId = $user->ProfileId;
            $ManagerId = $user->ManagerId;
            $user_profiles = DB::connection('DBD')->table('tbl_profiles')->where('ProfileId', $ProfileId)->get();
            if ($user_profiles->count() > 0)
            {   //user is exist
                $profiledata = $user_profiles->first();
                $ProfileName = $profiledata->ProfileName;
                $user->ProfileName = $ProfileName;
            }
            $user_permission = DB::connection('DBD')->table('tbl_user_permissions')->where('ProfileId', $ProfileId)->get();
            if ($user_permission->count() > 0)
            {   //user is exist
                $permissiondata = $user_permission->first();
                $user->user_permission = $permissiondata;
            }

            $ManagerName = '';
            $userManager = User::where('UserId', $ManagerId)->get();
            if ($userManager->count() > 0)
            {   //user is exist
                $userManagerData = $userManager->first();
                $ManagerName = $userManagerData->FirstName.' '.$userManagerData->LastName;
            }
            $user->ManagerName = $ManagerName;


            //check Manager
            $user->IsTeam = false;
            $userTeamCount = User::where('ManagerId',$UserId)->get();
            $teamCount = $userTeamCount->count();
            if($teamCount > 0)
            {
                $user->IsTeam = true;
            }


            $ManagerName = '';
            $UserProfileData = array();
            $UserProfiles = UserProfile::select('ModuleId','ModuleName', 'W', 'R', 'U','D','Mobile','Created_at','Updated_at')->where('ProfileId', $ProfileId)->OrderBy('ModuleName','Asc')->get();
            if ($UserProfiles->count() > 0)
            {   //user is exist
                $UserProfileData = $UserProfiles;

            }
            $user->UserProfileAccess = $UserProfileData;




            $user->TeamList = $this->getUserRoleList($UserId);




            if($OtpVerified == 0)
            {

                $data['OtpPassword'] = $OtpPassword;
                $data['OtpCreatedDate'] = $CreatedDate;

                $data['Updated_at'] = $UpdatedDate;
                $data['ModifiedDate'] = $ModifiedDate;

                $user_insert = DB::connection('DBD')->table('tbl_user')->where('UserId',$UserId)->update($data);

                $response = [
                    'success' => false,
                    'error_message' => "Your account is not verified. Please contact to Admin",
                    'error_code' => "209",
                    'ApiVersion' => env('APP_VERSION'),
                    'User' => $data,
                ];
                return response()->json($response);
            }

            if($isActive == 0)
            {
                $response = [
                    'success' => false,
                    'error_message' => "Your account is not active. Please contact to Admin",
                    'error_code' => "208",
                    'ApiVersion' => env('APP_VERSION'),
                ];
                return response()->json($response);
            }

            if($isActive == 2)
            {
                $response = [
                    'success' => false,
                    'error_message' => "Your account is not approved. Please contact to Admin",
                    'error_code' => "211",
                    'ApiVersion' => env('APP_VERSION'),
                ];
                return response()->json($response);
            }

            $tempPassword = isset($data['Password']) ? $data['Password'] : '';



            if(!$tempPassword)
            {
                $response = [
                    'success' => false,
                    'error_message' => "Please enter password",
                    'error_code' => "206",
                    'ApiVersion' => env('APP_VERSION'),
                ];
                return response()->json($response);
            }

            // echo $Password ."==". $tempPassword;
            // exit;
            if($Password && (md5(Crypt::decryptString($Password)) == md5($tempPassword)))
            {

                //get user details
                $tblData['UserId'] = $UserId;
                $tblData['AuthToken'] = $token;
                $tblData['CreatedDate'] = $CreatedDate;

                $auth = DB::connection('DBD')->table('tbl_user_auth')->insert($tblData);
                unset($user->Password);
                unset($user->ResetKey);
                unset($user->TempPassword);
                unset($user->OtpPassword);


                if($auth)
                {   // success
                    $response = [
                        'Success' => true,
                        'ResponseMessage' => "Login successfully",
                        'ResponseCode' => "200",
                        'UserId' => $UserId,
                        'AuthToken' => $token,
                        'Auth' => $auth,
                        'User' => $user,
                        'ApiUrl' => env('APP_URL'),
                        'ApiVersion' => env('APP_VERSION'),
                    ];
                }
                else
                {
                    // fail
                    $response = [
                        'Success' => false,
                        'ResponseMessage' => "Invalid Auth",
                        'ResponseCode' => "203",
                        'Auth' => $auth ,
                        'ApiVersion' => env('APP_VERSION'),
                    ];
                }
                return response()->json($response);

            }
            else
            {
                $response = [
                    'Success' => false,
                    'ResponseMessage' => "Invalid password!",
                    'ResponseCode' => "203",
                    'ApiVersion' => env('APP_VERSION'),
                ];
                return response()->json($response);
            }

        }
        else
        {

            //Check Memeber is exist or not
            $user = User::where('Mobile', $data['Mobile'])->get();
            if ($user->count() > 0)
            {   //email is not exist

                $user = $user->first();
                $UserId = $user->UserId;
                $OtpPassword = $user->OtpPassword;
                $OtpCreatedDate = $user->OtpCreatedDate;
                $OtpVerified = $user->OtpVerified;

                $data['OtpVerified'] = $OtpVerified;
                $data['UserId'] = $UserId;
                $data['OtpPassword'] = (string) $OtpPassword;
                $data['OtpCreatedDate'] = $OtpCreatedDate;

                $response = [
                    'Success' => false,
                    'ResponseMessage' => "Mobile number already exist!",
                    'ResponseCode' => "200",
                    'UserId' => $UserId,
                    'User' => $data,
                    'ApiUrl' => env('APP_URL'),
                    'ApiVersion' => env('APP_VERSION'),
                ];
                return response()->json($response);


            }
            else
            {   //get user data
                $data['UserId'] = $UserId;
                $data['OtpPassword'] = $OtpPassword;
                $data['OtpCreatedDate'] = $CreatedDate;
                $data['Created_at'] = $CreatedDate;
                $data['Updated_at'] = $UpdatedDate;
                $data['ModifiedDate'] = $ModifiedDate;

                $data['OtpVerified'] = 0;
                //$data['Status'] = 'In-Active';
                $data['ProfileId']= '8nYmY3jYKhWU8Bq4Ho11CgsBW0LhFw8O3YcJI';

                $user_insert = DB::connection('DBD')->table('tbl_user')->insert($data);
                if($user_insert)
                {
                    //get user details

                    $FirstName = "";
                    $LastName = "";
                    $TemPassword = "";
                    $Password = "";
                    $CompanyName = "";
                    $Mobile =  $data['Mobile'];
                    $Department = "";
                    $AboutMe = "";
                    $CommunityNickname = "";
                    $Address = "";
                    $City = "";
                    $Country = "";
                    $State = "";
                    $PostalCode = "";
                    $OtpCreatedDate = $CreatedDate;
                    $OtpVerified = '0';
                    $ProfileId = "";
                    $AssignExpenseAmount = "";
                    $IsDeleted = "";
                    $Status = "";
                    $Email = "";
                    $CrmId = $data['CrmId'];
                    $ProfileId = $data['ProfileId'];

                    $queryPG = "insert into salesforce.User__c (UserId__c,FirstName__c,LastName__c,Email__c,Mobile__c,Temp_Password__c,Password__c,Company_Name__c,Department__c,About_Me__c,Community_Nick_name__c,Address__c,City__c,Country__c,State__c	,PostalCode__c,Otp_Created_Date__c,Otp_Verified__c,ProfileId__c,Assign_Expense_Amount__c,Is_Deleted__c,Status__c, CrmId__c, Otp_Password__c) values ('$UserId','$FirstName','$LastName','$Email','$Mobile','$TemPassword','$Password','$CompanyName','$Department','$AboutMe','$CommunityNickname','$Address','$City','$Country','$State','$PostalCode','$OtpCreatedDate','$OtpVerified','$ProfileId','$AssignExpenseAmount','$IsDeleted','$Status','$CrmId', '$OtpPassword')";



                    $queryPG = "insert into salesforce.User__c (UserId__c,Mobile__c,Otp_Created_Date__c, CrmId__c, Otp_Password__c, ProfileId__c) values ('$UserId','$Mobile','$OtpCreatedDate','$CrmId', '$OtpPassword', '$ProfileId')";

                    DB::connection('pgsql')->insert($queryPG);

                    $response = [
                        'Success' => true,
                        'ResponseMessage' => "Mobile number has been registered",
                        'ResponseCode' => "200",
                        'UserId' => $UserId,
                        'User' => $data,
                        'ApiUrl' => env('APP_URL'),
                        'ApiVersion' => env('APP_VERSION'),
                        'queryPG'=> $queryPG
                    ];
                    return response()->json($response);
                }
                else
                {
                    // fail
                    $response = [
                        'Success' => false,
                        'ResponseMessage' => "Invalid data",
                        'ResponseCode' => "202",
                        'ApiVersion' => env('APP_VERSION'),
                    ];
                    return response()->json($response);
                }
            }

        }
    }

    //User Registration
    public function otpVerificationUser(Request $request) {
		//TODO What is device_token
        $data = $request->json()->all();
        $token = $this->userLib->tokenGenrator();

        $OtpPassword = $this->userLib->otpGenrator();

        $tblData = array();

        $CreatedDate = date('Y-m-d H:i:s',time());
        //$UserId = $data['UserId'];
		$validator = Validator::make($data, [
			'Mobile' => 'required|string|max:255',
        ]);
        //check validation
        if ($validator->fails())
        {
            $response = [
                'Success' => false,
                'ResponseMessage' => "Mobile is required!",
                'ResponseCode' => '220',
                'ApiVersion' => env('APP_VERSION'),
            ];
            return response()->json($response);
        }

        //Check Memeber is exist or not
        $user = User::where('Mobile', $data['Mobile'])->get();
        if ($user->count() > 0)
        {   //user is exist
            $user = $user->first();
            $UserId = $user->UserId;
            $OtpPassword = $user->OtpPassword;

            if($OtpPassword == $data['OtpPassword'])
            {
                $udata = array();
                $udata['OtpVerified'] = 1;
                $udata['ModifiedDate'] = $CreatedDate;
                $data['ModifiedDate']= $udata['ModifiedDate'];
                $data['OtpVerified']= $udata['OtpVerified'];
                //$data['ProfileId']= '8nYmY3jNKheU8Bq4Ho11CgsBW0LhFw8O3YcJI';
                $user_update = DB::table('tbl_user')->where('Mobile',$data['Mobile'])->update($udata);


                $OtpVerified = $data['OtpVerified'];
                $Mobile = $data['Mobile'];
                $queryPG = "update salesforce.User__c set otp_verified__c = '$OtpVerified', modified_date__c = '$CreatedDate' where mobile__c = '$Mobile'";
                DB::connection('pgsql')->insert($queryPG);
                if($user_update)
                {
                    //get user details
                    $tblData['UserId'] = $UserId;
                    $tblData['AuthToken'] = $token;
                    $tblData['CreatedDate'] = $CreatedDate;
                    $auth = DB::connection('DBD')->table('tbl_user_auth')->insert($tblData);
                    unset($user->Password);
                    unset($user->ResetKey);
                // unset($user_data->TempPassword);

                    if($auth)
                    {   // success
                        $response = [
                            'Success' => true,
                            'ResponseMessage' => "Mobile verification has been done successfully",
                            'ResponseCode' => "200",
                            'UserId' => $UserId,
                            'AuthToken' => $token,
                            'Auth' => $auth,
                            'User' => $data,
                            'ApiUrl' => env('APP_URL'),
                            'ApiVersion' => env('APP_VERSION'),
                            'queryPG'=>$queryPG,
                        ];
                    }
                    else
                    {
                        // fail
                        $response = [
                            'Success' => false,
                            'ResponseMessage' => "Invalid Auth",
                            'ResponseCode' => "203",
                            'Auth' => $auth ,
                            'ApiVersion' => env('APP_VERSION'),
                        ];
                    }
                    return response()->json($response);
                }
                else
                {
                    // fail
                    $response = [
                        'Success' => false,
                        'ResponseMessage' => "Invalid data",
                        'ResponseCode' => "202",
                        'ApiVersion' => env('APP_VERSION'),
                    ];
                    return response()->json($response);
                }
            }
            else
            {
                $response = [
                    'Success' => false,
                    'ResponseMessage' => "Invalid OTP!",
                    'ResponseCode' => "203",
                    'ApiVersion' => env('APP_VERSION'),
                ];
                return response()->json($response);
            }

        }
        else
        {
            $response = [
                'Success' => false,
                'ResponseMessage' => "Mobile number has not registered!",
                'ResponseCode' => "201",
                'ApiVersion' => env('APP_VERSION'),
            ];
            return response()->json($response);
        }
    }


    //otpResendUser
    public function otpResendUser(Request $request) {
		//TODO What is device_token
        $data = $request->json()->all();
        $token = $this->userLib->tokenGenrator();
        $OtpPassword = $this->userLib->otpGenrator();

        $tblData = array();

        $CreatedDate = date('Y-m-d H:i:s',time());

		$validator = Validator::make($data, [
			'Mobile' => 'required|string|max:255',
        ]);
        //check validation
        if ($validator->fails())
        {
            $response = [
                'Success' => false,
                'ResponseMessage' => "Mobile is required!",
                'ResponseCode' => '220',
                'ApiVersion' => env('APP_VERSION'),
            ];
            return response()->json($response);
        }

        //Check Memeber is exist or not
        $user = User::where('Mobile', $data['Mobile'])->get();
        if ($user->count() > 0)
        {   //email is not exist

            $user = $user->first();
            $UserId = $user->UserId;
            $udata = array();
            $udata['UserId'] = $UserId;
            $udata['Mobile']= $data['Mobile'];
            $udata['OtpPassword'] = $OtpPassword;
            $udata['ModifiedDate'] = $CreatedDate;
            $udata['CreatedDate']= $CreatedDate;


            $data['CreatedDate']= $CreatedDate;
            $user_update = DB::table('tbl_user')->where('Mobile',$data['Mobile'])->update($udata);
            if($user_update)
             {
                 //get user details

                 $response = [
                     'Success' => true,
                     'ResponseMessage' => "OTP has been sent to a registered mobile number.",
                     'ResponseCode' => "200",
                     'User' => $udata,
                     'ApiUrl' => env('APP_URL'),
                     'ApiVersion' => env('APP_VERSION'),
                 ];
                 return response()->json($response);
             }
             else
             {
                 // fail
                 $response = [
                     'Success' => false,
                     'ResponseMessage' => "Invalid data",
                     'ResponseCode' => "202",
                     'ApiVersion' => env('APP_VERSION'),
                 ];
                 return response()->json($response);
             }
        }
        else
        {
            $response = [
                'Success' => false,
                'ResponseMessage' => "Mobile number has not registered!",
                'ResponseCode' => "201",
                'ApiVersion' => env('APP_VERSION'),
            ];
            return response()->json($response);
        }
    }





    //User create first time password
    public function userCreateFirstTimePassword(Request $request) {
		//TODO What is device_token
        $data = $request->json()->all();
        $token = $this->userLib->tokenGenrator();
        $OtpPassword = $this->userLib->otpGenrator();

        $tblData = array();

        $CreatedDate = date('Y-m-d H:i:s',time());

		$validator = Validator::make($data, [
			'Mobile' => 'required|string|max:255',
            'Password' => 'required|string|max:255',
        ]);
        //check validation
        if ($validator->fails())
        {
            $response = [
                'Success' => false,
                'ResponseMessage' => "Mobile is required!",
                'ResponseCode' => '220',
                'ApiVersion' => env('APP_VERSION'),
            ];
            return response()->json($response);
        }

        //Check Memeber is exist or not
        $user = User::where('Mobile', $data['Mobile'])->get();
        if ($user->count() > 0)
        {   //email is exist
            $user = $user->first();
            $UserId = $user->UserId;
            //update password
            $data['TempPassword'] = $data['Password'];
            $data['Password'] = Crypt::encryptString($data['Password']);
            //$data['OtpPassword'] = $OtpPassword;
            $data['ModifiedDate'] = $CreatedDate;
            // $data['IsActive'] = 1;
            // $data['Status'] = "Activated";

            $data['isActive'] = 2;
            $data['Status'] = "Submitted";


            $user_update = DB::table('tbl_user')->where('UserId',$UserId)->update($data);
            if($user_update)
            {
                $user_details = User::where('Mobile', $data['Mobile'])->get();
                $user_data = $user_details->first();
                //create auth token
                $tblData['UserId'] = $user_data->UserId;
                $tblData['AuthToken'] = $token;
                $tblData['CreatedDate'] = $CreatedDate;

                $responseData = array();

                $responseData['Mobile'] = $data['Mobile'];
               // $auth = DB::connection('DBD')->table('tbl_user_auth')->insert($tblData);
                unset($user_data->Password);
                unset($user_data->ResetKey);
               // unset($user_data->TempPassword);

                // success
                $response = [
                    'Success' => true,
                    'ResponseMessage' => "Password has been created successfully, Please login.",
                    'ResponseCode' => "200",
                    'UserId' => $user_data->UserId,
                    //'AuthToken' => $token,
                    //  'Auth' => $auth,
                    'User' => $responseData,
                    'ApiUrl' => env('APP_URL'),
                    'ApiVersion' => env('APP_VERSION'),
                ];


                return response()->json($response);
            }
        }
        else
        {
            $response = [
                'Success' => false,
                'ResponseMessage' => "User not exist",
                'ResponseCode' => "201",
                'ApiVersion' => env('APP_VERSION'),
            ];
            return response()->json($response);

            //get user data
            $data['UserId'] = $UserId;
            $data['TempPassword'] = $data['Password'];
            $data['Password'] = Crypt::encryptString($data['Password']);
            $data['OtpPassword'] = $OtpPassword;
            $data['ModifiedDate'] = $CreatedDate;
            $data['Created_at'] = $CreatedDate;
            $data['Updated_at'] = $CreatedDate;

            $user_insert = DB::connection('DBD')->table('tbl_user')->insert($data);
            if($user_insert)
            {
                //get user details

            }
            else
            {
                // fail
                $response = [
                    'Success' => false,
                    'ResponseMessage' => "Invalid data",
                    'ResponseCode' => "202",
                    'ApiVersion' => env('APP_VERSION'),
                ];
                return response()->json($response);
            }
        }
    }


    //Forgot Password OTP send
    public function userForgotPasswordOtpSend(Request $request) {
		//TODO What is device_token
        $data = $request->json()->all();
        $token = $this->userLib->tokenGenrator();
        $OtpPassword = $this->userLib->otpGenrator();

        $tblData = array();

        $CreatedDate = date('Y-m-d H:i:s',time());

        //check auth token


		$validator = Validator::make($data, [
			'Mobile' => 'required|string|max:255',
        ]);
        //check validation
        if ($validator->fails())
        {
            $response = [
                'Success' => false,
                'ResponseMessage' => "Mobile is required!",
                'ResponseCode' => '220',
                'ApiVersion' => env('APP_VERSION'),
            ];
            return response()->json($response);
        }

        //Check Memeber is exist or not
        $user = User::where('Mobile', $data['Mobile'])->get();
        if ($user->count() > 0)
        {   //email is exist
            $user = $user->first();
            $UserId = $user->UserId;
            $OtpVerified = $user->OtpVerified;
            $isActive = $user->isActive;




            if($OtpVerified == 0)
            {

                $data['OtpPassword'] = $OtpPassword;
                $data['OtpCreatedDate'] = $CreatedDate;

                $data['Updated_at'] = $UpdatedDate;
                $data['ModifiedDate'] = $ModifiedDate;

                $user_insert = DB::connection('DBD')->table('tbl_user')->where('UserId',$UserId)->update($data);

                $response = [
                    'success' => false,
                    'error_message' => "Your account is not verified. Please contact to Admin",
                    'error_code' => "209",
                    'ApiVersion' => env('APP_VERSION'),
                    'User' => $data,
                ];
                return response()->json($response);
            }

            if($isActive == 0)
            {
                $response = [
                    'success' => false,
                    'error_message' => "Your account is not active. Please contact to Admin",
                    'error_code' => "208",
                    'ApiVersion' => env('APP_VERSION'),
                ];
                return response()->json($response);
            }

            if($isActive == 2)
            {
                $response = [
                    'success' => false,
                    'error_message' => "Your account is not approved. Please contact to Admin",
                    'error_code' => "211",
                    'ApiVersion' => env('APP_VERSION'),
                ];
                return response()->json($response);
            }
            //update password
            //$data['TempPassword'] = $data['Password'];
            //$data['Password'] = Crypt::encryptString($data['Password']);
            $ndata = array();
            $ndata['OtpPassword'] = $OtpPassword;
            //$data['ModifiedDate'] = $CreatedDate;


            $user_update = DB::table('tbl_user')->where('UserId',$UserId)->update($ndata);
            if($user_update)
            {
                $response = [
                    'Success' => true,
                    'ResponseMessage' => "Success",
                    'ResponseCode' => "200",
                    'UserId' => $UserId,

                    'OtpPassword' => $OtpPassword,
                    'ApiUrl' => env('APP_URL'),
                    'ApiVersion' => env('APP_VERSION'),
                ];
            }
            else
            {
                // fail
                $response = [
                    'Success' => false,
                    'ResponseMessage' => "Invalid data",
                    'ResponseCode' => "203",

                    'ApiVersion' => env('APP_VERSION'),
                ];
            }
            return response()->json($response);

        }
        else
        {
            // fail
            $response = [
                'Success' => false,
                'ResponseMessage' => "Invalid data",
                'ResponseCode' => "206",

                'ApiVersion' => env('APP_VERSION'),
            ];

            return response()->json($response);
        }
    }
    //Forgot Password

    //New password set

    public function userForgotPasswordUpdate(Request $request) {
        //TODO What is device_token
        $data = $request->json()->all();
        $token = $this->userLib->tokenGenrator();
        $OtpPassword = $this->userLib->otpGenrator();

        $tblData = array();

        $CreatedDate = date('Y-m-d H:i:s',time());

        //check auth token


        $validator = Validator::make($data, [
            'Mobile' => 'required|string|max:255',
            'Password' => 'required|string|max:255',
        ]);
        //check validation
        if ($validator->fails())
        {
            $response = [
                'Success' => false,
                'ResponseMessage' => "Mobile is required!",
                'ResponseCode' => '220',
                'ApiVersion' => env('APP_VERSION'),
            ];
            return response()->json($response);
        }

        //Check Memeber is exist or not
        $user = User::where('Mobile', $data['Mobile'])->where('OtpPassword', $data['OtpPassword'])->get();
        if ($user->count() > 0)
        {   //email is exist
            $user = $user->first();
            $UserId = $user->UserId;
            //update password
            $ndata = array();
            $ndata['TempPassword'] = $data['Password'];
            $ndata['Password'] = Crypt::encryptString($data['Password']);

            //$ndata['OtpPassword'] = $OtpPassword;
            $ndata['ModifiedDate'] = $CreatedDate;


            $user_update = DB::table('tbl_user')->where('UserId',$UserId)->update($ndata);
            if($user_update)
            {
                $response = [
                    'Success' => true,
                    'ResponseMessage' => "Success",
                    'ResponseCode' => "200",
                    'UserId' => $UserId,
                    'ApiUrl' => env('APP_URL'),
                    'ApiVersion' => env('APP_VERSION'),
                ];
            }
            else
            {
                // fail
                $response = [
                    'Success' => false,
                    'ResponseMessage' => "Invalid data",
                    'ResponseCode' => "203",

                    'ApiVersion' => env('APP_VERSION'),
                ];
            }
            return response()->json($response);

        }
        else
        {
            // fail
            $response = [
                'Success' => false,
                'ResponseMessage' => "Invalid data",
                'ResponseCode' => "206",

                'ApiVersion' => env('APP_VERSION'),
            ];

            return response()->json($response);
        }
    }

    //New password set


    //User create first time password
    public function userChangePassword(Request $request) {
		//TODO What is device_token
        $data = $request->json()->all();
        $token = $this->userLib->tokenGenrator();
        $OtpPassword = $this->userLib->otpGenrator();

        $tblData = array();

        $CreatedDate = date('Y-m-d H:i:s',time());

        //check auth token
        if($this->userLib->tokenChecker($request) == FALSE)
        {
            $response = [
                'success' => false,
                'error_message' => "Authentication Failed",
                'error_code' => "301",
                'ApiVersion' => env('APP_VERSION'),
            ];
            return response()->json($response);
        }

		$validator = Validator::make($data, [
			'Mobile' => 'required|string|max:255',
            'Password' => 'required|string|max:255',
        ]);
        //check validation
        if ($validator->fails())
        {
            $response = [
                'Success' => false,
                'ResponseMessage' => "Mobile is required!",
                'ResponseCode' => '220',
                'ApiVersion' => env('APP_VERSION'),
            ];
            return response()->json($response);
        }

        //Check Memeber is exist or not
        $user = User::where('Mobile', $data['Mobile'])->get();
        if ($user->count() > 0)
        {   //email is exist
            $user = $user->first();
            $UserId = $user->UserId;
            //update password
            $data['TempPassword'] = $data['Password'];
            $data['Password'] = Crypt::encryptString($data['Password']);
            //$data['OtpPassword'] = $OtpPassword;
            $data['ModifiedDate'] = $CreatedDate;


            $user_update = DB::table('tbl_user')->where('UserId',$UserId)->update($data);
            if($user_update)
            {
                $user_details = User::where('Mobile', $data['Mobile'])->get();
                $user_data = $user_details->first();
                //create auth token
                $tblData['UserId'] = $user_data->UserId;
                $tblData['AuthToken'] = $token;
                $tblData['CreatedDate'] = $CreatedDate;
                $auth = DB::connection('DBD')->table('tbl_user_auth')->insert($tblData);
                unset($user_data->Password);
                unset($user_data->ResetKey);
               // unset($user_data->TempPassword);

                if($auth)
                {   // success
                    $response = [
                        'Success' => true,
                        'ResponseMessage' => "Success",
                        'ResponseCode' => "200",
                        'UserId' => $user_data->UserId,
                        'AuthToken' => $token,
                        'Auth' => $auth,
                        'User' => $user_data,
                        'ApiUrl' => env('APP_URL'),
                        'ApiVersion' => env('APP_VERSION'),
                    ];
                }
                else
                {
                    // fail
                    $response = [
                        'Success' => false,
                        'ResponseMessage' => "Invalid Auth",
                        'ResponseCode' => "203",
                        'Auth' => $auth,
                        'ApiVersion' => env('APP_VERSION'),
                    ];
                }
                return response()->json($response);
            }
        }
        else
        {
            $response = [
                'Success' => false,
                'ResponseMessage' => "User not exist",
                'ResponseCode' => "201",
                'ApiVersion' => env('APP_VERSION'),
            ];
            return response()->json($response);

            //get user data
            $data['UserId'] = $UserId;
            $data['TempPassword'] = $data['Password'];
            $data['Password'] = Crypt::encryptString($data['Password']);
            $data['OtpPassword'] = $OtpPassword;
            $data['ModifiedDate'] = $CreatedDate;
            $data['Created_at'] = $CreatedDate;
            $data['Updated_at'] = $CreatedDate;


            $user_insert = DB::connection('DBD')->table('tbl_user')->insert($data);
            if($user_insert)
            {

                //get user details

            }
            else
            {
                // fail
                $response = [
                    'Success' => false,
                    'ResponseMessage' => "Invalid data",
                    'ResponseCode' => "202",
                    'ApiVersion' => env('APP_VERSION'),
                ];
                return response()->json($response);
            }
        }
    }



    //User edit profile
    public function userEditProfile(Request $request) {
		//TODO What is device_token
        $data = $request->json()->all();
        $OtpPassword = $this->userLib->otpGenrator();
        $tblData = array();
        $CreatedDate = date('Y-m-d H:i:s',time());

        $UserId = $request->header('UserId');
        $AuthToken = $request->header('AuthToken');




        //check auth token
        if($this->userLib->tokenChecker($request) == FALSE)
        {
            $response = [
                'success' => false,
                'error_message' => "Authentication Failed",
                'error_code' => "301",
                'ApiVersion' => env('APP_VERSION'),
            ];
            return response()->json($response);
        }


        //check validation
        if (empty($data['Mobile']))
        {
            $response = [
                'Success' => false,
                'ResponseMessage' => "Mobile is required!",
                'ResponseCode' => '220',
                'ApiVersion' => env('APP_VERSION'),
            ];
            return response()->json($response);
        }

        //Check Memeber is exist or not
        $user = User::where('Mobile', $data['Mobile'])->get();
        if ($user->count() > 0)
        {   //email is exist
            $user = $user->first();

            $data['ModifiedDate'] = $CreatedDate;

            unset($data['TempPassword']);
            unset($data['OtpPassword']);

            unset($data['ProfileName']);
            unset($data['user_permission']);
            unset($data['ManagerName']);

            $user_update = DB::table('tbl_user')->where('UserId',$UserId)->update($data);
            if($user_update)
            {

              //  {"UserProfileImage":"user/E2UN1vRfy5soAMejdw2ZOA9TXx682Z7FyKatM-1683695387.jpg","Email":"test1@gmail.com","FirstName":"New Test","AboutMe":"This user is created for testing purpose.","UserId":"nGdHMha3FUpLtTRir9jEaUD1qVodhoEAhT26S","LastName":"User 1","Mobile":"1515151515"}

            $UserProfileImage = isset($data['UserProfileImage']) ? $data['UserProfileImage'] : '';
            $Email = isset($data['Email']) ? $data['Email'] : '';
            $FirstName = isset($data['FirstName']) ? $data['FirstName'] : '';
            $AboutMe = isset($data['AboutMe']) ? $data['AboutMe'] : '';
            $UserId = isset($data['UserId']) ? $data['UserId'] : '';
            $LastName = isset($data['LastName']) ? $data['LastName'] : '';
            $Mobile = isset($data['Mobile']) ? $data['Mobile'] : '';


            $queryPG = "update salesforce.User__c set user_profile_image__c = '$UserProfileImage', email__c = '$Email', firstname__c = '$FirstName', lastname__c = '$LastName', about_me__c = '$AboutMe', mobile__c = '$Mobile', modified_date__c = '$CreatedDate' where userid__c = '$UserId'";
            DB::connection('pgsql')->insert($queryPG);


                $user_details = User::where('Mobile', $data['Mobile'])->get();
                $user_data = $user_details->first();
                unset($user_data->Password);
                unset($user_data->ResetKey);
                //create auth token
                $response = [
                    'Success' => true,
                    'ResponseMessage' => "Success",
                    'ResponseCode' => "200",
                    'UserId' => $UserId,
                    'AuthToken' => $AuthToken,

                    'User' => $user_data,
                    'ApiUrl' => env('APP_URL'),
                    'ApiVersion' => env('APP_VERSION'),
                    'queryPG'=>$queryPG,
                ];
                return response()->json($response);
            }
            else
            {
                // fail
                $response = [
                    'Success' => false,
                    'ResponseMessage' => "Invalid data",
                    'ResponseCode' => "202",
                    'ApiVersion' => env('APP_VERSION'),
                ];
                return response()->json($response);
            }
        }
        else
        {
            // fail
            $response = [
                'Success' => false,
                'ResponseMessage' => "User not exist",
                'ResponseCode' => "201",
                'ApiVersion' => env('APP_VERSION'),
            ];
            return response()->json($response);

        }
    }


//User get UserList
public function getUserList(Request $request) {
    //TODO What is device_token
    $data = $request->json()->all();
    $tblData = array();


    //check auth token
    if($this->userLib->tokenChecker($request) == FALSE)
    {
        $response = [
            'success' => false,
            'error_message' => "Authentication Failed",
            'error_code' => "301",
            'ApiVersion' => env('APP_VERSION'),
        ];
        return response()->json($response);
    }

    //Check Memeber is exist or not
    $users = User::select('UserId', 'FirstName', 'LastName', 'Email','Mobile')->get();
    if ($users->count() > 0)
    {   //email is exist
        $UserId = $request->header('UserId');
        $AuthToken = $request->header('AuthToken');
        $response = [
            'Success' => true,
            'ResponseMessage' => "Success",
            'ResponseCode' => "200",
            'UserId' => $UserId,
            'AuthToken' => $AuthToken,
            'Users' => $users,
            'ApiUrl' => env('APP_URL'),
            'ApiVersion' => env('APP_VERSION'),
        ];
        return response()->json($response);
    }
    else
    {
        // fail
        $response = [
            'Success' => false,
            'ResponseMessage' => "User does not exist",
            'ResponseCode' => "201",
            'ApiVersion' => env('APP_VERSION'),
        ];
        return response()->json($response);

    }
}


    //User get profile
    public function getUserProfile(Request $request, $UserId) {
		//TODO What is device_token
        $data = $request->json()->all();
        $tblData = array();


        //check auth token
        if($this->userLib->tokenChecker($request) == FALSE)
        {
            $response = [
                'success' => false,
                'error_message' => "Authentication Failed",
                'error_code' => "301",
                'ApiVersion' => env('APP_VERSION'),
            ];
            return response()->json($response);
        }


        //check validation
        if (!$UserId)
        {
            $response = [
                'Success' => false,
                'ResponseMessage' => "User is required!",
                'ResponseCode' => '220',
                'ApiVersion' => env('APP_VERSION'),
            ];
            return response()->json($response);
        }

        //Check Memeber is exist or not
        $user = User::where('UserId', $UserId)->get();
        if ($user->count() > 0)
        {   //email is exist
            $user = $user->first();
            $ProfileId = $user->ProfileId;
            $ManagerId = $user->ManagerId;
            $user_profiles = DB::connection('DBD')->table('tbl_user_profiles')->where('ProfileId', $ProfileId)->get();
            if ($user_profiles->count() > 0)
            {   //user is exist
                $profiledata = $user_profiles->first();
                $ProfileName = $profiledata->ProfileName;
                $user->ProfileName = $ProfileName;
            }

            $user_permission = DB::connection('DBD')->table('tbl_user_permissions')->where('ProfileId', $ProfileId)->get();
            if ($user_permission->count() > 0)
            {   //user is exist
                $permissiondata = $user_permission->first();
                $user->user_permission = $permissiondata;
            }

            //User profile details
            $ManagerName = '';
            $userManager = User::where('UserId', $ManagerId)->get();
            if ($userManager->count() > 0)
            {   //user is exist
                $userManagerData = $userManager->first();
                $ManagerName = $userManagerData->FirstName.' '.$userManagerData->LastName;
            }
            $user->ManagerName = $ManagerName;



            $ManagerName = '';
            $UserProfileData = array();
            $UserProfiles = UserProfile::select('ModuleId','ModuleName', 'W', 'R', 'U','D','Mobile','Created_at','Updated_at')->where('ProfileId', $ProfileId)->OrderBy('ModuleName','Asc')->get();
            if ($UserProfiles->count() > 0)
            {   //user is exist
                $UserProfileData = $UserProfiles;

            }
            $user->UserProfileAccess = $UserProfileData;


            unset($user->Password);
            unset($user->ResetKey);
            unset($user->TempPassword);
            unset($user->OtpPassword);

            $UserId = $request->header('UserId');
            $AuthToken = $request->header('AuthToken');
            $response = [
                'Success' => true,
                'ResponseMessage' => "Success",
                'ResponseCode' => "200",
                'UserId' => $UserId,
                'AuthToken' => $AuthToken,
                'User' => $user,
                'ApiUrl' => env('APP_URL'),
                'ApiVersion' => env('APP_VERSION'),
            ];
            return response()->json($response);
        }
        else
        {
            // fail
            $response = [
                'Success' => false,
                'ResponseMessage' => "User not exist",
                'ResponseCode' => "201",
                'ApiVersion' => env('APP_VERSION'),
            ];
            return response()->json($response);

        }
    }





    //User edit profile
    public function editUserProfileImage(Request $request) {
		//TODO What is device_token
       // $data = $request->json()->all();


        $CreatedDate = date('Y-m-d H:i:s',time());
        $UserId = $request->input('UserId');
        $AuthToken = $request->header('AuthToken');

        //check auth token
        if($this->userLib->tokenChecker($request) == FALSE)
        {
            $response = [
                'success' => false,
                'error_message' => "Authentication Failed",
                'error_code' => "301",
                'ApiVersion' => env('APP_VERSION'),
            ];
            return response()->json($response);
        }

        $user = User::where('UserId', $UserId)->get();
        if ($user->count() == 0)
        {
            $response = [
                'success' => false,
                'UserId' => $UserId,
                'error_message' => "User does not exist.",
                'error_code' => "201",
                'ApiVersion' => env('APP_VERSION'),
            ];
            return response()->json($response);
        }

        // $imageName = $this->userLib->useridGenrator();
        // if ($request->hasFile('UserProfileImage'))
        // {
        //     $path = '';
        //     $file = $request->file('UserProfileImage');
        //     $extension = $file->getClientOriginalExtension();
        //     $newFileName = $imageName . '-' . time() . '.' . $extension;

        //     Storage::putFileAs(
        //         'public/user',
        //         $file,
        //         $newFileName
        //     );
        //     $destinationPath = 'user';
        //     $isUploaded = $file->move($destinationPath,$newFileName);

        //     if($isUploaded)
        //     {
        //         $path = 'user/' . $newFileName;
        //         $ThumbnailUrl = $path;
        //     }
        $imageName = $this->userLib->useridGenrator();
        if ($request->hasFile('UserProfileImage'))
        {
            $path = '';
            $file = $request->file('UserProfileImage');
            $extension = $file->getClientOriginalExtension();
            $newFileName = $imageName . '-' . time() . '.' . $extension;

            Storage::putFileAs(
                'public/user/',
                $file,
                $newFileName
            );
            $destinationPath = 'user/';
            $isUploaded = $file->move($destinationPath,$newFileName);

            $uploadedFileURL = '';
            if($isUploaded)
            {
                $path = 'user/' . $newFileName;
                $ThumbnailUrl = $path;
            //File Upload Service as s3
            $sourceFileURL = env('APP_URL').'/'.$path;
            $curl = curl_init();
            curl_setopt_array($curl, array(
            CURLOPT_URL => 'http://172.105.42.62/s3-file-server/api-upload.php',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS => array('file_url' => $sourceFileURL),
            CURLOPT_HTTPHEADER => array(
                'Cookie: private_content_version=3f7abce738dd8b52d0dcb8653bfe8e93; mage-messages=%5B%7B%22type%22%3A%22error%22%2C%22text%22%3A%22Invalid%20Form%20Key.%20Please%20refresh%20the%20page.%22%7D%2C%7B%22type%22%3A%22error%22%2C%22text%22%3A%22Invalid%20Form%20Key.%20Please%20refresh%20the%20page.%22%7D%2C%7B%22type%22%3A%22error%22%2C%22text%22%3A%22Invalid%20Form%20Key.%20Please%20refresh%20the%20page.%22%7D%5D'
            ),
            ));
            $response = curl_exec($curl);
            curl_close($curl);
            $uploadedFile = json_decode($response,true);
            $uploadedFileURL = isset($uploadedFile['url']) ? $uploadedFile['url'] : '';
            }
            $data['UserProfileImage'] = $uploadedFileURL;
            $data['Updated_by'] = session('UserId');;
            $data['Updated_at'] = $CreatedDate;

            $User_update = User::where('UserId',$UserId)->update($data);

            if($User_update)
            {
                $User_details = User::where('UserId', $UserId)->get();
                $User_data = $User_details->first();

                unset($User_data->Password);
                $response = [
                    'success' => true,
                    'error_message' => "Success",
                    'error_code' => "200",
                    'ApiVersion' => env('APP_VERSION'),
                    'ApiUrl' => env('APP_URL'),
                    'User'=>$User_data,

                ];
                return response()->json($response);
            }
            else
            {
                $response = [
                    'Success' => false,
                    'ResponseMessage' => "Invalid data",
                    'ResponseCode' => "202",
                    'ApiVersion' => env('APP_VERSION'),
                ];
                return response()->json($response);
            }
        }
    }
    //end of edit profile


}