UserManager

(c) 2013-2014 http://ircanywhere.com

Author: Ricki Hastings

IRCAnywhere server/users.js

loginServerUser(email, password)

Handles login of IRC server user

Arguments:
  • email (string) – User email
  • password (string) – User password
updateLastSeen(userId[, lastSeen])

Update lastSeen entry of user.

Arguments:
  • userId (string) – Id of the user
  • [lastSeen] (date) – New lastSeen value
class UserManager.UserManager()

Responsible for handling user related actions ie registering, logging in, forgot passwords etc. Most of these actions are triggered via API calls.

Returns:void
UserManager.init()

Sets up the API routes and anything else needed by the user manager class. Such as timers and the SMTP connection

Returns:void
UserManager.timeOutInactive()

Responsible for disconnecting any inactive users

This function is ran every hour or so, but not perfectly precise, but it shouldn’t drift off too much because it re-corrects it self.

Returns:void
UserManager.isAuthenticated(data)

Checks the sent in authentication string (should be “token=actualToken”) all in string format, this is how it is sent in the authentication command and how it lies as a cookie. It also takes a full cookie string, such as “someKey=1; someOtherKey=2; token=actualToken” and the token will only be parsed and used.

Returns a valid user object which can be used to set on the socket for example or HTTP request, returns false if invalid

Arguments:
  • data (object) – A valid data object from sock.js
UserManager.registerUser(req)

Handles user registrations, it takes req and res objects from express at the moment however it should probably stay this way, because the api to register a user is at /api/register. I can’t see a reason to change this to take individual parameters.

Arguments:
  • req (object) – A valid request object from express
Returns:

An output object for the API call

UserManager.userLogin(req, res)

Handles the login call to /api/login and sets an appropriate cookie if successful.

Arguments:
  • req (object) – A valid request object from express
  • res (object) – A valid response object from express
Returns:

An output object for the API call

UserManager.userLogout(req)

Handles the call to /api/logout which is self explanatory.

Arguments:
  • req (object) – A valid request object from express
Returns:

An output object for the API call

UserManager.forgotPassword(req)

Handles the call to /api/forgot to send a forgot password link

Arguments:
  • req (object) – A valid request object from express
Returns:

An output object for the API call

UserManager.resetPassword(req)

Handles the call to /api/reset which will be called when the reset password link is visited Checking is done to make sure a token exists in a user record.

Arguments:
  • req (object) – A valid request object from express
Returns:

An output object for the API call

UserManager.updateSettings(req)

Handles the call to /api/settings/updatesettings which will update the settings for that user checking for authentication and validating if necessary.

Arguments:
  • req (object) – A valid request object from express
Returns:

An output object for the API call

UserManager.resetPassword(req)

Handles the call to /api/settings/changepassword which is almost identical to resetPassword however it checks for authentication and then changes the password using that user, it doesn’t take a token though.

Arguments:
  • req (object) – A valid request object from express
Returns:

An output object for the API call

UserManager.updatePassword(user, password, confirmPassword[, currentPassword])

Updates a users password, doesn’t bypass any checkings, just doesn’t define how you select the user, so via a token or direct user object

Arguments:
  • user (promise) – A valid promise object from isAuthenticated
  • password (string) – The new password to set
  • confirmPassword (string) – The same password again
  • [currentPassword] (string) – The current password
Returns:

An output object for the API call

UserManager.onUserLogin(me[, force])

An event which is called when a successful login occurs, this logic is kept out of the handler for /api/login because it’s specific to a different section of the application which is the networkManager and ircFactory.

Arguments:
  • me (object) – A valid user object
  • [force] (boolean) – Whether to force the reconnect of a disconnected client
Returns:

void

UserManager.parse(file, replace)

Looks for a template and parses the {{tags}} into the values in replace and returns a string, used to parse emails. Very basic parsing which will probably be replaced by something more powerful in the future with HTML outputs.

Arguments:
  • file (string) – The name of the email template
  • replace (object) – A hash of keys and values to replace in the template
Returns:

A parsed email template