From ce80c984205a77b7c291008e4fc6a7b8f31e0b49 Mon Sep 17 00:00:00 2001 From: Utkarsh Singh Date: Thu, 7 Sep 2017 19:19:45 +0530 Subject: [PATCH] Committing updated code with modified stored procedure for Blocked user info --- 150-DOCUMENTATION/002-DBScripts/GetBlockedUserByUserId.sql | 37 +++++++++++++++++++++++++++++++++++++ 400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs | 80 ++++++++++++++++++++++---------------------------------------------------------- 2 files changed, 59 insertions(+), 58 deletions(-) create mode 100644 150-DOCUMENTATION/002-DBScripts/GetBlockedUserByUserId.sql diff --git a/150-DOCUMENTATION/002-DBScripts/GetBlockedUserByUserId.sql b/150-DOCUMENTATION/002-DBScripts/GetBlockedUserByUserId.sql new file mode 100644 index 0000000..8161ea4 --- /dev/null +++ b/150-DOCUMENTATION/002-DBScripts/GetBlockedUserByUserId.sql @@ -0,0 +1,37 @@ +-- ============================================= +-- Author: <> +-- Create date: <> +-- Description: +-- ============================================= +CREATE PROCEDURE GetBlockedUserByUserId + -- Add the parameters for the stored procedure here + @userId int +AS +BEGIN + -- returns the metadata + IF 1=0 BEGIN + SET FMTONLY OFF + END + SELECT DISTINCT + AIAUser.Id, + AIAUser.FirstName, + AIAUser.LastName, + AIAUser.LoginId, + AIAUser.Password, + AIAUser.EmailId, + ISNULL(License.AccountNumber,'') AccountNumber, + IncorrectLoginAttempts.LoginTime + FROM + IncorrectLoginAttempts + INNER JOIN AIAUser ON IncorrectLoginAttempts.UserId = AIAUser.Id + INNER JOIN UserType ON AIAUser.UserTypeId = UserType.Id + LEFT JOIN AIAUserToLicenseEdition ON AIAUser.Id = AIAUserToLicenseEdition.UserId + LEFT JOIN LicenseToEdition ON AIAUserToLicenseEdition.LicenseEditionId = LicenseToEdition.Id + LEFT JOIN License ON LicenseToEdition.LicenseId = License.Id + WHERE + IncorrectLoginAttempts.CntIncorrectLogins >= 5 + AND AIAUser.Id = @userId + --AND UserType.Priority >= (SELECT UserType.Priority FROM UserType WHERE UserType.Id=@iUserTypeId) + --AND ((@iLicenseId =0) OR (License.Id = @iLicenseId)) + --AND License.IsActive = 1 +END \ No newline at end of file diff --git a/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs b/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs index 1fe62b8..0929e75 100644 --- a/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs +++ b/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs @@ -198,62 +198,26 @@ namespace AIAHTML5.API.Models objUser.License = null; } - if (objUser.UserType == User.SUPER_ADMIN || objUser.UserType == User.GENERAL_ADMIN) + BlockedUser blockedUser = objModel.GetBlockedUserByUserId(objUser.Id); + + if (blockedUser != null) { - ArrayList blockedAdminUsersList = objModel.GetBlockedAdminUsers(objUser.UserTypeId); - if (blockedAdminUsersList.Count > 0) + DateTime LoginTime = (DateTime)blockedUser.LoginTime; + DateTime blockTime = LoginTime.AddDays(1); + var difference = DateTime.Compare(DateTime.Now, blockTime); + if (difference >= 0) { - foreach (BlockedUser bUser in blockedAdminUsersList) - { - DateTime LoginTime = (DateTime)bUser.LoginTime; - DateTime blockTime = LoginTime.AddDays(1); - var difference = DateTime.Compare(DateTime.Now, blockTime); - if (bUser.Id == objUser.Id) - { - if (difference >= 0) - { - objUser.IsBlocked = false; - } - else - { - objUser.IsBlocked = true; - } - } - } + objUser.IsBlocked = false; } else { - objUser.IsBlocked = false; + objUser.IsBlocked = true; } } else { - ArrayList blockedUsersList = objModel.GetBlockedUsers(objUser.UserTypeId, objUser.License.Id); - if (blockedUsersList.Count > 0) - { - foreach (BlockedUser bUser in blockedUsersList) - { - DateTime LoginTime = (DateTime)bUser.LoginTime; - DateTime blockTime = LoginTime.AddDays(1); - var difference = DateTime.Compare(DateTime.Now, blockTime); - if (bUser.Id == objUser.Id) - { - if (difference >= 0) - { - objUser.IsBlocked = false; - } - else - { - objUser.IsBlocked = true; - } - } - } - } - else - { - objUser.IsBlocked = false; - } - } + objUser.IsBlocked = false; + } if (!objUser.IsBlocked) { @@ -270,8 +234,7 @@ namespace AIAHTML5.API.Models } else { - if (!objUser.IsBlocked) - objModel.UpdateIncorrectLoginAttempts(objUser.Id); + objModel.UpdateIncorrectLoginAttempts(objUser.Id); if (objUser.IncorrectLoginAttemptCount > 4) { @@ -997,12 +960,11 @@ namespace AIAHTML5.API.Models return result; } - protected ArrayList GetBlockedUsers(int userTypeId, int licenseId) + protected BlockedUser GetBlockedUserByUserId(int userId) { ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); - logger.Debug(" inside GetBlockedUsers for LicenseId= " + licenseId + " & UserTypeId= " + userTypeId); + logger.Debug(" inside GetBlockedUserByUserId for UserId= " + userId); - ArrayList blockedUsersList = new ArrayList(); BlockedUser blockedUser = new BlockedUser(); DataTable dt = null; try @@ -1010,10 +972,9 @@ namespace AIAHTML5.API.Models conn = new SqlConnection(dbConnectionString); cmd = new SqlCommand(); cmd.Connection = conn; - cmd.CommandText = "GetBlockedUserByAccNoAndType"; + cmd.CommandText = "GetBlockedUserByUserId"; cmd.CommandType = CommandType.StoredProcedure; - cmd.Parameters.AddWithValue("@iUserTypeId", userTypeId); - cmd.Parameters.AddWithValue("@iLicenseId", licenseId); + cmd.Parameters.AddWithValue("@userId", userId); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; dt = new DataTable(); @@ -1042,15 +1003,18 @@ namespace AIAHTML5.API.Models if (dc.ColumnName == "LoginTime") blockedUser.LoginTime = Convert.ToDateTime(dr[dc]); } - blockedUsersList.Add(blockedUser); } } + else + { + blockedUser = null; + } } catch (SqlException ex) { - logger.Fatal("Exception in GetBlockedUsers for LicenseId= " + licenseId + " & UserTypeId= " + userTypeId + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace); + logger.Fatal("Exception in GetBlockedUserByUserId for UserId= " + userId + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace); } - return blockedUsersList; + return blockedUser; } protected ArrayList GetBlockedAdminUsers(int userTypeId) -- libgit2 0.21.4