Laravel Controller Request Verify - laravel

Can someone help me verify a request via controller? I don't know how to do this.
public function verify(Request $request){
$key = clean($request->purchasecode);
$response = \Core\Http::url("https://cdn.gempixel.com/validator/";)
->with('X-Authorization', 'TOKEN '.md5(url()))
->body(['url' => url(), 'key' => $key])
->post()
->getBody();
if(!$response || empty($response) || $response == "Failed"){
return back()->with("danger", "This purchase code is not valid. It is either for another item or has been disabled.");
}elseif($response == "TooMany"){
return back()->with("danger", "This purchase code is already used on another domain. If you need to reset it, please us your purchase code and domain to reset it.");
}elseif($response == "Wrong.Item"){
return back()->with("danger", "This purchase code is for another item. Please use a Premium URL Shortener extended license purchase code.");
}elseif($response == "Wrong.License"){
return back()->with("danger", "This purchase code is for a standard license. Please use a Premium URL Shortener extended license purchase code.");
} else {
$setting = DB::settings()->where('config', 'purchasecode')->first();
$setting->var = $key;
$setting->save();
$this->seelfdb($response);
}
}
/**
* Seelfdb:code
*
* #author GemPixel <https://gempixel.com>
* #version 6.0
* #return void
*/
private function seelfdb($r){
$q = str_replace("_PRE_", DBprefix, $r);
$qs = explode("|", $q);
foreach ($qs as $query) {
if(!DB::raw_execute($query)){
return Gem::trigger(500, 'Task failed.');
}
}
return back()->with('success', base64_decode('RXh0ZW5kZWQgdmVyc2lvbiBoYXMgYmVlbiBzdWNjZXNzZnVsbHkgdW5sb2NrZWQuIFlvdSBtYXkgbm93IHVzZSBwYXltZW50IG1vZHVsZXMgYW5kIHN1YnNjcmlwdGlvbnMu'));
}
}
It's a laravel based website. I need to enable payment methods, the only method to do this is by verifying the purchase code. You can see the validator URL in the code. But I want to Bypass or something like this to verify any purchase code to trigger
$setting = DB::settings()->where('config', 'purchasecode')->first();
$setting->var = $key;
$setting->save();
$this->seelfdb($response);
And then I couldn't understand what is this code
private function seelfdb($r){
$q = str_replace("_PRE_", DBprefix, $r);
$qs = explode("|", $q);
foreach ($qs as $query) {
if(!DB::raw_execute($query)){
return Gem::trigger(500, 'Task failed.');
}
}
return back()->with('success', base64_decode('RXh0ZW5kZWQgdmVyc2lvbiBoYXMgYmVlbiBzdWNjZXNzZnVsbHkgdW5sb2NrZWQuIFlvdSBtYXkgbm93IHVzZSBwYXltZW50IG1vZHVsZXMgYW5kIHN1YnNjcmlwdGlvbnMu'));
}

Related

Send Mail laravel to multiple recipients by using foreach

Good evening everyone,
I have some issues in my project. I'm trying to send mail to each collaborator who celebrates his birthday. The data are taken from my database. The problem is that: if I have for example 2 or 3 collaborators who celebrate their birthday in the same day, only the first in the list receive a mail. My question how send to all concerned collaborator a mail.
My code:
public function handle()
{
$collaborateurs = Card::listCard();
foreach ($collaborateurs as $collaborateur) {
return Mail::to($collaborateur->adresse_email)->send(new SendEmail($collaborateur));
}
}
class CarteAnnif {
public static function listCard(){
$collaborateurs = Organigramme::whereMonth('date_de_naissance', now()->month)
->whereDay('date_de_naissance', now()->day)
->get();
$collaborateursConcernes = [];
foreach ($collaborateurs as $collaborateur) {
$date_de_naissance = Carbon::createFromFormat('d/m/Y', $collaborateur->date_de_naissance)->format('d-m');
$date_de_naissance = strtotime($date_de_naissance);
$today = date('d-m');
$today = strtotime($today);
if($date_de_naissance == $today ){
$collaborateursConcernes[] = $collaborateur;
}
}
return collect($collaborateursConcernes);
}
}
public $collaborateur;
public function __construct($collaborateur)
{
$this->collaborateur = $collaborateur;
}
/**
* Build the message.
*
* #return $this
*/
public function build()
{
$this->view('admin.emails.send_card_to_collaborateurs')
->subject("Joyeux anniversaire");
return $this->from('app#domain.com')->view('admin.emails.send_card_to_collaborateurs');
}
}
I hope I have been clear otherwise I remain available for any other additional information
Thanks in advance!
The return ends a function, so your function will stop after the first loop. Just delete the retun :
foreach ($collaborateurs as $collaborateur) {
Mail::to($collaborateur->adresse_email)->send(new SendEmail($collaborateur));
}

