User Management

Magnet Max offers a user management system that is easy to use. The MMUser class allows for user registration, login, logout, and search. An MMUser has properties that describe a user (e.g., userID, userName, firstName, lastName, email, etc.) and it also provides an extras (String, String) dictionary that allows you to associate extra data to a user.

User Registration

The following shows the basic way to register a user. For advanced options, see Advanced.

var user = {}; user.firstName = "John" user.lastName = "Doe" user.userName = "[email protected]" user.password = "magnet" Max.User.register($scope.data).success(function () { // here code on success register }).error(function (err) { // here code on error });

User Login

The following shows the basic way to log in a user. For advanced options, see Advanced.

var username = "[email protected]" var password = "magnet" Max.User.login(username, password).success(function () { // here code on login success }).error(function (err) { // here code on error }).always(function () { // here code on any response });

User Logout

The following shows how to log out a user.

Max.User.logout(); // here code on logout success }).error(function (err) { // here code on error });

User search uses elastic search.

It can perform queries to find a list of users:

var offset = 0; var searchStr = 'john'; var query = 'firstName:*' + searchStr + '*' + '%20AND%20' + 'lastName:*' + searchStr + '*'; // search for users based on first and last name using advanced search query Max.User.search(query, 50, offset).success(function (users) { if ( (users || []).length ) { // here code on login success } });

And find users by userId:

var UserUids = ["UserId1", "UserId2"]; Max.User.getUsersByUserIds(newUids).success(function(users) { if ( (users || []).length ) { // here code on success } });

User Avatar

To set an avatar for a user, refer to the code below.

Max.User.setAvatar(imageData).success(function() { // here code on success }).error(function(e) { // here code on error });

User Passwords

User passwords can be changed in two ways: have the server generate and email a One-time password (OTP) or use an old password to authorize a change.

To have the server generate and email a user an OTP code:

Max.User.passwordReset({ userName: 'userName', otpCode: 'usersOTPCode', newPassword: 'MyNewPassword', passwordResetMethod: 'OTP' }).success(function (res) { if ( true === res ) { // here code on success } else { // here code on error } }).error(function (err) { // here code on error });

To use a user’s old password to authorize a password change:

// reset user by supplying credentials Max.User.passwordReset({ oldPassword: "OldPassword", newPassword: "NewPassword", passwordResetMethod: 'OLDPASSWORD' }).success(function (res) { if ( true === res ) { // here code on success } else { // here code on error } }).error(function (err) { // here code on error });

Advanced

Register Pending Users

MMUser provides a way to register a user with a pending state. The user must be approved on the Magnet Max console before they can successfully log in.

var user = {}; user.firstName = "John" user.lastName = "Doe" user.userName = "[email protected]" user.password = "magnet" Max.User.register($scope.data).success(function () { // here code on success register }).error(function (err) { // here code on error });