1

I am trying to add a new user to a group and send an activation email. It was working earlier when I implemented it without queues.

Here's my (relevant) code in app/routes.php:

Queue::getIron()->ssl_verifypeer = false;

Route::post('queue/demo', function(){
    Log::info('marshal!');
    return Queue::marshal();
});

class FinishUserRegistration{
public function fire($job, $data){
    $user_id = $data['user_id'];
    $usergroup = Sentry::getGroupProvider()->findById(2);
    $newuser = Sentry::findUserById($user_id);
    $newuser->addGroup($usergroup);
    $emailData = array(
        'user_name' => $newuser->first_name . ' ' . $newuser->last_name,
        'activation_code' => $newuser->getActivationCode(),
        'user_id' => $newuser->id,
        'repeat' => false,
    );
    Mail::send('emails.activation', $emailData, function ($message) use($user_id){
        $newuser = Sentry::findUserById($user_id);
        $message->to($newuser->email, $newuser->first_name . ' ' . $newuser->last_name)->subject('Welcome to The Site!');
    });

    $job->delete();
}
}

In UsersControlller.php, I have:

public function postModalRegister(){
    $user = Sentry::createUser($input);
    /*
    $user->addGroup($usergroup);
    $this->activationMail($user->id, false);
    */

    Queue::push('FinishUserRegistration', ['user_id'=>$user->id]);

    return \Response::json(['success' => true], 200);
}

I have followed the instructions at IronMq + Laravel4: How make it working. When I register a new user, I receive success and I can see message count increase in IronMQ dashboard. But laravel.log doesn't show "marshal!", neither does it when I do curl --data "param1=whatever" http://livesite.com/queue/demo

Also, I have

Route::when('*', 'csrf', array('post', 'put', 'delete', 'patch'));

in my routes file, so the queue/demo route has a csrf before filter too.

Community
  • 1
  • 1
greatmj
  • 36
  • 4
  • Are you passing your token through with the data? As the token is needed for csrf. Else an exception is thrown, meaning the Log::info() line will never run. – Matt Burrow Dec 23 '14 at 12:01
  • @MattBurrow No, I didn't. And I figured out the csrf filter was causing the issue. I solved it by doing this: `//Route::when('*', 'csrf', array('post', 'put', 'delete', 'patch')); Route::when('users*', 'csrf', array('post', 'put', 'delete', 'patch')); Route::when('reviews*', 'csrf', array('post', 'put', 'delete', 'patch')); Route::when('admin*', 'csrf', array('post', 'put', 'delete', 'patch'));` I don't like this approach as the wildcard took care of anything that I would add. Is there a way to exclude just the queue route from the wildcard? Or should I just pass the token? – greatmj Dec 23 '14 at 15:51
  • Just pass the token. – Matt Burrow Dec 23 '14 at 15:55
  • Ok. Thanks! I was hesitant because I'm not sure if it's safe to do so. – greatmj Dec 23 '14 at 16:06

0 Answers0