public JObject Generate() { var data = _httpContextProxy.GetRequestBody <GenerateAuthTokenRequest>(); var userAccontHelper = _serviceResolver.Resolve <UserAccontHelper>(); if (userAccontHelper.ValidateUser(data.UserName, data.Password)) { var user = userAccontHelper.GetUser(data.UserName); if (GetAuthTokenCount(_dbService, user) < MAX_KEYS) { var apikey = GenerateApiKey(); var apikeydata = GenerateApiKeyData(user, apikey); if (_dbService.WriteData(CommonConst.Collection.AUTH_TOKEN_COLLECTION, apikeydata)) { apikeydata[CommonConst.CommonField.AUTH_TOKEN] = apikey; return(_responseBuilder.Success(apikeydata)); } else { _logger.Error("Error in writing data"); return(_responseBuilder.ServerError()); } } else { return(_responseBuilder.CreateReponse(ApiKeyResponseCode._MAX_AUTH_TOKEN_REACHED)); } } else { return(_responseBuilder.Unauthorized()); } }