I am developing a web application that involves Symfony2 and AngularJs. I have a question about the right way of authenticate users in the site.
I have built a function
The bundle you linked is a better solution than your current.
It's because of the differences between security needs of a REST Api and a classic form-based application.
Look at the jwt.io introduction to Json Web Token, and after, you should try to implement the LexikJWTAuthenticationBundle which is very clean, easy-to-use, securely and powerful.
JWT will provide more security and a ready-to-use login process, only need a few lines of configuration. Of course, you can easily manage, register and create token from users retrieved/registered by your user provider (for me it's the FOSUserBundle).
A JWT is a real signature representing your user. Read more in the link I've given you.
See also this JWTAuthenticationBundle Sandbox for a real example with AngularJS.