From 7f812aae6819fa9ec3de92ff7dcda2dfe1dd0008 Mon Sep 17 00:00:00 2001 From: Utkarsh Singh Date: Fri, 15 Sep 2017 17:31:12 +0530 Subject: [PATCH] Committing restructured code of login --- 400-SOURCECODE/AIAHTML5.API/Constants/AIAConstants.cs | 4 ++++ 400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs | 156 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs | 209 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------------------------------------------------------------------------- 400-SOURCECODE/AIAHTML5.API/Models/Users.cs | 228 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------- 400-SOURCECODE/AIAHTML5.Web/app/controllers/HomeController.js | 42 +++++++++++++++++++++++++++++++----------- 5 files changed, 458 insertions(+), 181 deletions(-) diff --git a/400-SOURCECODE/AIAHTML5.API/Constants/AIAConstants.cs b/400-SOURCECODE/AIAHTML5.API/Constants/AIAConstants.cs index ea87561..f37b114 100644 --- a/400-SOURCECODE/AIAHTML5.API/Constants/AIAConstants.cs +++ b/400-SOURCECODE/AIAHTML5.API/Constants/AIAConstants.cs @@ -18,6 +18,10 @@ namespace AIAHTML5.API.Constants public const string KEY_NAME = "name"; public const string KEY_SLUG = "slug"; public const string KEY_DESCRIPTION = "Description"; + public const string KEY_LICENSE = "LICENSE"; + public const string KEY_EDITION = "EDITION"; + public const string KEY_LOGINID = "LOGINID"; + public const string KEY_PASSWORD = "PASSWORD"; public const string PASSWORD_UPDATE_SUCCESS = "Password updated successfully"; public const string PASSWORD_UPDATE_FAILED = "Password update failed"; diff --git a/400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs b/400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs index b4fa666..49e5105 100644 --- a/400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs +++ b/400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs @@ -8,6 +8,8 @@ using System.Net.Http; using System.Web.Http; using log4net; using AIAHTML5.API.Constants; +using AIAHTML5.API.Models; +using System.Collections; namespace AIAHTML5.API.Controllers { @@ -31,28 +33,164 @@ namespace AIAHTML5.API.Controllers ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); logger.Debug("inside POST"); - bool isUserAuthenticatedByDefault = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["isUserAuthenticated"]); - if (isUserAuthenticatedByDefault) + dynamic authenticationRepsonse; + + //01. check user is authenticated or not by login credential macth + bool isUserAuthenticated = AIAHTML5.API.Models.Users.IsUserAuthenticated(credentials); + + User objUser = new Models.User(); + + //02. Get User details + objUser = AIAHTML5.API.Models.Users.getUserDetails(credentials); + + if(isUserAuthenticated) { - return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("true") }; + //03.delete past wrong login attempts of user + objUser.IsCorrectPassword = true; + int wrongAttemptDeteledCount = AIAHTML5.API.Models.Users.deletePastWrongAttempts(objUser.Id); + if (wrongAttemptDeteledCount < 0) + { + logger.Fatal("Unable to delete past wrong login attempts for userId= "+objUser.Id); + } + + if (objUser.UserType == AIAHTML5.API.Models.User.SUPER_ADMIN || objUser.UserType == AIAHTML5.API.Models.User.GENERAL_ADMIN) + { + objUser.Modules = AIAHTML5.API.Models.Users.getAllModulesList(); + AIAHTML5.API.Models.Users.insertLoginDetails(objUser.Id); + } + 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 + + //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 + + //if (objUser.IsActive) + //{ //Commenting as Inactive userid returns from here + //5.1 check the License expiration + //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); + + //5.2 Check for subscription Expiration [Promoted for case if license inactive along with subscription expired] + if (!string.IsNullOrEmpty(objUser.SubscriptionExpirationDateString)) + { + objUser.IsSubscriptionExpired = true; + } + 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 (!objUser.License.IsTermAccepted) + { + ArrayList termsList = AIAHTML5.API.Models.Users.getTermsOfServiceText(); + foreach (Hashtable item in termsList) + { + objUser.TermsOfServiceTitle = item["title"].ToString(); + objUser.TermsOfServiceText = item["content"].ToString(); + } + } + } + //else + //{ + // //6. + + + // // now return this list to the UI + //} + //} + //else + //{ + // // send message back to th UI that user is inactive + //} + } } else { + bool isCorrectLoginId = AIAHTML5.API.Models.Users.isCredentialCorrect(credentials, objUser, "loginId"); + //bool isCorrectPassword = AIAHTML5.API.Models.Users.isCredentialCorrect(credentials, userInfo, "password"); - dynamic authenticationRepsonse = AIAHTML5.API.Models.Users.GetUserDetailsForAuthenticatedUser(credentials); - if (Convert.ToString(authenticationRepsonse) != AIAConstants.USER_NOT_FOUND && Convert.ToString(authenticationRepsonse) != AIAConstants.ERROR_IN_FECTHING_DETAILS && Convert.ToString(authenticationRepsonse)!= AIAConstants.SQL_CONNECTION_ERROR) + if (!isCorrectLoginId) { - //string userDetails = Newtonsoft.Json.JsonConvert.SerializeObject(authenticationRepsonse); - return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(authenticationRepsonse) }; + objUser = null; } else { - return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(authenticationRepsonse) }; + objUser.IsCorrectPassword = false; + objUser.IncorrectLoginAttemptCount = AIAHTML5.API.Models.Users.checkNoOfWrongAttempts(objUser.Id) + 1; + //01. insert wrong attempt in dtabase + if (objUser.IncorrectLoginAttemptCount == 1) + { + int insertedCount = AIAHTML5.API.Models.Users.insertWrongAttemptofUser(objUser.Id); + } + else + { + int updateCount = AIAHTML5.API.Models.Users.saveWrongAttemptofUser(objUser.Id); + if (updateCount < 0) + { + //Put the log in log file + logger.Fatal("Unable to Update past wrong login attempts for userId= " + objUser.Id); + } + else + { + + //02. check no of wrong attempts + //userInfo.IncorrectLoginAttemptCount = AIAHTML5.API.Models.Users.checkNoOfWrongAttempts(userInfo.Id); + //if (userInfo.IncorrectLoginAttemptCount >= 5) + //{ + // userInfo.IsBlocked = true; + // // send block message + //} + //else + //{ + // // send message back to UI for login fail + //} + if (objUser.IncorrectLoginAttemptCount > 4) + { + objUser.IsBlocked = true; + objUser.LoginFailureCauseId = ErrorHelper.E_USER_ID_BLOCKED_24_HRS; + } + } + } + if (objUser.License != null && !string.IsNullOrEmpty(objUser.License.AccountNumber)) + { + int result = AIAHTML5.API.Models.Users.insertUserLoginLog(objUser.License.AccountNumber, objUser.LoginFailureCauseId, null, objUser.EditionId.ToString(), null); + if (result < 0) + logger.Fatal("Unable to insert wrong attempt detail in UserLoginLog table for accountNumber= " + objUser.License.AccountNumber); + } } } - } + + if(objUser!=null) + authenticationRepsonse = JsonConvert.SerializeObject(objUser); + else + authenticationRepsonse = AIAConstants.USER_NOT_FOUND; + + //if (Convert.ToString(authenticationRepsonse) != AIAConstants.USER_NOT_FOUND && Convert.ToString(authenticationRepsonse) != AIAConstants.ERROR_IN_FECTHING_DETAILS && Convert.ToString(authenticationRepsonse)!= AIAConstants.SQL_CONNECTION_ERROR) + //{ + // //string userDetails = Newtonsoft.Json.JsonConvert.SerializeObject(authenticationRepsonse); + // return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(authenticationRepsonse) }; + //} + //else + //{ + return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(authenticationRepsonse) }; + + //} + } + // PUT api/authenticate/5 public void Put(int id, [FromBody]string value) diff --git a/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs b/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs index f2d80a2..7560612 100644 --- a/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs +++ b/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs @@ -59,7 +59,7 @@ namespace AIAHTML5.API.Models return ds; } - protected ArrayList GetUserModules() + public ArrayList GetUserModules() { ArrayList arrUserModules = new ArrayList(); Hashtable userModuleHash = null; @@ -176,133 +176,10 @@ namespace AIAHTML5.API.Models { objUser = null; } - - if (objUser != null) - { - Hashtable licenseEditionHash = objModel.GetUserLicenseIdEditionIdByUserId(objUser.Id); - foreach (DictionaryEntry de in licenseEditionHash) - { - if (de.Key.ToString() == AIAConstants.LICENSE_KEY_ID) - objUser.LicenseId = Convert.ToInt32(de.Value); - if (de.Key.ToString() == AIAConstants.EDITION_KEY_ID) - objUser.EditionId = Convert.ToInt32(de.Value); - } - - if (objUser.LicenseId != 0) - { - objUser.License = objModel.GetLicenseDetailsByLicenseId(objUser.LicenseId); - objUser.LicenseSubscriptions = objModel.GetLicenseSubscriptionDetailsByLicenseId(objUser.LicenseId); - } - else - { - objUser.License = null; - } - - BlockedUser blockedUser = objModel.GetBlockedUserByUserId(objUser.Id); - - if (blockedUser != null) - { - DateTime LoginTime = (DateTime)blockedUser.LoginTime; - DateTime blockTime = LoginTime.AddDays(1); - var difference = DateTime.Compare(DateTime.Now, blockTime); - if (difference >= 0) - { - objUser.IsBlocked = false; - } - else - { - objUser.IsBlocked = true; - objUser.IncorrectLoginAttemptCount = objModel.GetIncorrectLoginAttempts(objUser.Id); - } - } - else - { - objUser.IsBlocked = false; - } - - if (!objUser.IsBlocked) - { - if (!string.Equals(objUser.Password, password)) - { - objUser.IsCorrectPassword = false; - objUser.IncorrectLoginAttemptCount = objModel.GetIncorrectLoginAttempts(objUser.Id) + 1; - - objUser.LoginFailureCauseId = ErrorHelper.E_PASSWORD_NOT_MATCH; - - if (objUser.IncorrectLoginAttemptCount == 1) - { - objModel.InsertIncorrectLoginAttempts(objUser.Id); - } - else - { - objModel.UpdateIncorrectLoginAttempts(objUser.Id); - - if (objUser.IncorrectLoginAttemptCount > 4) - { - objUser.IsBlocked = true; - objUser.LoginFailureCauseId = ErrorHelper.E_USER_ID_BLOCKED_24_HRS; - } - } - if (objUser.License != null && !string.IsNullOrEmpty(objUser.License.AccountNumber)) - { - objModel.InsertUserLoginLog(objUser.License.AccountNumber, objUser.LoginFailureCauseId, null, objUser.EditionId.ToString(), null); - } - } - else - { - if (objUser.UserType == User.SUPER_ADMIN || objUser.UserType == User.GENERAL_ADMIN) - { - objUser.IsCorrectPassword = true; - objUser.Modules = objModel.GetUserModules(); - - objModel.InsertLoginDetails(objUser.Id); - objModel.DeleteIncorrectLoginAttempts(objUser.Id); - } - else - { - objUser.IsCorrectPassword = true; - - if (objUser.License != null) - { - if (objUser.LicenseSubscriptions != null) - { - DateTime? subscriptionValidThrough = objUser.LicenseSubscriptions.SubscriptionValidThrough; - if (subscriptionValidThrough != null && subscriptionValidThrough.Value.Date >= DateTime.Now.Date) - { - ArrayList allModulesList = objModel.GetUserModules(); - ArrayList licensedModulesList = objModel.GetModuleStatusByLicenseId(objUser.LicenseId); - - ArrayList userModuleList = objModel.GetUserModulesList(allModulesList, licensedModulesList); - objUser.Modules = userModuleList; - - if (!objUser.License.IsTermAccepted) - { - ArrayList termsList = DBModel.GetTermsOfServiceText(); - foreach (Hashtable item in termsList) - { - objUser.TermsOfServiceTitle = item["title"].ToString(); - objUser.TermsOfServiceText = item["content"].ToString(); - } - } - objModel.InsertLoginDetails(objUser.Id); - objModel.DeleteIncorrectLoginAttempts(objUser.Id); - } - else - { - objUser.IsSubscriptionExpired = true; - objUser.SubscriptionExpirationDateString = objUser.LicenseSubscriptions.SubscriptionValidThrough.Value.Date.ToString("MM/dd/yyyy").ToString(); - } - } - } - } - } - } - } - return objUser; } - protected Hashtable GetUserLicenseIdEditionIdByUserId(int userId) + public Hashtable GetUserLicenseDetailByUserId(int userId) { Hashtable hash = new Hashtable(); @@ -313,7 +190,7 @@ namespace AIAHTML5.API.Models DataSet ds = new DataSet(); cmd.Connection = conn; - cmd.CommandText = "GetLicenseIdEditionIdByUserId"; + cmd.CommandText = "GetLicenseDetailByUserId"; cmd.CommandType = CommandType.StoredProcedure; param = new SqlParameter("@iUserId", userId); @@ -331,7 +208,7 @@ namespace AIAHTML5.API.Models return hash; } - protected ArrayList GetModuleStatusByLicenseId(int licenseId) + public ArrayList GetUserModulesByLicenseId(int licenseId) { ArrayList userModulelist = new ArrayList(); Hashtable modulesHash; @@ -343,7 +220,7 @@ namespace AIAHTML5.API.Models SqlParameter param; cmd.Connection = conn; - cmd.CommandText = "GetModuleStatusByLicenseId"; + cmd.CommandText = "GetUserModulesByLicenseId"; cmd.CommandType = CommandType.StoredProcedure; param = new SqlParameter("@iLicenseId", licenseId); @@ -358,16 +235,15 @@ namespace AIAHTML5.API.Models foreach (DataRow dr in dt.Rows) { modulesHash = new Hashtable(); - modulesHash.Add("Id", dr["Id"]); - modulesHash.Add("Title", dr["Title"]); - modulesHash.Add("Status", dr["Status"]); + modulesHash.Add("name", dr["Title"]); + modulesHash.Add("slug", dr["Slug"]); userModulelist.Add(modulesHash); } return userModulelist; } - protected ArrayList GetUserModulesList(ArrayList allModules, ArrayList modulesByLicense) + public ArrayList GetUserModulesList(ArrayList allModules, ArrayList modulesByLicense) { ArrayList userModules = new ArrayList(); Hashtable moduleHash; @@ -536,7 +412,7 @@ namespace AIAHTML5.API.Models return result; } - protected LicenseSubscriptionDetails GetLicenseSubscriptionDetailsByLicenseId(int licenseId) + public LicenseSubscriptionDetails GetLicenseSubscriptionDetailsByLicenseId(int licenseId) { ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); logger.Debug(" Inside GetLicenseSubscriptionDetailsByLicenseId for LicenseId = " + licenseId); @@ -627,7 +503,7 @@ namespace AIAHTML5.API.Models return lsd; } - protected License GetLicenseDetailsByLicenseId(int licenseId) + public License GetLicenseDetailsByLicenseId(int licenseId) { ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); logger.Debug(" inside GetLicenseDetailsByLicenseId for LicenseId = " + licenseId); @@ -740,7 +616,7 @@ namespace AIAHTML5.API.Models return result; } - protected static ArrayList GetTermsOfServiceText() + internal static ArrayList GetTermsOfServiceText() { ArrayList arrTermsOfService = new ArrayList(); Hashtable contentHash = null; @@ -759,7 +635,7 @@ namespace AIAHTML5.API.Models return arrTermsOfService; } - protected int InsertLoginDetails(int userId) + internal int InsertLoginDetails(int userId) { ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); logger.Debug(" inside InsertLoginDetails for UserId= " + userId); @@ -785,7 +661,7 @@ namespace AIAHTML5.API.Models return result; } - protected int InsertIncorrectLoginAttempts(int userId) + public int InsertIncorrectLoginAttempts(int userId) { ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); logger.Debug(" inside InsertIncorrectLoginAttempts for UserId= " + userId); @@ -810,7 +686,7 @@ namespace AIAHTML5.API.Models return result; } - protected int GetIncorrectLoginAttempts(int userId) + public int GetIncorrectLoginAttempts(int userId) { ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); logger.Debug(" inside GetIncorrectLoginAttempts for UserId = " + userId); @@ -844,7 +720,7 @@ namespace AIAHTML5.API.Models return count; } - protected int UpdateIncorrectLoginAttempts(int userId) + internal int UpdateIncorrectLoginAttempts(int userId) { ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); logger.Debug(" inside UpdateIncorrectLoginAttempts for UserId= " + userId); @@ -870,7 +746,7 @@ namespace AIAHTML5.API.Models return result; } - protected int DeleteIncorrectLoginAttempts(int userId) + public int DeleteIncorrectLoginAttempts(int userId) { ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); logger.Debug(" inside DeleteIncorrectLoginAttempts for UserId= " + userId); @@ -916,7 +792,7 @@ namespace AIAHTML5.API.Models return failureCauseList; } - protected int InsertUserLoginLog(string accountNumber, Int16 failureId, string referalUrl, string edition, string httpReferer) + internal int InsertUserLoginLog(string accountNumber, Int16 failureId, string referalUrl, string edition, string httpReferer) { ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); logger.Debug(" inside InsertUserLoginLog for AccountNumber= " + accountNumber); @@ -1068,5 +944,56 @@ namespace AIAHTML5.API.Models return result; } + + internal static bool ValidateUserAuthenticity(string username, string password) + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug(" Inside ValidateUserAuthenticity for Username = " + username + ", Password: " + password); + + User objUser = new User(); + DBModel objModel = new DBModel(); + + conn = new SqlConnection(dbConnectionString); + cmd = new SqlCommand(); + SqlDataAdapter da = new SqlDataAdapter(); + SqlParameter param; + DataSet ds = new DataSet(); + + cmd.Connection = conn; + cmd.CommandText = "GetUserDetailsByLoginId"; + cmd.CommandType = CommandType.StoredProcedure; + + param = new SqlParameter("@sLoginId", username); + param.Direction = ParameterDirection.Input; + param.DbType = DbType.String; + cmd.Parameters.Add(param); + + da.SelectCommand = cmd; + DataTable dt = new DataTable(); + da.Fill(dt); + + bool result = false; + + if (dt.Rows.Count > 0) + { + foreach (DataRow dr in dt.Rows) + { + foreach (DataColumn dc in dt.Columns) + { + if (dc.ColumnName == "LoginId") + objUser.LoginId = dr[dc].ToString(); + if (dc.ColumnName == "Password") + objUser.Password = dr[dc].ToString(); + } + } + + if ((string.Equals(username.ToUpper(), objUser.LoginId.ToUpper())) && (string.Equals(password, objUser.Password))) + result = true; + else + result = false; + } + + return result; + } } } \ No newline at end of file diff --git a/400-SOURCECODE/AIAHTML5.API/Models/Users.cs b/400-SOURCECODE/AIAHTML5.API/Models/Users.cs index f97c4b3..8031fde 100644 --- a/400-SOURCECODE/AIAHTML5.API/Models/Users.cs +++ b/400-SOURCECODE/AIAHTML5.API/Models/Users.cs @@ -23,26 +23,6 @@ namespace AIAHTML5.API.Models try { - //var client = new MongoClient(); - //var db = client.GetDatabase(Settings.Default.database); - - //var collection = db.GetCollection("Users"); - - //FilterDefinition[] filterCondition = { Builders.Filter.Eq("loginId", credentials["username"].ToString()), - // Builders.Filter.Eq("password", credentials["password"].ToString())}; - - //dynamic userDetails = collection.Find(Builders.Filter.And(filterCondition)).SingleOrDefault(); - - - //if (userDetails != null) - //{ - // logger.Debug("userDetails.loginId= " + userDetails.loginId); - // return userDetails; - //} - //else - //{ - // return AIAConstants.USER_NOT_FOUND; - //} User user = DBModel.GetUserDetailsByLoginIdAndPassword(credentials["username"].ToString(), credentials["password"].ToString()); //string userDetails = DBModel.GetUserDetailsByLoginId2(credentials["username"].ToString()); @@ -206,5 +186,213 @@ namespace AIAHTML5.API.Models return result; } + + internal static bool IsUserAuthenticated(Newtonsoft.Json.Linq.JObject credentials) + { + bool isAuthenticatedUser = DBModel.ValidateUserAuthenticity(credentials["username"].ToString(), credentials["password"].ToString()); + + return isAuthenticatedUser; + } + + internal static User getLoggedinUserDetail(Newtonsoft.Json.Linq.JObject credentials) + { + User user = DBModel.GetUserDetailsByLoginIdAndPassword(credentials["username"].ToString(), credentials["password"].ToString()); + + return user; + } + + internal static User getUserDetails(Newtonsoft.Json.Linq.JObject credentials) + { + User user = DBModel.GetUserDetailsByLoginIdAndPassword(credentials["username"].ToString(), credentials["password"].ToString()); + + return user; + } + + internal static int getLicenseIdForThisUser(int userId, string key) + { + ArrayList arrLicense = new ArrayList(); + DBModel objModel = new DBModel(); + int licenseId = 0 , editionId = 0, result = 0; + Hashtable licenseEditionHash = objModel.GetUserLicenseDetailByUserId(userId); + foreach (DictionaryEntry de in licenseEditionHash) + { + if (de.Key.ToString() == AIAConstants.LICENSE_KEY_ID) + licenseId = Convert.ToInt32(de.Value); + if (de.Key.ToString() == AIAConstants.EDITION_KEY_ID) + editionId = Convert.ToInt32(de.Value); + } + + if (string.Equals(key.ToUpper(), AIAConstants.KEY_LICENSE)) + result = licenseId; + if (string.Equals(key.ToUpper(), AIAConstants.KEY_EDITION)) + result = editionId; + return result; + } + + internal static int insertLoginDetails(int userId) + { + int result = 0; + DBModel objModel = new DBModel(); + + result = objModel.InsertLoginDetails(userId); + + return result; + } + + internal static bool isUSerActive(User user) + { + if (user.IsActive) + return true; + else + return false; + } + + internal static string SubscriptionExpirationDateString(int licenseId) + { + DBModel objModel = new DBModel(); + LicenseSubscriptionDetails licenseSubscription = objModel.GetLicenseSubscriptionDetailsByLicenseId(licenseId); + string subscritptionExpirationDateString = null; + + if (licenseSubscription != null) + { + DateTime? subscriptionValidThrough = licenseSubscription.SubscriptionValidThrough; + if (subscriptionValidThrough != null && subscriptionValidThrough.Value.Date >= DateTime.Now.Date) + { + subscritptionExpirationDateString = null; + } + else + { + subscritptionExpirationDateString = licenseSubscription.SubscriptionValidThrough.Value.Date.ToString("MM/dd/yyyy").ToString(); + } + } + return subscritptionExpirationDateString; + } + + internal static ArrayList getModuleListByLicenseId(int licenseId) + { + DBModel objModel = new DBModel(); + ArrayList licensedModulesList = objModel.GetUserModulesByLicenseId(licenseId); + + return licensedModulesList; + } + + internal static int deletePastWrongAttempts(int userId) + { + int result = 0; + DBModel objModel = new DBModel(); + + result = objModel.DeleteIncorrectLoginAttempts(userId); + + return result; + } + + internal static int insertWrongAttemptofUser(int userId) + { + int result = 0; + DBModel objModel = new DBModel(); + + result = objModel.InsertIncorrectLoginAttempts(userId); + + return result; + } + + internal static int checkNoOfWrongAttempts(int userId) + { + int result = 0; + DBModel objModel = new DBModel(); + + result = objModel.GetIncorrectLoginAttempts(userId); + + return result; + } + + internal static int saveWrongAttemptofUser(int userId) + { + int result = 0; + DBModel objModel = new DBModel(); + + result = objModel.UpdateIncorrectLoginAttempts(userId); + + return result; + } + + internal static bool isLicenseActive(int licenseId) + { + DBModel objModel = new DBModel(); + License userLicense = objModel.GetLicenseDetailsByLicenseId(licenseId); + + if (userLicense.IsActive) + return true; + else + return false; + } + + internal static License getLicenseDetails(int licenseId) + { + DBModel objModel = new DBModel(); + License userLicense = objModel.GetLicenseDetailsByLicenseId(licenseId); + + return userLicense; + } + + internal static LicenseSubscriptionDetails getLicenseSubscriptionDetails(int licenseId) + { + DBModel objModel = new DBModel(); + LicenseSubscriptionDetails userSubscriptionDetail = objModel.GetLicenseSubscriptionDetailsByLicenseId(licenseId); + + return userSubscriptionDetail; + } + + internal static bool isCredentialCorrect(Newtonsoft.Json.Linq.JObject credentials, User user, string key) + { + bool result = false; + if (user != null) + { + if (string.Equals(key.ToUpper(), AIAConstants.KEY_LOGINID)) + { + if (string.Equals(credentials["username"].ToString().ToUpper(), user.LoginId.ToUpper())) + result = true; + else + result = false; + } + + if (string.Equals(key.ToUpper(), AIAConstants.KEY_PASSWORD)) + { + if (string.Equals(credentials["password"].ToString(), user.Password)) + result = true; + else + result = false; + } + } + + return result; + } + + internal static int insertUserLoginLog(string accountNumber, Int16 failureId, string referalUrl, string edition, string httpReferer) + { + int result = 0; + DBModel objModel = new DBModel(); + result = objModel.InsertUserLoginLog(accountNumber, failureId, null, edition, null); + + return result; + } + + + internal static ArrayList getTermsOfServiceText() + { + ArrayList arrTermsOfService = new ArrayList(); + DBModel objModel = new DBModel(); + arrTermsOfService = DBModel.GetTermsOfServiceText(); + + return arrTermsOfService; + } + + internal static ArrayList getAllModulesList() + { + DBModel objModel = new DBModel(); + ArrayList modulesList = objModel.GetUserModules(); + + return modulesList; + } } } \ No newline at end of file diff --git a/400-SOURCECODE/AIAHTML5.Web/app/controllers/HomeController.js b/400-SOURCECODE/AIAHTML5.Web/app/controllers/HomeController.js index 2ce99b2..5f74eac 100644 --- a/400-SOURCECODE/AIAHTML5.Web/app/controllers/HomeController.js +++ b/400-SOURCECODE/AIAHTML5.Web/app/controllers/HomeController.js @@ -342,11 +342,29 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic try { var userInfo = JSON.parse(currentUserDetails); - if (userInfo.loginId != undefined || userInfo.loginId != "" || userInfo.loginId != null) { - $rootScope.isVisibleLogin = false; - $rootScope.userData = userInfo; - $rootScope.userModules = userInfo.Modules; - if ($rootScope.refreshcheck == null) { + if (userInfo.LoginId != undefined || userInfo.LoginId != "" || userInfo.LoginId != null) { + if (userInfo.License.IsTermAccepted) { + $rootScope.userData = userInfo; + $rootScope.userModules = userInfo.Modules; + $rootScope.isVisibleLogin = false; + //$rootScope.haveRoleAdmin = true; + $rootScope.licenseeAccountNumber = userInfo.License.AccountNumber; + + if ($rootScope.refreshcheck == null) { + $location.path('/'); + } + + } + else { + if ($('#dvTerms').length > 0) { + $('#dvTerms').html(userInfo.TermsOfServiceText); + } + $rootScope.isVisibleLogin = true; + $('#dvTermCondition').fadeIn(); + $rootScope.userData = userInfo; + $rootScope.userModules = userInfo.Modules; + //$rootScope.haveRoleAdmin = true; + $rootScope.licenseeAccountNumber = userInfo.License.AccountNumber; $location.path('/'); } } @@ -521,24 +539,26 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic userEmailId = split[1]; } - //document.location = '/'; - AuthenticationService.UnblockUser(userEmailId) .then( function (result) { if (result == LoginMessageConstants.USER_UNBLOCK_SUCCESS) { $rootScope.errorMessage = LoginMessageConstants.USER_UNBLOCK_SUCCESS_MESSAGE; $("#messageModal").modal('show'); + $rootScope.isVisibleLogin = true; //$('#messageModal.btn-primary').click(function () { - // document.location = '/'; + //$location.path('/'); //}); + document.location.href = "/" } else { $rootScope.errorMessage = LoginMessageConstants.USER_ALREADY_UNBLOCKED; - //$("#messageModal").modal('show'); + $("#messageModal").modal('show'); + $rootScope.isVisibleLogin = true; //$('#messageModal.btn-primary').click(function () { - // document.location = '/'; + //$location.path('/'); //}); + document.location.href = "/" } }, function (error) { @@ -3775,7 +3795,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic if ((localStorage.getItem('loggedInUserDetails') == null) && ($rootScope.isVisibleLogin == false)) { - if ($location.url().indexOf('?') == -1) + if ($location.url().indexOf('?em') == -1 && $location.url().indexOf('?unb') == -1) $rootScope.LogoutUser(); -- libgit2 0.21.4