NOTICE: The TGIMBA git hub repository has been corrupted and I had to start over. The link to the repository is here -> Git Code Commit
To redo the login functionality, I defined a class for the Login Controller. However, instead of an interface as described in the example above, I used a base class. For most controllers, a base object is more useful in my experience to hold common data points that all controllers share. First gotcha I encountered is that require() is Node JS construct. So, dropping the require() and module.export.X methods and then just creating the objects worked.
The new version looks like this:
I am not actually using the token property in BaseController.js, but I can. As you can see, the property set in BaseController.js is present in LoginController.js.
I will most likely leave the token in the Session.js. But common properties like this that are shared by the controllers would go here. If I don’t end up using it, I will delete BaseController.js
- Login_Login() becomes a little less confusing. I never really liked this naming convention, but I kept getting lost with all of the functions. With the object approach, its a little readable (I think)
- EVERYTHING is public (as I understand it). There is not an easy way that is C#’ish to accomplish this. Reference #2 has some interesting ideas though. But they are more than I want to implement here.
I ended up creating an object for LoginController.js and ApplicationFlow.js. I also added BaseController.js and RegistrationController.js objects (Registration.js is not functional yet). So is the extra ‘object’ layer worth it? I honestly do not know at this point…but at least it is different and I am learning new stuff 🙂 Next post will be the registration page…really 🙂