{"size": 1024, "ext": "js", "max_stars_repo_path": "controllers/SignupCtrl.js", "max_stars_repo_name": "adrianbarwicki/nodejs-authentication-microservice", "max_stars_repo_stars_event_min_datetime": "2017-11-26T02:55:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:38:00.000Z", "max_issues_repo_path": "controllers/SignupCtrl.js", "max_issues_repo_name": "adrianbarwicki/nodejs-authentication-microservice", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "controllers/SignupCtrl.js", "max_forks_repo_name": "adrianbarwicki/nodejs-authentication-microservice", "max_forks_repo_forks_event_min_datetime": "2018-03-25T23:54:37.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-28T04:26:06.000Z"}
{"max_stars_count": 14, "max_issues_count": null, "max_forks_count": 4, "avg_line_length": 24.380952381, "max_line_length": 85, "alphanum_fraction": 0.6240234375}
var async = require("async");
var AuthService = require("../services/AuthService.js");

const createLocalAccount = (appId, email, password, callback) => {
  if (!appId || !email || !password) {
    return callback({
      status: 400,
      code: "INITIAL_PARAMS"
    });
  }
  
  var newUser = {};

	if (password) {
		newUser.password = AuthService.generateHashSync(password);
	}
	
  async.waterfall([
    callback => AuthService.createNewUser(appId, (err, rNewUser) => {
        if (err) {
          return callback(err);
        }

        newUser = rNewUser;
        
        return callback();
    }),
    callback => AuthService.createNewEmail(appId, newUser.id, email, callback),
    callback => AuthService.createNewPassword(appId, newUser.id, password, callback),
    callback => AuthService.createNewToken(appId, newUser.id, callback)
  ], (err, rUserToken) => {
    if (err) {
      console.error(err);
    }

    callback(err, rUserToken);
  });
};

module.exports = {
	createLocalAccount: createLocalAccount,
};