Commit 9801aa67feb6260f66f7c46f3156d05648834f64

Authored by Utkarsh Singh
1 parent 0a3aabc0

Committing restructured code files

400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs
... ... @@ -38,146 +38,285 @@ namespace AIAHTML5.API.Controllers
38 38 //01. check user is authenticated or not by login credential macth
39 39 //bool isUserAuthenticated = AIAHTML5.API.Models.Users.IsUserAuthenticated(credentials);
40 40  
41   - //Above code commented to reduce dbhitting for same result set
42   -
  41 + //Above code commented to reduce db hitting for same result set
  42 + // get user details based on credentials provided
43 43 User userInfo = AIAHTML5.API.Models.Users.getUserDetails(credentials);
44   - //check is user authenticated
45   - bool isUserAuthenticated = AIAHTML5.API.Models.Users.IsUserAuthenticated(credentials, userInfo);
46   -
47 44  
48   - if (isUserAuthenticated)
  45 + if (userInfo != null)
49 46 {
  47 + //check is user authenticated
  48 + bool isUserAuthenticated = AIAHTML5.API.Models.Users.IsUserAuthenticated(credentials, userInfo);
50 49  
51   - //01. Get User details
52   - //userInfo = AIAHTML5.API.Models.Users.getUserDetails(credentials);
  50 + // check if user is blocked
  51 + DateTime blockTime;
  52 + bool isUserBlocked = AIAHTML5.API.Models.Users.isUserBlocked(userInfo.Id, out blockTime);
53 53  
54   - //02. assigning isCorrectPassword to true 'required for internal processing'
55   - userInfo.IsCorrectPassword = true;
  54 + if (isUserAuthenticated && !isUserBlocked)
  55 + {
  56 + //01. Get User details
  57 + //userInfo = AIAHTML5.API.Models.Users.getUserDetails(credentials);
56 58  
57   - //03.insert Log login details
58   - // Below statement executing irrespective of the fact user license inactive
59   - //AIAHTML5.API.Models.Users.insertLoginDetails(userInfo.Id);
  59 + //02. assigning isCorrectPassword to true 'required for internal processing'
  60 + userInfo.IsCorrectPassword = true;
60 61  
61   - //04.delete past wrong login attempts of user
62   - int wrongAttemptDeteledCount = AIAHTML5.API.Models.Users.deletePastWrongAttempts(userInfo.Id);
63   - if (wrongAttemptDeteledCount <= 0)
64   - {
65   - logger.Fatal("Unable to delete past wrong login attempts for userId= " + userInfo.Id);
66   - }
  62 + //04.delete past wrong login attempts of user
  63 + int wrongAttemptDeteledCount = AIAHTML5.API.Models.Users.deletePastWrongAttempts(userInfo.Id);
  64 + if (wrongAttemptDeteledCount < 0)
  65 + {
  66 + logger.Fatal("Unable to delete past wrong login attempts for userId= " + userInfo.Id);
  67 + }
67 68  
68   - //05. Now get the module list- for ADMIN (superadmin/ general admin) by default all module loads
69   - if (userInfo.UserType == AIAHTML5.API.Models.User.SUPER_ADMIN || userInfo.UserType == AIAHTML5.API.Models.User.GENERAL_ADMIN)
70   - {
71   - userInfo.Modules = AIAHTML5.API.Models.Users.getAllModulesList();
  69 + //05. Now get the module list- for ADMIN (superadmin/ general admin) by default all module loads
  70 + if (userInfo.UserType == AIAHTML5.API.Models.User.SUPER_ADMIN || userInfo.UserType == AIAHTML5.API.Models.User.GENERAL_ADMIN)
  71 + {
  72 + userInfo.Modules = AIAHTML5.API.Models.Users.getAllModulesList();
72 73  
73   - //Insert user login detail
74   - AIAHTML5.API.Models.Users.insertLoginDetails(userInfo.Id);
75   - }
76   - else
77   - {
78   - //CORRECT CODE
79   - //05.1 For normal user need to get the license details, get the license id for aUTHENTICATED USER
80   - int licenseId, editionId;
81   - AIAHTML5.API.Models.Users.getLicenseIdForThisUser(userInfo.Id, out licenseId, out editionId);
  74 + //Insert user login detail
  75 + AIAHTML5.API.Models.Users.insertLoginDetails(userInfo.Id);
  76 + }
  77 + else
  78 + {
  79 + //05.1 For normal user need to get the license details, get the license id for authenticated user
  80 + int licenseId, editionId;
  81 + AIAHTML5.API.Models.Users.getLicenseIdForThisUser(userInfo.Id, out licenseId, out editionId);
82 82  
83   - userInfo.LicenseId = licenseId;
84   - userInfo.EditionId = editionId;
  83 + userInfo.LicenseId = licenseId;
  84 + userInfo.EditionId = editionId;
85 85  
86   - //05.2 Check user is active or not
87   -
  86 + //05.2 Check user is active or not
88 87  
89   - //05.3 get license/ licenseSubscription details
90   - userInfo.LicenseInfo = AIAHTML5.API.Models.Users.getLicenseDetails(userInfo.LicenseId);
91 88  
92   - //05.4
93   - userInfo.LicenseSubscriptions = AIAHTML5.API.Models.Users.getLicenseSubscriptionDetails(userInfo.LicenseId);
  89 + //05.3 get license details
  90 + userInfo.LicenseInfo = AIAHTML5.API.Models.Users.getLicenseDetails(userInfo.LicenseId);
94 91  
95   - //05.5 check the License expiration irespective of either user is active or not because on AIA
96   - //we shows the License expiration message for inactive users too
97   - string expirationDate = null;
  92 + //05.4 get licenseSubscription details
  93 + userInfo.LicenseSubscriptions = AIAHTML5.API.Models.Users.getLicenseSubscriptionDetails(userInfo.LicenseId);
98 94  
99   - bool isLicenseExpired = AIAHTML5.API.Models.Users.checkIfLicenseExpired(userInfo.LicenseSubscriptions, out expirationDate);
  95 + //05.5 check the License expiration irespective of either user is active or not because on AIA
  96 + //we shows the License expiration message for inactive users too
  97 + string expirationDate = null;
100 98  
101   - // send message to the UI for license expiration
102   - //05.6 Check for subscription Expiration [Promoted for case if license inactive along with subscription expired]
103   - if (isLicenseExpired)
104   - {
105   - userInfo.IsSubscriptionExpired = isLicenseExpired;
106   - userInfo.SubscriptionExpirationDate = expirationDate;
107   - }
108   - else
109   - {
110   - //05.6.1
111   - if (userInfo.LicenseInfo.IsActive)
  99 + bool isLicenseExpired = AIAHTML5.API.Models.Users.checkIfLicenseExpired(userInfo.LicenseSubscriptions, out expirationDate);
  100 +
  101 + // send message to the UI for license expiration
  102 + //05.6 Check for subscription Expiration [Promoted for case if license inactive along with subscription expired]
  103 + if (isLicenseExpired)
  104 + {
  105 + userInfo.IsSubscriptionExpired = isLicenseExpired;
  106 + userInfo.SubscriptionExpirationDate = expirationDate;
  107 + }
  108 + else
112 109 {
113   - if (!userInfo.LicenseInfo.IsTermAccepted)
  110 + //05.6.1
  111 + if (userInfo.LicenseInfo.IsActive)
114 112 {
115   - ArrayList termsList = AIAHTML5.API.Models.Users.getTermsOfServiceText();
116   - foreach (Hashtable item in termsList)
  113 + if (!userInfo.LicenseInfo.IsTermAccepted)
  114 + {
  115 + ArrayList termsList = AIAHTML5.API.Models.Users.getTermsOfServiceText();
  116 + foreach (Hashtable item in termsList)
  117 + {
  118 + userInfo.TermsOfServiceTitle = item["title"].ToString();
  119 + userInfo.TermsOfServiceText = item["content"].ToString();
  120 + }
  121 + }
  122 + else
117 123 {
118   - userInfo.TermsOfServiceTitle = item["title"].ToString();
119   - userInfo.TermsOfServiceText = item["content"].ToString();
  124 + userInfo.Modules = AIAHTML5.API.Models.Users.getModuleListByLicenseId(userInfo.LicenseId);
  125 +
  126 + //Insert user login detail
  127 + AIAHTML5.API.Models.Users.insertLoginDetails(userInfo.Id);
120 128 }
121 129 }
122 130 else
123 131 {
124   - userInfo.Modules = AIAHTML5.API.Models.Users.getModuleListByLicenseId(userInfo.LicenseId);
  132 + //05.6.1.1
  133 + // return message of license inactive
  134 + // property value assigned. Separate return statement not required
125 135  
126   - //Insert user login detail
127   - AIAHTML5.API.Models.Users.insertLoginDetails(userInfo.Id);
128 136 }
129   - }
130   - else
131   - {
132   - //05.6.1.1
133   - // return message of license inactive
134   - // property value assigned. Separate return statement not required
135 137  
136 138 }
137   -
138 139 }
139   - }
140 140  
141   - authenticationRepsonse = JsonConvert.SerializeObject(userInfo);
142   - }
143   - else
144   - {
145   - bool isCorrectLoginId, isCorrectPassword;
146   - AIAHTML5.API.Models.Users.isCredentialCorrect(credentials, out isCorrectLoginId, out isCorrectPassword);
147   -
148   - if (!isCorrectLoginId)
149   - {
150   - // send message back to th UI that login id is incorrect
151   - authenticationRepsonse = AIAConstants.USER_NOT_FOUND;
  141 + authenticationRepsonse = JsonConvert.SerializeObject(userInfo);
152 142 }
153 143 else
154 144 {
155   - //getting userDetails
156   - userInfo = AIAHTML5.API.Models.Users.getUserDetails(credentials);
  145 + //compare block time of user with current time if user is blocked
  146 + DateTime blockDuration = blockTime.AddDays(1);
  147 + var difference = DateTime.Compare(DateTime.Now, blockDuration);
157 148  
158   - if (!isCorrectPassword)
  149 + //check if credentials are valid credentials
  150 + bool isCorrectLoginId, isCorrectPassword;
  151 + AIAHTML5.API.Models.Users.isCredentialCorrect(credentials, out isCorrectLoginId, out isCorrectPassword);
  152 +
  153 + if (isUserBlocked)
159 154 {
160   - // send message back to th UI that password is incorrect
161   - userInfo.IsCorrectPassword = false;
  155 + if (difference >= 0)
  156 + {
  157 + if (isCorrectPassword)
  158 + {
  159 + userInfo.IsBlocked = false;
  160 + userInfo.IsCorrectPassword = true;
162 161  
163   - //get wrong attempt count of user
164   - userInfo.IncorrectLoginAttemptCount = AIAHTML5.API.Models.Users.checkNoOfWrongAttempts(userInfo.Id) +1;
165   - userInfo.LoginFailureCauseId = ErrorHelper.E_PASSWORD_NOT_MATCH;
  162 + int wrongAttemptDeteledCount = AIAHTML5.API.Models.Users.deletePastWrongAttempts(userInfo.Id);
  163 + if (wrongAttemptDeteledCount < 0)
  164 + {
  165 + logger.Fatal("Unable to delete past wrong login attempts for userId= " + userInfo.Id);
  166 + }
166 167  
167   - //01. insert wrong attempt in dtabase
168   - int updateCount = AIAHTML5.API.Models.Users.saveWrongAttemptofUser(userInfo.Id);
  168 + //05. Now get the module list- for ADMIN (superadmin/ general admin) by default all module loads
  169 +
  170 + if (userInfo.UserType == AIAHTML5.API.Models.User.SUPER_ADMIN || userInfo.UserType == AIAHTML5.API.Models.User.GENERAL_ADMIN)
  171 + {
  172 + userInfo.Modules = AIAHTML5.API.Models.Users.getAllModulesList();
  173 +
  174 + //Insert user login detail
  175 + AIAHTML5.API.Models.Users.insertLoginDetails(userInfo.Id);
  176 + }
  177 + else
  178 + {
  179 + //05.1 For normal user need to get the license details, get the license id for aUTHENTICATED USER
  180 + int licenseId, editionId;
  181 + AIAHTML5.API.Models.Users.getLicenseIdForThisUser(userInfo.Id, out licenseId, out editionId);
  182 +
  183 + userInfo.LicenseId = licenseId;
  184 + userInfo.EditionId = editionId;
  185 +
  186 + //05.2 Check user is active or not
  187 +
  188 +
  189 + //05.3 get license/ licenseSubscription details
  190 + userInfo.LicenseInfo = AIAHTML5.API.Models.Users.getLicenseDetails(userInfo.LicenseId);
  191 +
  192 + //05.4
  193 + userInfo.LicenseSubscriptions = AIAHTML5.API.Models.Users.getLicenseSubscriptionDetails(userInfo.LicenseId);
  194 +
  195 + //05.5 check the License expiration irespective of either user is active or not because on AIA
  196 + //we shows the License expiration message for inactive users too
  197 + string expirationDate = null;
  198 +
  199 + bool isLicenseExpired = AIAHTML5.API.Models.Users.checkIfLicenseExpired(userInfo.LicenseSubscriptions, out expirationDate);
  200 +
  201 + // send message to the UI for license expiration
  202 + //05.6 Check for subscription Expiration [Promoted for case if license inactive along with subscription expired]
  203 + if (isLicenseExpired)
  204 + {
  205 + userInfo.IsSubscriptionExpired = isLicenseExpired;
  206 + userInfo.SubscriptionExpirationDate = expirationDate;
  207 + }
  208 + else
  209 + {
  210 + //05.6.1
  211 + if (userInfo.LicenseInfo.IsActive)
  212 + {
  213 + if (!userInfo.LicenseInfo.IsTermAccepted)
  214 + {
  215 + ArrayList termsList = AIAHTML5.API.Models.Users.getTermsOfServiceText();
  216 + foreach (Hashtable item in termsList)
  217 + {
  218 + userInfo.TermsOfServiceTitle = item["title"].ToString();
  219 + userInfo.TermsOfServiceText = item["content"].ToString();
  220 + }
  221 + }
  222 + else
  223 + {
  224 + userInfo.Modules = AIAHTML5.API.Models.Users.getModuleListByLicenseId(userInfo.LicenseId);
  225 +
  226 + //Insert user login detail
  227 + AIAHTML5.API.Models.Users.insertLoginDetails(userInfo.Id);
  228 + }
  229 + }
  230 + else
  231 + {
  232 + //05.6.1.1
  233 + // return message of license inactive
  234 + // property value assigned. Separate return statement not required
  235 +
  236 + }
  237 +
  238 + }
  239 + }
  240 + }
  241 + else
  242 + {
  243 + int wrongAttemptDeteledCount = AIAHTML5.API.Models.Users.deletePastWrongAttempts(userInfo.Id);
  244 + if (wrongAttemptDeteledCount < 0)
  245 + {
  246 + logger.Fatal("Unable to delete past wrong login attempts for userId= " + userInfo.Id);
  247 + }
  248 +
  249 + // send message back to th UI that password is incorrect
  250 + userInfo.IsCorrectPassword = false;
  251 +
  252 + //get wrong attempt count of user
  253 + userInfo.IncorrectLoginAttemptCount = AIAHTML5.API.Models.Users.checkNoOfWrongAttempts(userInfo.Id) + 1;
  254 + userInfo.LoginFailureCauseId = ErrorHelper.E_PASSWORD_NOT_MATCH;
  255 +
  256 + //01. insert wrong attempt in dtabase
  257 + int updateCount = AIAHTML5.API.Models.Users.saveWrongAttemptofUser(userInfo.Id);
  258 +
  259 + if (updateCount < 0)
  260 + {
  261 + //Put the log in log file
  262 + logger.Fatal("Unable to Update past wrong login attempts for userId= " + userInfo.Id);
  263 + }
  264 + else
  265 + {
  266 + if (userInfo.IncorrectLoginAttemptCount > 4)
  267 + {
  268 + userInfo.IsBlocked = true;
  269 + userInfo.LoginFailureCauseId = ErrorHelper.E_USER_ID_BLOCKED_24_HRS;
  270 + }
  271 + }
  272 +
  273 + }
169 274  
170   - if (updateCount < 0)
171   - {
172   - //Put the log in log file
173   - logger.Fatal("Unable to Update past wrong login attempts for userId= " + userInfo.Id);
174 275 }
175 276 else
176 277 {
177   - if (userInfo.IncorrectLoginAttemptCount > 4)
  278 + userInfo.IsBlocked = true;
  279 + }
  280 + }
  281 +
  282 + else
  283 + {
  284 +
  285 + //bool isCorrectLoginId, isCorrectPassword;
  286 + //AIAHTML5.API.Models.Users.isCredentialCorrect(credentials, out isCorrectLoginId, out isCorrectPassword);
  287 +
  288 + //below code commented as way of retrieving data changed 'very first line in this method'
  289 + //if (!isCorrectLoginId)
  290 + //{
  291 + // // send message back to th UI that login id is incorrect
  292 + // authenticationRepsonse = AIAConstants.USER_NOT_FOUND;
  293 + //}
  294 + //else
  295 + //{
  296 + if (!isCorrectPassword)
  297 + {
  298 + // send message back to th UI that password is incorrect
  299 + userInfo.IsCorrectPassword = false;
  300 +
  301 + //get wrong attempt count of user
  302 + userInfo.IncorrectLoginAttemptCount = AIAHTML5.API.Models.Users.checkNoOfWrongAttempts(userInfo.Id) + 1;
  303 + userInfo.LoginFailureCauseId = ErrorHelper.E_PASSWORD_NOT_MATCH;
  304 +
  305 + //01. insert wrong attempt in dtabase
  306 + int updateCount = AIAHTML5.API.Models.Users.saveWrongAttemptofUser(userInfo.Id);
  307 +
  308 + if (updateCount < 0)
178 309 {
179   - userInfo.IsBlocked = true;
180   - userInfo.LoginFailureCauseId = ErrorHelper.E_USER_ID_BLOCKED_24_HRS;
  310 + //Put the log in log file
  311 + logger.Fatal("Unable to Update past wrong login attempts for userId= " + userInfo.Id);
  312 + }
  313 + else
  314 + {
  315 + if (userInfo.IncorrectLoginAttemptCount > 4)
  316 + {
  317 + userInfo.IsBlocked = true;
  318 + userInfo.LoginFailureCauseId = ErrorHelper.E_USER_ID_BLOCKED_24_HRS;
  319 + }
181 320 }
182 321 }
183 322 }
... ... @@ -190,8 +329,13 @@ namespace AIAHTML5.API.Controllers
190 329 //}
191 330  
192 331 authenticationRepsonse = JsonConvert.SerializeObject(userInfo);
  332 + //}
193 333 }
194 334 }
  335 + else
  336 + {
  337 + authenticationRepsonse = AIAConstants.USER_NOT_FOUND;
  338 + }
195 339  
196 340 //if (Convert.ToString(authenticationRepsonse) != AIAConstants.USER_NOT_FOUND && Convert.ToString(authenticationRepsonse) != AIAConstants.ERROR_IN_FECTHING_DETAILS && Convert.ToString(authenticationRepsonse)!= AIAConstants.SQL_CONNECTION_ERROR)
197 341 //{
... ...
400-SOURCECODE/AIAHTML5.API/Models/Users.cs
... ... @@ -219,13 +219,19 @@ namespace AIAHTML5.API.Models
219 219 ArrayList arrLicense = new ArrayList();
220 220 DBModel objModel = new DBModel();
221 221 Hashtable licenseEditionHash = objModel.GetLicenseDetailByUserId(userId);
222   - foreach (DictionaryEntry de in licenseEditionHash)
223   - {
224   - if (de.Key.ToString() == AIAConstants.LICENSE_KEY_ID)
225   - licenseId = Convert.ToInt32(de.Value);
226   - if (de.Key.ToString() == AIAConstants.EDITION_KEY_ID)
227   - editionId = Convert.ToInt32(de.Value);
228   - }
  222 +
  223 + if (licenseEditionHash.ContainsKey(AIAConstants.LICENSE_KEY_ID))
  224 + licenseId = Convert.ToInt32(licenseEditionHash[AIAConstants.LICENSE_KEY_ID]);
  225 +
  226 + if (licenseEditionHash.ContainsKey(AIAConstants.EDITION_KEY_ID))
  227 + editionId = Convert.ToInt32(licenseEditionHash[AIAConstants.EDITION_KEY_ID]);
  228 + //foreach (DictionaryEntry de in licenseEditionHash)
  229 + //{
  230 + // if (de.Key.ToString() == AIAConstants.LICENSE_KEY_ID)
  231 + // licenseId = Convert.ToInt32(de.Value);
  232 + // if (de.Key.ToString() == AIAConstants.EDITION_KEY_ID)
  233 + // editionId = Convert.ToInt32(de.Value);
  234 + //}
229 235 }
230 236  
231 237 internal static int insertLoginDetails(int userId)
... ... @@ -385,5 +391,20 @@ namespace AIAHTML5.API.Models
385 391  
386 392 return modulesList;
387 393 }
  394 +
  395 + internal static bool isUserBlocked(int userId, out DateTime blockTime)
  396 + {
  397 + blockTime = new DateTime();
  398 + DBModel objModel = new DBModel();
  399 + BlockedUser blockedUser = objModel.GetBlockedUserByUserId(userId);
  400 +
  401 + if (blockedUser != null)
  402 + {
  403 + blockTime = blockedUser.LoginTime;
  404 + return true;
  405 + }
  406 + else
  407 + return false;
  408 + }
388 409 }
389 410 }
390 411 \ No newline at end of file
... ...