Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I'm using Symfony on my backend, accessed only by a JS frontend with AJAX requests.
The issue I'm having is that the return codes sent by the FOSUserBundle does not coincide with what I'm expecting for 'user management' actions.
For instance, when for instance a user tries to register on the frontend :
What I get:
Registration success --> Redirection to '.../confirmed'
Registration failure --> 200 (re-displaying the form page)
What I would like to have:
Registration success --> 202 Added
Registration failure --> 500 or else
Do you know how to archieve that, especially given that, in FOSUserBundle, there are no events to hook on to for failures?
You can modify the file RegistrationController.php in the path /vendor/friendsofsymfony/user-bundle/Controller/
In this file, you will find a method called registerAction. Simply add the following code in your form validation part.
if ($form->isValid()) {
$event = new FormEvent($form, $request);
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event);
$userManager->updateUser($user);
if (null === $response = $event->getResponse()) {
$url = $this->generateUrl('fos_user_registration_confirmed');
$response = new RedirectResponse($url);
}
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
return $response;
}
else
{
return new JsonResponse(array('status' => 'failure'), 500);
}
Keep in mind this is a simple case of invalid form validation that I have provided. You can do other type of modifications in this part.
After a few analysis, I decided to rewrite entirely what I needed from scratch, since it was a very small subset of FOSUserBundle.
This solves the problem, allowing to return specific responses with the desired HTTP codes, at any stage of the processes.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 months ago.
Improve this question
Please help me. The website works fine in the local host, but it is having error in the C panel. How to solve?
the path is:
app/config/app.php
you can use Process Component of Symfony that is already in Laravel
http://symfony.com/doc/current/components/process.html
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
inside your elcdetails use
$macAddr = new Process('getmac');
$macAddr->run();
// executes after the command finishes
if (!$macAddr->isSuccessful()) {
throw new ProcessFailedException($macAddr;
}
//or whatever you want to do with the output.
echo $macAddr->getOutput();
note that, if you are trying to get the client mac address, short answer is you cannot.
From your image, I'm supposing you defined the public function exec() function somewhere above or below in your controller. You cannot reference to it that way since its a method in your controller class.
So change it to this instead. $macAddr = $this->exec('getmac');
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I have two fields, views, which just counts views, and add_to_views, a number that we add to views.
I need to display the sum of these numbers in the blade. Of course, you can just do this and everything will work.
{{ $article->views + $article->add_to_views }} Views
But I want to make the summation function separately and output the already ready number
Here is what I am trying to do, in the Article model itself I create a method
public function getTotalViews() {
return $this->views + $this->add_to_views;
}
Further in the controller I call it
$article = Article::where('id')->first();
$article->getTotalViews();
And I bring to the blade
{{ $article->getTotalViews() }} Views
But I get the error
Call to a member function getTotalViews() on null
You're missing the ID for the Article that you're trying to get so it is null.
It should actually be something like:
$article = Article::where('id', 1)->first();
Or alternatively, you could do
$article = Article::find(1);
For a longer explanation on the find method:
https://laravel.com/docs/8.x/eloquent#retrieving-single-models
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have to send a email using cron job in laravel, the flow is that the user will select the time for the email to be sent. ones done, that email would be sent at that time but only ones, we dont have to send it again and again.
You can dispatch the job with the delay method.
For exampe this job will be run in one day from now:
dispatch(YourJob::class)->delay(now()->addDay());
Doc ref about delayed job https://laravel.com/docs/8.x/queues#delayed-dispatching
I suggest using Laravels queues, more specifically the Mailer::later and the Mailer::laterOn method for that regard. You can delay the sending of the mail and it's only getting executed once.
YourMailable::later(now()->addMinutes(10))
or without a mailable:
Mail::later(now()->addMinutes(10), 'emails.view', $data, function ($message) {
//
});
You can also specify a specifc queue within your Mailable:
use Illuminate\Mail\Mailable;
class YourMailable extends Mailable
{
protected string $queue = 'mails-queue';
// ...
}
With the Mail facade you can use the laterOn method:
Mail::laterOn('mails-queue', now()->addMinutes(10), 'emails.view', $data, function ($message) {
//
});
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
ASP.NET BOILERPLATE: I have a table Asset for which I have created AssetApplicationService with base class CRUDAsync; I have wired up AssetController, & appropriate DTO's, I am able to retrieve data and show on the list as similar to user list.
when I click on Create New Asset,I am able to bring the modal dailog as well until now it is all good, I have copied the user\index.js and tailored to call my asset application service from javascript...this is where i am struck
var _assetService = abp.services.app.asset; //line1
var _$modal = $('#AssetCreateModal');
var _$form = _$modal.find('form');
line 1 returns me undefined when I debug through alert(_assetService), not sure why...where as abp.services.app.user, role works fine.
AssetApplicationService must be implemented by IApplicationService.
public interface IAssetApplicationService : IApplicationService
{
}
public class AssetApplicationService : IAssetApplicationService
{
}
Note: I've replied your previous question. Please mark the answer as solution if that worked for you.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I have 2 different logged in users. I go to the same page in both accounts, and hit refresh in the same time.
On that page I have ajax call which calls function:
public JsonResult GetAppointments()
{
var userId = User.Identity.GetUserId();
var eventList = from a in db.Appointments
where a.UserId == userId
select new
{
...
So it should return different appointments, based on userId.
But for some reason, one user gets data from other user. (On page I get same data for both users)
It looks like that function call from first user occupied thread, and second user got data from that thread, not from his function call.
Anyone knows how is this possible and why is this happening?
EDIT:
When this happends, I hit logout for second user and get: "The anti-forgery cookie token and form field token do not match." error. It seems that somehow second user got form field token from first user also, don't know how.
I found problem.
On controller I had:
OutputCache(NoStore = true, Duration = 1, VaryByParam = "")
I changed Duration = 0 and everything works fine now.