how to build a Laravel command that loops through users is sends unique emails to each user

I have a command that I'll run nightly using the Forge scheduler. The command simply loops through and sends emails to each user who qualifies for one.
COMMAND:
public function handle()
{
//Get all users
$users = User::all();
$data = [];
$renewalEmail = '';
foreach($users as $user)
{
//Check each users next_biling_date and see if is less than 72 hours from now, if so send reminder email
$nextBillingDate = ($user->hasSubscription())? $user->getSubscriptionData()->current_period_end : false;
$now = strtotime(now());
$threeDaysFromNow = 60*60*24*3;
//($user->hasSubscription())? $this->updateNextBillingDate($user) : false;//TODO: remove after working: follow up
if($user->hasSubscription() && $nextBillingDate-$now<=$threeDaysFromNow)
{
$data = [
'name' => $user->name,
'billingdate' => date('n/j/Y',strtotime($user->next_billing_date)),
];
// Log::info(print_r($data,true));
$renewalEmail = Mail::to('my#email.com')->send(new SubscriptionRenewalReminder($data));
// Log::info(print_r($renewalEmail,true));
}
}
return true;
}
My Mailable is pretty straight forward:
public function __construct($data)
{
$this->data = $data;
}
/**
* Build the message.
*
* #return $this
*/
public function build()
{
Log::info('SubscriptionRenewalReminder Email build() called: ');
$firstName = explode(' ',$this->data['name'])[0];
$billingDate = $this->data['billingdate'];
Log::info('firstname: '.$firstName);
Log::info('billingDate: '.$billingDate);
return $this->view('emails.subscription-renewal-reminder')
->from('my#email.com', 'Project')
->subject('Project Subscription Is About To Renew')
->withName($firstName)
->withBillingdate($billingDate);
}
All of my Log::info's dump out the right information. I have 3 test users who all qualify to get the email.
In my testing, all three emails show the first user's name and billing date. Instead of unique emails, they are all identical.
I may move this into a queue but on a small set of users this should work fine. TIA

Check mail is sent successfully or not on Laravel 5

I have a function that can send mail on Laravel5 using this
/**
* Send Mail from Parts Specification Form
*/
public function sendMail(Request $request) {
$data = $request->all();
$messageBody = $this->getMessageBody($data);
Mail::raw($messageBody, function ($message) {
$message->from('yourEmail#domain.com', 'Learning Laravel');
$message->to('goper.zosa#gmail.com');
$message->subject('Learning Laravel test email');
});
return redirect()->back();
}
/**
* Return message body from Parts Specification Form
* #param object $data
* #return string
*/
private function getMessageBody($data) {
$messageBody = 'dummy dummy dummy dummy';
}
and is sent successfully. But how to check if it was sent or not? Like
if (Mail::sent == 'error') {
echo 'Mail not sent';
} else {
echo 'Mail sent successfully.';
}
I'm just guessing that code.
I'm not entirely sure this would work but you can give it a shot
/**
* Send Mail from Parts Specification Form
*/
public function sendMail(Request $request) {
$data = $request->all();
$messageBody = $this->getMessageBody($data);
Mail::raw($messageBody, function ($message) {
$message->from('yourEmail#domain.com', 'Learning Laravel');
$message->to('goper.zosa#gmail.com');
$message->subject('Learning Laravel test email');
});
// check for failures
if (Mail::failures()) {
// return response showing failed emails
}
// otherwise everything is okay ...
return redirect()->back();
}
Hope this helps
The Mail::failures() will return an array of failed emails.
Mail::send(...)
if( count(Mail::failures()) > 0 ) {
echo "There was one or more failures. They were: <br />";
foreach(Mail::failures() as $email_address) {
echo " - $email_address <br />";
}
} else {
echo "No errors, all sent successfully!";
}
source : http://laravel.io/forum/08-08-2014-how-to-know-if-e-mail-was-sent
For Laravel 9.11.0
Mail::failures() // is deprecated in laravel 9.11.0
To check if your email was sent successfully one could wrap mail send in a try catch block:
try {
Mail::to($userEmail)->send($welcomeMailable);
} catch (Exception $e) {
//Email sent failed.
}
or since Mail::to($email)->send($mailable) on success returns an instance of : SentMessage one could check:
$welcomeEmailSent = Mail::to($userEmail)->send($welcomeMailable);
if ($welcomeEmailSent instanceof \Illuminate\Mail\SentMessage) {
//email sent success
} else {
//email sent failed
}
You may additionally can make use "Swift_TransportException" to identify any errors.
try{
//code to send the mail
}catch(\Swift_TransportException $transportExp){
//$transportExp->getMessage();
}
You can use the Mail::failures() function for that.
It will have a collection of failed mails if it exists so you can use the code below to check for it.
public function sendMail(Request $request) {
$data = $request->all();
$messageBody = $this->getMessageBody($data);
Mail::raw($messageBody, function ($message) use ($messageBody) {
$message->from('yourEmail#domain.com', 'Learning Laravel');
$message->to('goper.zosa#gmail.com');
$message->subject($messageBody);
});
// check for failed ones
if (Mail::failures()) {
// return failed mails
return new Error(Mail::failures());
}
// else do redirect back to normal
return redirect()->back();
}

