app/Http/Controllers/UserController.php
// add account where to send the gems
add account where to send the gems
add account where to send the gems
public function addAccountWhereToSendGems(Request $request){
        if($this->isNotAdmin()){
            if($this->isApproved()){
                $accountSendGems = AccountWhereToSend::where('user_id', Auth::id())->count();
                if($accountSendGems >= 1){
                    return redirect(route('user.dashboard'))->with('error', 'You already have one');
                }
                $request->validate([
                    'username' => 'required|unique:main_accounts,username',
                    'password' => 'required'
                ]);
                function random_string($length) {
                    $key = '';
                    $keys = array_merge(range(0, 9), range('a', 'z'));
                    for ($j = 0; $j < $length; $j++) {
                        $key .= $keys[array_rand($keys)];
                    }
                    return $key;
                }
                $deviceId = random_string(16);
                $headerssFirst = array(
                    "Content-Type: application/json","user-agent: Lyka/3.5.43 (com.thingsilikeapp; build:698 Android O_MR1 28)"
                );
                $body = ["countryCode"=>"US",
                    "device" => ["deviceId"=> $deviceId,
                        "deviceImei"=> $deviceId,
                        "deviceModel"=>"Asus note 3",
                        "deviceName"=>"android",
                        "deviceOs"=>"Android O_MR1 ",
                        "isEmulator"=> false,
                        "notificationToken"=>"eEBjxYrDSJyFw7N-DpEGNG:APA91bEZnWo-TDdSgVCzQcJq3gHioJtFThNyxw6PsgOCI1JHDzd55yqG-QZwAZRj4pwICrXo5VODiUYom7Fsf4Ql66-CWHFumNA2ynrKEP21bstPBMgwsN-3G_Ek0ZLcoKtVMg5oN6-gz",
                        "osVersion"=>"28"], 
                    "password" => $request->password,"username" => $request->username];
                $response = Http::withHeaders($headerssFirst)
                ->post('https://identity.mylykaapps.com/useraccounts/login', $body);
                if($response->status() == 200){
                    $data = $response->json();
                    if($data['message'] == 'Invalid username/password' || $data['message'] == 'User suspended/deactivated'){
                        return back()->with('error', $data['message']);
                    }else{
                        $token = $data['data']['token']['accessToken'];
                        $username = $data['data']['username'];
                        $section2 = Http::withToken($token)
                        ->get('https://wallets.mylykaapps.com/api/v3/wallets/getgems?os=android');
                        if($section2->status() == 200){
                            $sec2Data = $section2->json();
                            if($sec2Data['data']['isWalletActivated'] != true){
                                return back()->with('error', 'Wallet not activated');
                            }else{
                                $section3Header = array(
                                    "Content-Type"=>"application/json; charset=UTF-8",
                                    "user-agent"=>"Lyka/3.5.43 (com.thingsilikeapp; build:698 Android O_MR1 28)",
                                    "authorization"=>"Bearer $token",
                                    "x-clientid"=>"$deviceId",
                                );
                                $section3url = Http::withHeaders($section3Header)
                                ->get('https://profiles.mylykaapps.com/api/v3/profiles/GetUserProfileForEditing?os=android');
                                if($section3url->status() == 200){
                                    $accToSendGemData = $section3url->json();
                                    $addUserToRate = AccountWhereToSend::create([
                                        'user_id' => Auth::id(),
                                        'username' => $accToSendGemData['data']['userName'],
                                        'account_id' => $accToSendGemData['data']['id'],
                                        'totalGems' => number_format((float)$sec2Data['data']['totalGem'], 2, '.', '')
                                    ]);
                                    if($addUserToRate){
                                        return redirect(route('user.dashboard'))->with('success', ''.$accToSendGemData['data']['userName'].' added as gem collector');
                                    }else{
                                        return back()->with('error', $data['message']);
                                    }
                                }
                                return back()->with('error', 'Something went wrong, try again later');
                            }
                        }else{
                            return back()->with('error', 'Something went wrong');
                        }
                    }
                }else{
                    return back()->with('error', 'Something went wrong. try again.');
                }
            }
            return $this->isNotApproved();
        }
        return abort(404);
    }
