1
votes

I'm building a Symfony 1.4 project that is using sfDoctrineGuardPlugin for users/authentication. I have a field on my user table named "access_token" that I would like to populate with an auto-generated value upon user registration. I see that for registration, the sfGuardRegisterForm is used for validation. Unfortunately, when I run ./symfony doctrine:build-forms from the command line, this form doesn't appear to be extended, meaning that I can't generate an access token there without editing the plugin.

Alternatively, I was thinking of modifying the sfRequest parameters such that I manually set the "access_token" value before attempting to validate via this form. However, since I'm allowing users to register both by a frontend application as well as an API application, this means that I would have to make sure I manually stuff this parameter value in both places, which seems inefficient. However, perhaps that is actually the right way to go, and trying to modify the form is not ideal.

Any input/suggestions? Would anyone do anything different than the ideas I have listed here?

Edit: I've already create a public static method on my sfGuardUser model named generateAccessToken, which returns the value. I'm just trying to figure out the best place to call this in my project's code.

1
Does your access_token depends on current request? - Darmen Amanbayev
The generation of the access_token does not depend upon the current request. It will be random, unique, and private, but not based upon the request at all. It will be used later (post-registration) when making API calls on behalf of the user, at which point it will be included as a URL parameter. - Matt Huggins

1 Answers

1
votes

sfDoctrineGuardPlugin does not provide user registration functionality. This why you have to implement it on your own. So, in your controller you can populate a field just the way it's being done with symfony:

class myActions extends sfActions {
    public function executeRegistration(sfWebRequest $request) {
        ...
        $form = new myRegisterForm();
        $form->setDefault('access_token', sfGuardUser::generateAccessToken());
        ...
    }
}

And the access_token widget should be an instance of sfWidgetFormInputHidden. Hope this helps.