Commit ce80c984205a77b7c291008e4fc6a7b8f31e0b49

Authored by Utkarsh Singh
1 parent d27a8c82

Committing updated code with modified stored procedure for Blocked user info

150-DOCUMENTATION/002-DBScripts/GetBlockedUserByUserId.sql 0 → 100644
  1 +-- =============================================
  2 +-- Author: <>
  3 +-- Create date: <>
  4 +-- Description: <Description,,>
  5 +-- =============================================
  6 +CREATE PROCEDURE GetBlockedUserByUserId
  7 + -- Add the parameters for the stored procedure here
  8 + @userId int
  9 +AS
  10 +BEGIN
  11 + -- returns the metadata
  12 + IF 1=0 BEGIN
  13 + SET FMTONLY OFF
  14 + END
  15 + SELECT DISTINCT
  16 + AIAUser.Id,
  17 + AIAUser.FirstName,
  18 + AIAUser.LastName,
  19 + AIAUser.LoginId,
  20 + AIAUser.Password,
  21 + AIAUser.EmailId,
  22 + ISNULL(License.AccountNumber,'') AccountNumber,
  23 + IncorrectLoginAttempts.LoginTime
  24 + FROM
  25 + IncorrectLoginAttempts
  26 + INNER JOIN AIAUser ON IncorrectLoginAttempts.UserId = AIAUser.Id
  27 + INNER JOIN UserType ON AIAUser.UserTypeId = UserType.Id
  28 + LEFT JOIN AIAUserToLicenseEdition ON AIAUser.Id = AIAUserToLicenseEdition.UserId
  29 + LEFT JOIN LicenseToEdition ON AIAUserToLicenseEdition.LicenseEditionId = LicenseToEdition.Id
  30 + LEFT JOIN License ON LicenseToEdition.LicenseId = License.Id
  31 + WHERE
  32 + IncorrectLoginAttempts.CntIncorrectLogins >= 5
  33 + AND AIAUser.Id = @userId
  34 + --AND UserType.Priority >= (SELECT UserType.Priority FROM UserType WHERE UserType.Id=@iUserTypeId)
  35 + --AND ((@iLicenseId =0) OR (License.Id = @iLicenseId))
  36 + --AND License.IsActive = 1
  37 +END
0 38 \ No newline at end of file
... ...
400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs
... ... @@ -198,62 +198,26 @@ namespace AIAHTML5.API.Models
198 198 objUser.License = null;
199 199 }
200 200  
201   - if (objUser.UserType == User.SUPER_ADMIN || objUser.UserType == User.GENERAL_ADMIN)
  201 + BlockedUser blockedUser = objModel.GetBlockedUserByUserId(objUser.Id);
  202 +
  203 + if (blockedUser != null)
202 204 {
203   - ArrayList blockedAdminUsersList = objModel.GetBlockedAdminUsers(objUser.UserTypeId);
204   - if (blockedAdminUsersList.Count > 0)
  205 + DateTime LoginTime = (DateTime)blockedUser.LoginTime;
  206 + DateTime blockTime = LoginTime.AddDays(1);
  207 + var difference = DateTime.Compare(DateTime.Now, blockTime);
  208 + if (difference >= 0)
205 209 {
206   - foreach (BlockedUser bUser in blockedAdminUsersList)
207   - {
208   - DateTime LoginTime = (DateTime)bUser.LoginTime;
209   - DateTime blockTime = LoginTime.AddDays(1);
210   - var difference = DateTime.Compare(DateTime.Now, blockTime);
211   - if (bUser.Id == objUser.Id)
212   - {
213   - if (difference >= 0)
214   - {
215   - objUser.IsBlocked = false;
216   - }
217   - else
218   - {
219   - objUser.IsBlocked = true;
220   - }
221   - }
222   - }
  210 + objUser.IsBlocked = false;
223 211 }
224 212 else
225 213 {
226   - objUser.IsBlocked = false;
  214 + objUser.IsBlocked = true;
227 215 }
228 216 }
229 217 else
230 218 {
231   - ArrayList blockedUsersList = objModel.GetBlockedUsers(objUser.UserTypeId, objUser.License.Id);
232   - if (blockedUsersList.Count > 0)
233   - {
234   - foreach (BlockedUser bUser in blockedUsersList)
235   - {
236   - DateTime LoginTime = (DateTime)bUser.LoginTime;
237   - DateTime blockTime = LoginTime.AddDays(1);
238   - var difference = DateTime.Compare(DateTime.Now, blockTime);
239   - if (bUser.Id == objUser.Id)
240   - {
241   - if (difference >= 0)
242   - {
243   - objUser.IsBlocked = false;
244   - }
245   - else
246   - {
247   - objUser.IsBlocked = true;
248   - }
249   - }
250   - }
251   - }
252   - else
253   - {
254   - objUser.IsBlocked = false;
255   - }
256   - }
  219 + objUser.IsBlocked = false;
  220 + }