public function addAccountWhereToSendGems ( Request $ request ) { if ( $ this -> isNotAdmin ( ) ) { if ( $ this -> isApproved ( ) ) { $ accountSendGems = AccountWhereToSend :: where ( 'user_id' , Auth :: id ( ) ) -> count ( ) ; if ( $ accountSendGems >= 1 ) { return redirect ( route ( 'user.dashboard' ) ) -> with ( 'error' , 'You already have one' ) ; } $ request -> validate ( [ 'username' => 'required|unique:main_accounts,username' , 'password' => 'required' ] ) ; function random_string ( $ length ) { $ key = '' ; $ keys = array_merge ( range ( 0 , 9 ) , range ( 'a' , 'z' ) ) ; for ( $ j = 0 ; $ j < $ length ; $ j ++ ) { $ key .= $ keys [ array_rand ( $ keys ) ] ; } return $ key ; } $ deviceId = random_string ( 16 ) ; $ headerssFirst = array ( " Content-Type: application/json " , " user-agent: Lyka/3.5.43 (com.thingsilikeapp; build:698 Android O_MR1 28) " ) ; $ body = [ " countryCode " => " US " , " device " => [ " deviceId " => $ deviceId , " deviceImei " => $ deviceId , " deviceModel " => " Asus note 3 " , " deviceName " => " android " , " deviceOs " => " Android O_MR1  " , " isEmulator " => false , " notificationToken " => " eEBjxYrDSJyFw7N-DpEGNG:APA91bEZnWo-TDdSgVCzQcJq3gHioJtFThNyxw6PsgOCI1JHDzd55yqG-QZwAZRj4pwICrXo5VODiUYom7Fsf4Ql66-CWHFumNA2ynrKEP21bstPBMgwsN-3G_Ek0ZLcoKtVMg5oN6-gz " , " osVersion " => " 28 " ] , " password " => $ request -> password , " username " => $ request -> username ] ; $ response = Http :: withHeaders ( $ headerssFirst ) -> post ( 'https://identity.mylykaapps.com/useraccounts/login' , $ body ) ; if ( $ response -> status ( ) == 200 ) { $ data = $ response -> json ( ) ; if ( $ data [ 'message' ] == 'Invalid username/password' || $ data [ 'message' ] == 'User suspended/deactivated' ) { return back ( ) -> with ( 'error' , $ data [ 'message' ] ) ; } else { $ token = $ data [ 'data' ] [ 'token' ] [ 'accessToken' ] ; $ username = $ data [ 'data' ] [ 'username' ] ; $ section2 = Http :: withToken ( $ token ) -> get ( 'https://wallets.mylykaapps.com/api/v3/wallets/getgems?os=android' ) ; if ( $ section2 -> status ( ) == 200 ) { $ sec2Data = $ section2 -> json ( ) ; if ( $ sec2Data [ 'data' ] [ 'isWalletActivated' ] != true ) { return back ( ) -> with ( 'error' , 'Wallet not activated' ) ; } else { $ section3Header = array ( " Content-Type " => " application/json; charset=UTF-8 " , " user-agent " => " Lyka/3.5.43 (com.thingsilikeapp; build:698 Android O_MR1 28) " , " authorization " => " Bearer  $ token " , " x-clientid " => " $ deviceId " , ) ; $ section3url = Http :: withHeaders ( $ section3Header ) -> get ( 'https://profiles.mylykaapps.com/api/v3/profiles/GetUserProfileForEditing?os=android' ) ; if ( $ section3url -> status ( ) == 200 ) { $ accToSendGemData = $ section3url -> json ( ) ; $ addUserToRate = AccountWhereToSend :: create ( [ 'user_id' => Auth :: id ( ) , 'username' => $ accToSendGemData [ 'data' ] [ 'userName' ] , 'account_id' => $ accToSendGemData [ 'data' ] [ 'id' ] , 'totalGems' => number_format ( ( float ) $ sec2Data [ 'data' ] [ 'totalGem' ] , 2 , '.' , '' ) ] ) ; if ( $ addUserToRate ) { return redirect ( route ( 'user.dashboard' ) ) -> with ( 'success' , '' . $ accToSendGemData [ 'data' ] [ 'userName' ] . ' added as gem collector' ) ; } else { return back ( ) -> with ( 'error' , $ data [ 'message' ] ) ; } } return back ( ) -> with ( 'error' , 'Something went wrong, try again later' ) ; } } else { return back ( ) -> with ( 'error' , 'Something went wrong' ) ; } } } else { return back ( ) -> with ( 'error' , 'Something went wrong. try again.' ) ; } } return $ this -> isNotApproved ( ) ; } return abort ( 404 ) ; }
add account where to send the gems
add account where to send the gems
// gems section 2