how to get facebook email id from Nodge/yii2-eauth

Am trying to integrate Yii2 EAuth for facebook login integration.
I made configaration * in model am using below code
public static function findIdentity($id) {
if (Yii::$app->getSession()->has('user-'.$id)) {
return new self(Yii::$app->getSession()->get('user-'.$id));
}
else {
return isset(self::$users[$id]) ? new self(self::$users[$id]) : null;
}
}
/**
* #param \nodge\eauth\ServiceBase $service
* #return User
* #throws ErrorException
*/
public function findByEAuth($service) {
if (!$service->getIsAuthenticated()) {
throw new ErrorException('EAuth user should be authenticated before creating identity.');
}
$id = $service->getServiceName().'-'.$service->getId();
// echo $id;exit;
print_r($service->getAttribute('email'));
echo '<pre>';
print_r($service->getAttributes());
exit;
$attributes = array(
'id' => $id,
'username' => $service->getAttribute('name'),
'authKey' => md5(#$id),
'profile' => $service->getAttributes(),
);
$attributes['profile']['service'] = $service->getServiceName();
Yii::$app->getSession()->set('user-'.$id, $attributes);
return new self($attributes);
}
i want email , pls can any one help me to get facebook email id...thanks in advance......
I managed to get the email of the user from facebook after changing the few setting in vendor\nodge\yii2-eauth\src\services\FacebookOAuth2Service.php.
Edit FacebookOAuth2Service.php
Override protected $scopes = array(self::SCOPE_EMAIL);
And modify the fetchAttributes() functions. It should look like this:
protected function fetchAttributes()
{
$info = $this->makeSignedRequest('me');
$this->attributes['id'] = $info['id'];
$this->attributes['name'] = $info['name'];
$this->attributes['url'] = $info['link'];
$this->attributes['email'] = $info['email'];
return true;
}
Try and see it it works for you.

Mage_Core_Exception with message 'Cannot retrieve entity config: sales/Array'

The following code runs fine under Magento 1.6 but raises a Mage_Core_Exception (message: 'Cannot retrieve entity config: sales/Array') when run under 1.5.0.1. What do I need to do to get this code running under Magento 1.5.0.1?
$results = Mage::getResourceModel('sales/order_collection');
$results->join(
array('status_key_table' => 'order_status'),
'main_table.status = status_key_table.status',
array('status_key_table.label')
);
Thank you,
Ben
If you compare the join() methods between 1.5.0.1 and 1.6.2.0:
1.5.0.1: Mage_Core_Model_Mysql4_Collection_Abstract::join()
public function join($table, $cond, $cols='*')
{
if (!isset($this->_joinedTables[$table])) {
$this->getSelect()->join(array($table=>$this->getTable($table)), $cond, $cols);
$this->_joinedTables[$table] = true;
}
return $this;
}
1.6.2.0: Mage_Core_Model_Resource_Db_Collection_Abstract::join()
public function join($table, $cond, $cols = '*')
{
if (is_array($table)) {
foreach ($table as $k => $v) {
$alias = $k;
$table = $v;
break;
...
You can see that 1.5.0.1 doesn't support aliases. Instead, it calls $this->getTable() on the first parameter you pass in -- which should be a string. So, in your case, you'll need to pass in 'sales/order_status' as the first parameter.

Resources