Currently we have very large method (u:OnLogin event) in UsersEventHandler, that is used only once during user login. It sits there and eats memory in each user event handler created even, when user is already logged-in or not logged-in at all. I propose to
- create UserHelper class and move all login-related code to it;
- make loginUser method, that will have 3 input parameters: $username, $password, $dry_run = false
This method will login user with given credentials and return error as constant otherwise. When $dry_run parameter is specified, then it's only checked, that user with given credentials will be able to login if he tries to.
As the result of this optimization we will be able to transparently login users we want. Also we can upgrade this method, so it can login user by given ID (login and password not checked). Also we can specify where user should be logged-in: front-end or admin. This way it will be easy to implement feature, when administrator can login as any of front-end users without even knowing their password.