I have two tables, users
and tokens
.
Each user have a activated
field and each token have the {id, token, user_id, created}
fields.
The way the app should work is: On the creation, the app will -
activated
field is empty (to avoid manipulations to the submitted data).tokens
table.On update, the app will -
activated
field.activated
field to false.I know how to activate the account through the controller and how to setup the router for that.
What I need is mainly the model configuration.
For example:
I think that the token creation should be done in the afterSave
method, so - how do I determine if the method is called by an update or by a create operation?
Thanks for any help
yossi you can also specify the fields that should be saved from the form though - a whitelist of fields it is ok to save in you $this->save() call. That way you can stop a hacker passing an ID in the request, and you should just set it in the controller yourself then with $this->Token->id = whatever you have, I would personally use saveField ('activated) in conjunction with this (just saves a single field!). Fat models is best if you can but get it working first then refactor it if you have got stuck. Better than wasting lots of time writing perfect first time.