diff --git a/150-DOCUMENTATION/002-DBScripts/GetUserModulesByLicenseId.sql b/150-DOCUMENTATION/002-DBScripts/GetUserModulesByLicenseId.sql new file mode 100644 index 0000000..233768d --- /dev/null +++ b/150-DOCUMENTATION/002-DBScripts/GetUserModulesByLicenseId.sql @@ -0,0 +1,25 @@ +-- ============================================= +-- Author: +-- Create date: +-- Description: +-- ============================================= +CREATE PROCEDURE [dbo].[GetUserModulesByLicenseId] + -- Add the parameters for the stored procedure here + @iLicenseId int +AS +BEGIN + IF 1=0 BEGIN + SET FMTONLY OFF + END + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + -- Insert statements for procedure here + SELECT ResourceModule.Id,ResourceModule.Title, ResourceModule.Slug + FROM ResourceModule + INNER JOIN ModuleToLicense ON ResourceModule.Id = ModuleToLicense.ModuleId + WHERE ModuleToLicense.Status = 1 + AND ModuleToLicense.LicenseId = @iLicenseId + +END \ No newline at end of file diff --git a/400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs b/400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs index 546bc5e..2892170 100644 --- a/400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs +++ b/400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs @@ -38,70 +38,81 @@ namespace AIAHTML5.API.Controllers //01. check user is authenticated or not by login credential macth bool isUserAuthenticated = AIAHTML5.API.Models.Users.IsUserAuthenticated(credentials); - User objUser = new Models.User(); + User userInfo = new Models.User(); //02. Get User details - objUser = AIAHTML5.API.Models.Users.getUserDetails(credentials); + userInfo = AIAHTML5.API.Models.Users.getUserDetails(credentials); if(isUserAuthenticated) { + //04.insert Log login details + AIAHTML5.API.Models.Users.insertLoginDetails(userInfo.Id); + //03.delete past wrong login attempts of user - objUser.IsCorrectPassword = true; - int wrongAttemptDeteledCount = AIAHTML5.API.Models.Users.deletePastWrongAttempts(objUser.Id); + userInfo.IsCorrectLoginId = true; + userInfo.IsCorrectPassword = true; + + int wrongAttemptDeteledCount = AIAHTML5.API.Models.Users.deletePastWrongAttempts(userInfo.Id); if (wrongAttemptDeteledCount < 0) { - logger.Fatal("Unable to delete past wrong login attempts for userId= "+objUser.Id); + logger.Fatal("Unable to delete past wrong login attempts for userId= "+userInfo.Id); } - if (objUser.UserType == AIAHTML5.API.Models.User.SUPER_ADMIN || objUser.UserType == AIAHTML5.API.Models.User.GENERAL_ADMIN) + // for ADMIN (superadmin/ general admin) users by default all module loads + if (userInfo.UserType == AIAHTML5.API.Models.User.SUPER_ADMIN || userInfo.UserType == AIAHTML5.API.Models.User.GENERAL_ADMIN) { - objUser.Modules = AIAHTML5.API.Models.Users.getAllModulesList(); - AIAHTML5.API.Models.Users.insertLoginDetails(objUser.Id); + userInfo.Modules = AIAHTML5.API.Models.Users.getAllModulesList(); + } else { //03. get the license id for aUTHENTICATED USER - objUser.LicenseId = AIAHTML5.API.Models.Users.getLicenseIdForThisUser(objUser.Id, "license"); - objUser.EditionId = AIAHTML5.API.Models.Users.getLicenseIdForThisUser(objUser.Id, "edition"); - - //04.insert Log login details - //AIAHTML5.API.Models.Users.insertLoginDetails(objUser.Id); - //Commented above code inserts if the user license ~ subscription expired as well - + userInfo.LicenseId = AIAHTML5.API.Models.Users.getLicenseIdForThisUser(userInfo.Id, "license"); + userInfo.EditionId = AIAHTML5.API.Models.Users.getLicenseIdForThisUser(userInfo.Id, "edition"); + //05.Check user is active or not - //objUser.IsActive = AIAHTML5.API.Models.Users.isUSerActive(objUser); //Id suggested but passed userInfo to avoid multiple database hitting + // Below statement required as tl says it is required for better code readability + userInfo.IsActive = userInfo.IsActive; - //if (objUser.IsActive) - //{ //Commenting as Inactive userid returns from here - //5.1 check the License expiration + + //5.1 get license/ licenseSubscription details //objUser.License.IsActive = AIAHTML5.API.Models.Users.isLicenseActive(objUser.LicenseId); - objUser.License = AIAHTML5.API.Models.Users.getLicenseDetails(objUser.LicenseId); - objUser.LicenseSubscriptions = AIAHTML5.API.Models.Users.getLicenseSubscriptionDetails(objUser.LicenseId); - objUser.SubscriptionExpirationDateString = AIAHTML5.API.Models.Users.SubscriptionExpirationDateString(objUser.LicenseId); + userInfo.License = AIAHTML5.API.Models.Users.getLicenseDetails(userInfo.LicenseId); + userInfo.LicenseSubscriptions = AIAHTML5.API.Models.Users.getLicenseSubscriptionDetails(userInfo.LicenseId); + + //5.2 check the License expiration irespective of either user is active or not because on AIA + //we shows the License expiration message for inactive users too + bool isLicenseSubscriptionExpired = false; + string expirationDate = AIAHTML5.API.Models.Users.getLicenseExpirationDate(userInfo.LicenseId,out isLicenseSubscriptionExpired); + // send message to the UI for license expiration //5.2 Check for subscription Expiration [Promoted for case if license inactive along with subscription expired] - if (!string.IsNullOrEmpty(objUser.SubscriptionExpirationDateString)) + if (isLicenseSubscriptionExpired) { - objUser.IsSubscriptionExpired = true; + userInfo.IsSubscriptionExpired = isLicenseSubscriptionExpired; + userInfo.SubscriptionExpirationDate = expirationDate; } - if (objUser.License.IsActive) - { - // send message to the UI for license expiration - //5.2 Check for subscription Expiration - //Insert user login details - AIAHTML5.API.Models.Users.insertLoginDetails(objUser.Id); - objUser.Modules = AIAHTML5.API.Models.Users.getModuleListByLicenseId(objUser.LicenseId); + + if (userInfo.License.IsActive) + { + //Insert user login details + //AIAHTML5.API.Models.Users.insertLoginDetails(objUser.Id); - if (!objUser.License.IsTermAccepted) - { - ArrayList termsList = AIAHTML5.API.Models.Users.getTermsOfServiceText(); - foreach (Hashtable item in termsList) + if (!userInfo.License.IsTermAccepted) + { + ArrayList termsList = AIAHTML5.API.Models.Users.getTermsOfServiceText(); + foreach (Hashtable item in termsList) + { + userInfo.TermsOfServiceTitle = item["title"].ToString(); + userInfo.TermsOfServiceText = item["content"].ToString(); + } + } + else { - objUser.TermsOfServiceTitle = item["title"].ToString(); - objUser.TermsOfServiceText = item["content"].ToString(); + userInfo.Modules = AIAHTML5.API.Models.Users.getModuleListByLicenseId(userInfo.LicenseId); } } - } + //else //{ // //6. @@ -119,34 +130,38 @@ namespace AIAHTML5.API.Controllers } else { - bool isCorrectLoginId = AIAHTML5.API.Models.Users.isCredentialCorrect(credentials, objUser, "loginId"); - //bool isCorrectPassword = AIAHTML5.API.Models.Users.isCredentialCorrect(credentials, userInfo, "password"); + bool isCorrectLoginId = AIAHTML5.API.Models.Users.isCredentialCorrect(credentials, userInfo, "loginId"); if (!isCorrectLoginId) { - objUser = null; + // send message back to th UI that login id is incorrect + userInfo.IsCorrectLoginId = isCorrectLoginId; } else { - objUser.IsCorrectPassword = false; - objUser.IncorrectLoginAttemptCount = AIAHTML5.API.Models.Users.checkNoOfWrongAttempts(objUser.Id) + 1; - objUser.LoginFailureCauseId = ErrorHelper.E_PASSWORD_NOT_MATCH; - //01. insert wrong attempt in dtabase - if (objUser.IncorrectLoginAttemptCount == 1) - { - int insertedCount = AIAHTML5.API.Models.Users.insertWrongAttemptofUser(objUser.Id); - } - else + userInfo.IsCorrectLoginId = true; + bool isCorrectPassword = AIAHTML5.API.Models.Users.isCredentialCorrect(credentials, userInfo, "password"); + + if (!isCorrectPassword) { - int updateCount = AIAHTML5.API.Models.Users.saveWrongAttemptofUser(objUser.Id); + // send message back to th UI that password is incorrect + userInfo.IsCorrectPassword = false; + + //get wrong attempt count of user + userInfo.IncorrectLoginAttemptCount = AIAHTML5.API.Models.Users.checkNoOfWrongAttempts(userInfo.Id) + 1; + userInfo.LoginFailureCauseId = ErrorHelper.E_PASSWORD_NOT_MATCH; + + //01. insert wrong attempt in dtabase + int updateCount = AIAHTML5.API.Models.Users.saveWrongAttemptofUser(userInfo.Id); + if (updateCount < 0) { //Put the log in log file - logger.Fatal("Unable to Update past wrong login attempts for userId= " + objUser.Id); + logger.Fatal("Unable to Update past wrong login attempts for userId= " + userInfo.Id); } else { - + //02. check no of wrong attempts //userInfo.IncorrectLoginAttemptCount = AIAHTML5.API.Models.Users.checkNoOfWrongAttempts(userInfo.Id); //if (userInfo.IncorrectLoginAttemptCount >= 5) @@ -159,24 +174,25 @@ namespace AIAHTML5.API.Controllers // // send message back to UI for login fail //} - if (objUser.IncorrectLoginAttemptCount > 4) + if (userInfo.IncorrectLoginAttemptCount > 4) { - objUser.IsBlocked = true; - objUser.LoginFailureCauseId = ErrorHelper.E_USER_ID_BLOCKED_24_HRS; + userInfo.IsBlocked = true; + userInfo.LoginFailureCauseId = ErrorHelper.E_USER_ID_BLOCKED_24_HRS; } } } - //if (objUser.License != null && !string.IsNullOrEmpty(objUser.License.AccountNumber)) + // unreachable code detected as license is null + //if (userInfo.License != null && !string.IsNullOrEmpty(userInfo.License.AccountNumber)) //{ - // int result = AIAHTML5.API.Models.Users.insertUserLoginLog(objUser.License.AccountNumber, objUser.LoginFailureCauseId, null, objUser.EditionId.ToString(), null); + // int result = AIAHTML5.API.Models.Users.insertUserLoginLog(userInfo.License.AccountNumber, userInfo.LoginFailureCauseId, null, userInfo.EditionId.ToString(), null); // if (result < 0) - // logger.Fatal("Unable to insert wrong attempt detail in UserLoginLog table for accountNumber= " + objUser.License.AccountNumber); + // logger.Fatal("Unable to insert wrong attempt detail in UserLoginLog table for accountNumber= " + userInfo.License.AccountNumber); //} } } - if(objUser!=null) - authenticationRepsonse = JsonConvert.SerializeObject(objUser); + if(userInfo.IsCorrectLoginId) + authenticationRepsonse = JsonConvert.SerializeObject(userInfo); else authenticationRepsonse = AIAConstants.USER_NOT_FOUND; diff --git a/400-SOURCECODE/AIAHTML5.API/Controllers/LicenseTermConditionController.cs b/400-SOURCECODE/AIAHTML5.API/Controllers/LicenseTermConditionController.cs index 7c9a397..0f3d9d1 100644 --- a/400-SOURCECODE/AIAHTML5.API/Controllers/LicenseTermConditionController.cs +++ b/400-SOURCECODE/AIAHTML5.API/Controllers/LicenseTermConditionController.cs @@ -8,6 +8,7 @@ using log4net; using AIAHTML5.API.Constants; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using AIAHTML5.API.Models; namespace AIAHTML5.API.Controllers { @@ -26,19 +27,30 @@ namespace AIAHTML5.API.Controllers } // POST api/licensetermcondition - public HttpResponseMessage Post([FromBody]string licenseeAccountNumber) + public HttpResponseMessage Post([FromBody]JObject userLicenseInfo) { ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); logger.Debug("inside POST"); HttpResponseMessage response = null; - dynamic result = AIAHTML5.API.Models.Users.UpdateLicenseTerm(licenseeAccountNumber); + int licenseId = Convert.ToInt32(userLicenseInfo["userLicenseId"]); + User user = new User(); + dynamic userModules = null; // assigned to avoid unassigned local variable compilation error; + + dynamic result = AIAHTML5.API.Models.Users.UpdateLicenseTerm(userLicenseInfo); if (Convert.ToString(result) != AIAConstants.SQL_CONNECTION_ERROR) { if (Convert.ToInt32(result) > 0) - response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.LICENSE_TERM_CONDITION_UPDATE_SUCCESS) }; + { + user.Modules = Users.getModuleListByLicenseId(licenseId); + userModules = JsonConvert.SerializeObject(user); + + response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(userModules) }; + } else + { response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.LICENSE_TERM_CONDITION_UPDATE_FAILED) }; + } } else {