257 221  
258 222 if (!objUser.IsBlocked)
259 223 {
... ... @@ -270,8 +234,7 @@ namespace AIAHTML5.API.Models
270 234 }
271 235 else
272 236 {
273   - if (!objUser.IsBlocked)
274   - objModel.UpdateIncorrectLoginAttempts(objUser.Id);
  237 + objModel.UpdateIncorrectLoginAttempts(objUser.Id);
275 238  
276 239 if (objUser.IncorrectLoginAttemptCount > 4)
277 240 {
... ... @@ -997,12 +960,11 @@ namespace AIAHTML5.API.Models
997 960 return result;
998 961 }
999 962  
1000   - protected ArrayList GetBlockedUsers(int userTypeId, int licenseId)
  963 + protected BlockedUser GetBlockedUserByUserId(int userId)
1001 964 {
1002 965 ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
1003   - logger.Debug(" inside GetBlockedUsers for LicenseId= " + licenseId + " & UserTypeId= " + userTypeId);
  966 + logger.Debug(" inside GetBlockedUserByUserId for UserId= " + userId);
1004 967  
1005   - ArrayList blockedUsersList = new ArrayList();
1006 968 BlockedUser blockedUser = new BlockedUser();
1007 969 DataTable dt = null;
1008 970 try
... ... @@ -1010,10 +972,9 @@ namespace AIAHTML5.API.Models
1010 972 conn = new SqlConnection(dbConnectionString);
1011 973 cmd = new SqlCommand();
1012 974 cmd.Connection = conn;
1013   - cmd.CommandText = "GetBlockedUserByAccNoAndType";
  975 + cmd.CommandText = "GetBlockedUserByUserId";
1014 976 cmd.CommandType = CommandType.StoredProcedure;
1015   - cmd.Parameters.AddWithValue("@iUserTypeId", userTypeId);
1016   - cmd.Parameters.AddWithValue("@iLicenseId", licenseId);
  977 + cmd.Parameters.AddWithValue("@userId", userId);
1017 978 SqlDataAdapter da = new SqlDataAdapter();
1018 979 da.SelectCommand = cmd;
1019 980 dt = new DataTable();
... ... @@ -1042,15 +1003,18 @@ namespace AIAHTML5.API.Models
1042 1003 if (dc.ColumnName == "LoginTime")
1043 1004 blockedUser.LoginTime = Convert.ToDateTime(dr[dc]);
1044 1005 }
1045   - blockedUsersList.Add(blockedUser);
1046 1006 }
1047 1007 }
  1008 + else
  1009 + {
  1010 + blockedUser = null;
  1011 + }
1048 1012 }
1049 1013 catch (SqlException ex)
1050 1014 {
1051   - logger.Fatal("Exception in GetBlockedUsers for LicenseId= " + licenseId + " & UserTypeId= " + userTypeId + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace);
  1015 + logger.Fatal("Exception in GetBlockedUserByUserId for UserId= " + userId + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace);
1052 1016 }
1053   - return blockedUsersList;
  1017 + return blockedUser;
1054 1018 }
1055 1019  
1056 1020 protected ArrayList GetBlockedAdminUsers(int userTypeId)
... ...