[Flow] Beginner Questions

Steffen Wickham steffen at gaming-inc.de
Mon Jan 13 14:12:08 CET 2014


Hello and welcome Jan! :)

I agree that there is some lack of documentation for specific solutions 
but it is much easier to achieve a valid login system as you can imagine.

Getting a working authentication in Flow isn't that hard. Here a short 
description what to do:
- Derive your User model from AbstractParty of TYPO3.Party package and 
add all User properties you need (except login credentials)
- Create a new Controller which handles the authentication. This is my 
controller and its Login form: [1]
- Create a new instance of your User model, add all data and create a 
new account like described in [2] but before the last line of the code, 
link your User model to the account ( $account->setParty($userModel); ). 
Don't forget to persist your newly created User model by using the 
\TYPO3\Party\Domain\Repository\PartyRepository (no special 
UserRepository necessary), too.
- Modify your Configuration/Settings.yaml like my Settings.yaml in [1]. 
Please note that the "uri" value is a path defined in my Routes.yaml

Now you should be able to authenticate your user. To get a logged in 
user you can check it like shown in [3].
So you can forget about using hashService by your own. But for your 
information, the changed hash value is correct as it uses an other salt 
each time using the bcrypt algorythm.


In reply to your second question I just can say it sounds like you are 
doing it the right way. You fetch all data within your controller, pass 
it to the view and use ViewHelper like "for" to go through it. If you 
need more filtering or advanced features (e.g. I need a special for-loop 
for dates to mark last week, last month and so on), you have to write 
your own ViewHelper. But the normal for loop will do its job very well 
in most cases.

To your create action code:
That's not the way how it should be done. TYPO3 Flow allows you to use 
dependency injection for all kind of classes and is much easier to use, 
so use it! ;-)

When you need your Repository, just add a new property to your class and 
provide proper phpdoc annotations. For example:
/**
  * @var *\*\*\AddressDataRepository
  * @Flow\Inject
  */
protected $addressDataRepository;

So you can use it within your create action like 
$this->addressDataRepository->add($newAddressData);
No need to create it yourself. Creating new models by using a "new" 
command is fine IMHO. For further informations, please have a look at [4].

Happy coding! :)
Steffen



[1] https://gist.github.com/BlackIPS/666c30d8a4826b37d08f
[2] 
http://docs.typo3.org/flow/TYPO3FlowDocumentation/TheDefinitiveGuide/PartIII/Security.html#creating-accounts
[3] https://gist.github.com/BlackIPS/1a213b5f52e6f7046f71
[4] 
http://docs.typo3.org/flow/TYPO3FlowDocumentation/TheDefinitiveGuide/PartIII/ObjectManagement.html#object-dependencies 




Am 13.01.14 11:15, schrieb Jan Herzog:
> Hello,
>
> im new to Flow (not new to php), and got a few questions.
> To be honest, i read only Partialy trough the documentation (its quite 
> tiring).
>
> First of all - in my Current project i tried using the Flow 
> authentication system, but didnt get it working. The Documentation on 
> this is leaking of usefull example code. So i made my own User, with 
> username as ID, and a password. When i tried use 
> \TYPO3\Flow\Security\Cryptography\HashService generateHash function, i 
> ended up getting different hash values each time executing, while 
> still using the same string. So i switched to Hmac.. but i dont know 
> what it exactly does, and if this is any secure for passwords.
> - On this i need an example on how to use the Flow authentication, 
> with linking to an object (i need stuff like address information 
> linked to a user), or just an information on how hmac works.
>
> Second - i got (for example) 2 models. The user, and an Address Data 
> object. I wanted an profile page for the User, so i used 
> /user/show?user=username. In the show action i linked the user to the 
> view. In the Template i used an loop (<f:for each="{user.addressData}" 
> as="addressData">) to cycle trough different address informations. But 
> im not sure if its the right way. It feels quite dirty.
>
> Also in the Create action im doing this:  ($addressDataRepository = 
> new *\*\*\AddressDataRepository();) to add some data with a new user. 
> But this also feels quite dirty.
>
> there might be loads more questions, but i think those two are giving 
> me the most headache.
>
> Thanks for any help you can give me.
> Greetings
> Aivaria
>
> _______________________________________________
> Flow mailing list
> Flow at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow



More information about the Flow mailing list