public function passwordReset() { //TODO make new push token $token = Input::get('token'); $udid = Input::get('udid'); if (!$udid) { return $this->respondInsufficientPrivileges('user.no-device'); } $smsEntry = SMS::where('token', $token)->orderBy('id')->first(); if (!Input::has('password')) { return $this->respondInsufficientPrivileges('user.wrong-password'); } $validator = Validator::make(Input::only('password'), ['password' => 'required|between:6,12']); if ($validator->fails()) { return $this->respondInsufficientPrivileges($validator->messages()->all()); } if (!$smsEntry) { return $this->respondInsufficientPrivileges('user.invalid-token'); } if (!$smsEntry->verified) { return $this->respondInsufficientPrivileges('user.phone-not-verified'); } $phone = Phone::where('number', $smsEntry->phone)->first(); $user = $phone->user; $user->password = Input::get('password'); if ($user->save()) { //TODO create new auth token $user->devices->each(function (Device $device) { $device->pushTokens()->delete(); }); $user->devices()->delete(); $smsEntry->delete(); $device = Device::create(['udid' => $udid, 'auth_token' => base64_encode(openssl_random_pseudo_bytes(32)), 'phone' => 0]); $user->devices()->save($device); $response['user'] = $this->collectionTransformer->transformUserToSmall($user); $response['auth_token'] = $device->auth_token; return $this->respond($response); } return $this->respondServerError(); }
public function addNewLead($domain, $linkedin_contact_id) { $domain = DomainHelper::getDomain($domain); $company_domain = CompanyDomain::where("linkedin_contact_id", "=", $linkedin_contact_id)->get(); for ($i = 0; $i < count($company_domain); $i++) { $company_domain[$i]->status = CompanyDomain::UNSELECTED; $company_domain[$i]->save(); } $company_domain = CompanyDomain::where("linkedin_contact_id", "=", $linkedin_contact_id)->where("url", "=", $domain)->first(); if (count($company_domain) == 0) { $linkedin_contact = LinkedinContact::find($linkedin_contact_id); $company_domain = new CompanyDomain(); $company_domain->url = $domain; $company_domain->linkedin_url = ""; $company_domain->status = CompanyDomain::SELECTED; $company_domain = $linkedin_contact->companyDomain()->save($company_domain); $company_domain->save(); if ($linkedin_contact->started_at == '' || $linkedin_contact->started_at == '0000-00-00 00:00:00') { $linkedin_contact->started_at = date("Y-m-d H:i:s"); $linkedin_contact->save(); } } else { $company_domain = CompanyDomain::find($company_domain->id); $company_domain->status = CompanyDomain::SELECTED; $company_domain->save(); } //SEO Scrapping Start $company_seo_data = $this->scrapeCompanySEO($domain); $company_domain->seo_company_title = $company_seo_data['seo_company_title']; $company_domain->seo_company_descriptoin = $company_seo_data['seo_company_descriptoin']; $company_domain->seo_company_keywords = $company_seo_data['seo_company_keywords']; //SEO Scrapping End //Company Social URL --Start $company_social_url = $this->companySocialURL($domain); $company_domain->company_facebook_url = $company_social_url['company_facebook_url']; $company_domain->company_twitter_url = $company_social_url['company_twitter_url']; $company_domain->company_google_url = $company_social_url['company_google_url']; $company_domain->fullcontact_company = $company_social_url['full_contact_company']; //Company Social URL --End // Company Visistat --Start $params = array('website' => $domain); //Query by Domain $objVisistat = new Visistat(); $response_Visistat = $objVisistat->makeCall($params); $company_domain->visistat = $response_Visistat; // Company Visistat URL --End $company_domain->save(); $linkedin_contact = LinkedinContact::find($linkedin_contact_id); $domain_list = $linkedin_contact->companyDomain()->get(); $domain = array(); $email_list = array(); $valid_email_array_list = array(); $api_email_array_list = array(); $emails = array(); $key = "id-"; foreach ($domain_list as $domain_item) { $domain_id = $domain_item->id; $domain["id-" . $domain_item->id] = $domain_item->url; if ($domain_item->status == CompanyDomain::SELECTED) { $key = "id-" . $domain_item->id; $email_list = $this->emailGenerator($linkedin_contact->firstname, $linkedin_contact->lastname, $domain_item->url); $final_domain = $domain_item->url; $test_domain = explode("www.", $domain_item->url); if (count($test_domain) == 2) { $final_domain = $test_domain[1]; } $check_email = strtolower($linkedin_contact->firstname . "_" . $linkedin_contact->lastname . '@' . $final_domain); //echo $check_email; exit; //save paid email for a specific contact according to history patterns of that domain $paid_db_email_patterns_list = PaidDatabaseEmail::select('url', 'pattern_id', 'level', 'percentage', 'paid_db')->distinct()->where("url", "=", $domain_item->url)->get(); if (count($paid_db_email_patterns_list) > 0) { foreach ($paid_db_email_patterns_list as $patterns) { $paid_email = ""; switch ($patterns['pattern_id']) { case 1: $patt = $linkedin_contact->firstname; //first $paid_email = strtolower($patt . '@' . $final_domain); break; case 2: $patt = $linkedin_contact->firstname . "." . $linkedin_contact->lastname; //first.last $paid_email = strtolower($patt . '@' . $final_domain); break; case 3: $patt = substr($linkedin_contact->firstname, 0, 1) . '' . $linkedin_contact->lastname; //flast $paid_email = strtolower($patt . '@' . $final_domain); break; case 4: $patt = $linkedin_contact->lastname; //last $paid_email = strtolower($patt . '@' . $final_domain); break; case 5: $patt = $linkedin_contact->firstname . "_" . $linkedin_contact->lastname; //first_last $paid_email = strtolower($patt . '@' . $final_domain); break; case 6: $patt = $linkedin_contact->firstname . substr($linkedin_contact->lastname, 0, 1); //firstl $paid_email = strtolower($patt . '@' . $final_domain); break; case 7: $patt = $linkedin_contact->firstname . $linkedin_contact->lastname; //firstlast $paid_email = strtolower($patt . '@' . $final_domain); break; case 8: $patt = $linkedin_contact->lastname . substr($linkedin_contact->firstname, 0, 1); //lastf $paid_email = strtolower($patt . '@' . $final_domain); break; case 9: $patt = substr($linkedin_contact->lastname, 0, 1) . $linkedin_contact->firstname; //lfirst $paid_email = strtolower($patt . '@' . $final_domain); break; case 10: $patt = substr($linkedin_contact->firstname, 0, 1) . '.' . $linkedin_contact->lastname; //f.last $paid_email = strtolower($patt . '@' . $final_domain); break; case 11: $patt = $linkedin_contact->lastname . '.' . substr($linkedin_contact->firstname, 0, 1); //last.f $paid_email = strtolower($patt . '@' . $final_domain); break; case 12: $patt = substr($linkedin_contact->firstname, 0, 1) . $linkedin_contact->lastname . substr(0, 1); //fl $paid_email = strtolower($patt . '@' . $final_domain); break; case 13: $patt = substr($linkedin_contact->firstname, 0, 1) . $linkedin_contact->lastname . "8"; //flast8 $paid_email = strtolower($patt . '@' . $final_domain); break; case 14: $patt = $linkedin_contact->firstname . "-" . $linkedin_contact->lastname; //first-last $paid_email = strtolower($patt . '@' . $final_domain); break; case 15: $patt = $linkedin_contact->firstname . "." . substr($linkedin_contact->lastname, 0, 1); //first.l $paid_email = strtolower($patt . '@' . $final_domain); break; case 16: $patt = $linkedin_contact->lastname . "." . $linkedin_contact->firstname; //last.first $paid_email = strtolower($patt . '@' . $final_domain); break; default: //echo "default"; } if ($paid_email != "") { $_email_exist = PaidDatabaseEmail::where("email", "=", $paid_email)->get(); if (count($_email_exist) > 0) { //$_JSON["result"] = "This mail is already taken"; } else { try { $email_obj = new PaidDatabaseEmail(); $email_obj->url = $patterns['url']; $email_obj->email = $paid_email; $email_obj->paid_db = $patterns['paid_db']; $email_obj->pattern_id = $patterns['pattern_id']; $email_obj->level = $patterns['level']; $email_obj->percentage = $patterns['percentage']; $email_obj->linkedin_contact_id = $linkedin_contact->id; $email_obj->save(); } catch (Exception $e) { Log::notice($e); } } } } } //saving paid db1 and paid db2 for final phone $paid_phone_list = PaidDatabasePhone::select('url', 'phone', 'level', 'percentage', 'paid_db')->distinct()->where("url", "=", $domain_item->url)->get(); if (count($paid_phone_list) > 0) { foreach ($paid_phone_list as $phone_item) { $paid_phone = $phone_item['phone']; if ($paid_phone != "") { $_phone_exist = Phone::where("phone", "=", $paid_phone)->where("linkedin_contact_id", "=", $linkedin_contact->id)->get(); if (count($_phone_exist) > 0) { //$_JSON["result"] = "This phone is already taken"; } else { try { $ph_obj = new Phone(); $ph_obj->phone = $paid_phone; $ph_obj->level = $phone_item['level']; $ph_obj->percentage = $phone_item['percentage']; $ph_obj->linkedin_contact_id = $linkedin_contact->id; $ph_obj->save(); //$insertedId = $ph_obj->id; } catch (Exception $e) { Log::notice($e); } } } } } // first name or last name has been changed $check_email_validator = EmailDomainValidator::where("domain_id", "=", $domain_id)->where('email_pattern', '=', $check_email)->orderBy('status', 'desc')->get()->toArray(); $email_validator = EmailDomainValidator::where("domain_id", "=", $domain_id)->orderBy('status', 'desc')->get()->toArray(); if (!count($email_validator) || !count($check_email_validator)) { $emails = $email_list; array_shift($emails); set_time_limit(0); foreach ($emails as $email) { $api_key = '9bbfe3db-eeb8-413b-810c-f4aa02d62448'; $client = new BriteAPIContact($api_key); $client->email = $email; $client->verify(); $response = $client->response['email']; $status = $response['status']; $full_status = 0; $likelihood = 0; //Added by developer $validator = new EmailDomainValidator(); $validator->domain_id = $domain_id; $validator->email_pattern = $email; $validator->status = $response['status']; $validator->disposable = $response['disposable']; $validator->role_address = $response['role_address']; $validator->duration = $response['duration']; $validator->result = json_encode($response); $validator->save(); $validator_id = $validator->id; if ($response['status'] == 'invalid') { // We are doing nothing with it. Domain might be Invalid $response_json = ""; $errors = $client->errors(); $errors_codes = $client->error_codes(); $error_code = $errors_codes[0]; $error = $errors['email']; } else { // If status is not Valid, We are saving the pattern along with Full Contact Person API response $valid_email_array_list[$email] = $email; $response_json = $this->createWebhook($email, $validator_id); $response_obj = json_decode($response_json); $likelihood = 0; $full_status = $response_obj->status; // for api result copy patterns if (is_object($response_obj)) { if ($response_obj->status == 202) { //$api_email_list[$email->email_pattern] = $email->email_pattern; $api_email_array_list[$email] = $email; } else { if ($response_obj->status == 200) { //$api_email_list[$email->email_pattern] = $email->email_pattern; $api_email_array_list[$email] = $email; $likelihood = $response_obj->likelihood; } } } $error_code = ""; $error = ""; } $validator->likelihood = $likelihood; $validator->error_code = $error_code; $validator->error = $error; if ($response['status'] == 'valid') { $objFullContactPerson = new FullContactPerson(); $response_json = $objFullContactPerson->makeCall($email); $validator->fullcontact = $response_json; $response_obj = json_decode($response_json); $validator->full_status = $response_obj->status; } else { $validator->full_status = $full_status; $validator->fullcontact = $response_json; } $validator->webhook = 1; $validator->save(); // save record for accept all tracking // This needs to be placed under BriteVerify Status Level based on its most VALID recommendation. $accept_all_domain = CompanyDomain::find($domain_id); $accept_all_domain->brite_api_status = $response['status']; $accept_all_domain->save(); //auto save email for contact if it is valid by Brite api /* if ($response['status'] == 'valid') { if (Email::where('email', '=', $email)->exists()) { // email found } else { $email_object = new Email(); $email_object->linkedin_contact_id = $linkedin_contact->id; $email_object->email = $email; $email_object->level = 'Verified'; $email_object->percentage = '10'; $email_object->save(); } } */ } } // CONDITIONAL LOGIC FOR BRITEVERIFY STATUSES STARTS HERE // Initial Check - If any of the Email Pattern(s) is VALID $email_validator = EmailDomainValidator::where("domain_id", "=", $domain_id)->where('status', '=', "valid")->orderBy('status', 'desc')->get()->toArray(); if (!empty($email_validator)) { //echo " == Found Valid email ==" ; //print_r ($email_validator); $responseSocialURL = $this->socialURL($domain_id, 'valid'); $is_valid_lead = $responseSocialURL['is_valid']; if ($is_valid_lead == 1) { //echo " == Have found correct Social Data FullContact =="; } //else //echo " == Not found correct Social Data in FullContact =="; //exit ; // Fetch FULL Contact Social information through Email validator table against found VALID records. And show the results in Email POP UP } elseif (empty($email_validator)) { // Check if all email patterns are INVALID $email_validator = EmailDomainValidator::where("domain_id", "=", $domain_id)->where('status', '=', "invalid")->orderBy('status', 'desc')->get()->toArray(); if (!empty($email_validator) && count($email_validator) == 10) { //echo "== All Email Patterns are INVALID =="; //print_r ($email_validator); //exit; // Domain might not correct or email patterns don't exist } else { // All are not Invalid, Check if we have got unknown or accept_all $email_validator = EmailDomainValidator::whereIn('status', array('unknown', 'accept_all'))->where("domain_id", "=", $domain_id)->orderBy('status', 'desc')->get()->toArray(); if (!empty($email_validator)) { // echo "== Found unknown and/or accept_all email ==" ; // print_r ($email_validator); // Validating Social Data $responseSocialURL = $this->socialURL($domain_id, 'accept_all'); $is_valid_lead = $responseSocialURL['is_valid']; if ($is_valid_lead == 1) { //echo " == Have found correct Social Data in FullContact =="; // WE NEED TO UPDATE THE EMAIL PATTERN STATUS to VALID } elseif ($is_valid_lead == 0) { // echo " == Not found any Social Data in FullContact =="; // If Social Links are invalid then we would go further to following APis //$objNetProspexPerson = new NetProspexPerson(); //$objZoomInfoPersonDetail = new ZoomInfoPersonDetail(); /* // ZoominfoPersonMatch API $objZoomInfoPersonMatch = new ZoomInfoPersonMatch(); $response_ZoomInfoPersonMatch = $objZoomInfoPersonMatch->makeCall(array('firstName' => $linkedin_contact->firstname, 'lastName' => $linkedin_contact->lastname, 'companyName' => $final_domain)); $company_domain = CompanyDomain::find($domain_id); $company_domain->zoominfo_search = $response_ZoomInfoPersonMatch; $company_domain->save(); */ /* foreach ($email_validator as $key => $pattern) { // NetProsPexPerson API $response_NetProspexPerson = $objNetProspexPerson->makeCall(array('email' => $pattern['email_pattern'] )); // ZoominfoPersonDetail API $response_ZoomInfoPersonDetail = $objZoomInfoPersonDetail->makeCall(array('EmailAddress' => $pattern['email_pattern'] )); // Saving NetprosPex and Zoominfo API calls response in DB, email_validator table $validator = EmailDomainValidator::find($pattern['id']); $validator->netprospex_match = $response_NetProspexPerson; $validator->zoominfo_detail = $response_ZoomInfoPersonDetail; //$validator->zoominfo_detail = $response_ZoomInfoPersonMatch; // Saving Person Match Result in DB $validator->save(); } */ // echo "== NetProsPex and ZoomInfo Response has been saved in DB ==" ; // Fetch NetprosPex and Zoominfo Reponse to check if they have returned some Valid info /* $netProsPexResponse = $this->validateNetprosPex($domain_id, "accept_all") ; $is_valid_netprospex = $netProsPexResponse['is_found'] ; $zoomInfoResponse = $this->validateZoomInfo($domain_id, "accept_all") ; $is_valid_zoominfo = $zoomInfoResponse['is_found'] ; */ //if ( $is_valid_netprospex > 0 ) //{ // echo "== Found in NetprosPexPerson ==" ; // WE NEED TO UPDATE THE EMAIL PATTERN STATUS to VALID //} else { // echo "== Not found in NetprosPexPerson =="; //} // LETS CHECK OUT ZOOMINFO RESPONSE //if ( $is_valid_zoominfo > 0 ) //{ // echo "== Found in ZoominfoPerson ==" ; // WE NEED TO UPDATE THE EMAIL PATTERN STATUS to VALID //} else { // echo "== Not found in ZoominfoPerson =="; //} // NetProsPex Person Search AND ZoomInfo Person Search $is_valid_netprospex = 0; $is_valid_zoominfo = 0; if ($is_valid_netprospex == 0 && $is_valid_zoominfo == 0) { // We are unable to find success with FullcontactPerson, NetProsPexPerson and ZoominfoPerson, we need to keep looking // Before making following person search calls, we will look into company_domain_patterns table if we have already saved email patterns // for requested domain. If we already have, then we will get the patterns from DB and won't make new API calls for the same domain: $objNetProspexPersonList = new NetProspexPersonList(); $objZoomInfoPersonSearch = new ZoomInfoPersonSearch(); // NetProsPexPersonList API $response_NetProspexPersonList = $objNetProspexPersonList->makeCall(array('organizationWebsite' => $final_domain)); // ZoominfoPersonDetail API $response_ZoomInfoPersonSearch = $objZoomInfoPersonSearch->makeCall(array('companyDomainName' => $final_domain, 'companyPastOrPresent' => '1')); // Saving NetprosPex and Zoominfo API calls response in DB, company_domain table if ($response_NetProspexPersonList != "") { $company_domain = CompanyDomain::find($domain_id); $company_domain->netprospex_list = $response_NetProspexPersonList; $company_domain->save(); // Fetching email patterns / phone numbers out of Netprospex Person Search API to save these in // company_domain_patterns table for current / future use. $this->parseNetprospexList($domain_id, $final_domain); } if ($response_ZoomInfoPersonSearch != "") { $company_domain = CompanyDomain::find($domain_id); $company_domain->zoominfo_search = $response_ZoomInfoPersonSearch; $company_domain->save(); // Fetching email patterns / phone numbers out of Zoominfo Person Search API to save these in // company_domain_patterns table for current / future use. $this->parseZoomInfoList($domain_id, $final_domain); } } } } } } // PHONE Validator Code goes here.. $this->parsePhoneNumbers($domain_id); // Email pattern recognition Code // First we need to fetch the leads First Name, Last Name and Domain URL $response_lead = EmailDomainValidator::where("domain_id", "=", $domain_id)->get()->toArray(); $leadEmails = array(); foreach ($response_lead as $lead) { $leadEmails[] = $lead['email_pattern']; } // Second, we need to fetch the domain email patterns through DB $response_domain = CompanyDomainPatterns::where("company_domain_id", "=", $domain_id)->get()->toArray(); foreach ($response_domain as $lead) { $array = $this->emailGenerator($lead['first_name'], $lead['last_name'], $final_domain); $i = -1; foreach ($array as $email) { if ($email == $lead['email']) { // Update the lead email pattern status to 1 in company_status column to effect the Recommendation Formula on Email Popup $validator = EmailDomainValidator::where('email_pattern', $leadEmails[$i])->first(); $validator->company_status = $validator->company_status + 1; $validator->save(); break; } $i++; } } // Preselect top email pattern as Current $this->markTopEmailAsCurrent($domain_id, 1); // exit ; } } }
/** * Authorize new device, * request new access_token * @return Response */ public function devicesAuth() { $number = Input::get('phone'); $password = Input::get('password'); $udid = Input::get('udid'); if (!Input::has('udid')) { return $this->respondNotFound('Device id not found'); } //TODO Validation $phone = Phone::where('number', $number)->first(); if (!$phone) { return $this->respondNotFound('Phone not found'); } $user = $phone->user; if (!$user) { return $this->respondNotFound('User not found'); } if ($user->checkPasswordAttribute($password)) { $device = $user->devices()->where('udid', $udid)->first(); if ($device) { //TODO hardcoded bad return $this->respond(['user' => ['id' => $user->id, 'name' => $user->name, 'img' => ["thumb" => $user->img_small, "middle" => $user->img_middle, "origin" => $user->img_large]], 'auth_token' => $device->auth_token]); } else { $newDevice = Device::create(['udid' => $udid, 'auth_token' => base64_encode(openssl_random_pseudo_bytes(32))]); $user->devices()->save($newDevice); return $this->respond(['user' => ['id' => $user->id, 'name' => $user->name, 'img' => ["thumb" => $user->img_origin, "middle" => $user->img_middle, "origin" => $user->img_origin]], 'auth_token' => $newDevice->auth_token]); } } else { return $this->respondInsufficientPrivileges('Wrong password'); //TODO change to 401 } }
echo json_encode($data); }); // Delete contact $contactList->delete("/contacts/:id", function ($id) use($contactList) { $contact = Contact::find($id); if ($contact->delete()) { $data['msg'] = 'Contact deleted successfully!'; } else { $data['msg'] = 'An error occurred while deleting the contact!'; } $contactList->response()->header('Content-Type', 'application/json'); echo json_encode($data); }); // Get all phones to one contact $contactList->get("/contact/:id/phone", function ($id) use($contactList) { $phones = Phone::where('contactId', '=', $id)->get(); $contactList->response()->header('Content-Type', 'application/json'); echo json_encode(objectToArray(json_decode($phones))); }); // Add new phone $contactList->post("/contact/:id/phone", function ($id) use($contactList) { $phone = $contactList->request->params('phone'); $newPhone = new Phone(); $newPhone->contactId = $id; $newPhone->phone = $phone; if ($newPhone->save()) { $data['msg'] = 'Phone saved successfully!'; $data['id'] = $newPhone->id; } else { $data['msg'] = 'An error occurred while saving the phone!'; }
public function mostrar_telefono() { $telefono_persona = Phone::where('fk_empresa', '=', null)->orderBy('fk_persona')->paginate(10); $telefono_empresa = Phone::where('fk_persona', '=', null)->orderBy('fk_empresa')->paginate(10); return View::make('telefono.listaTelefono', array('telefono_persona' => $telefono_persona, 'telefono_empresa' => $telefono_empresa)); }