Commit 7f812aae6819fa9ec3de92ff7dcda2dfe1dd0008
1 parent
246d84ae
Committing restructured code of login
Showing
5 changed files
with
458 additions
and
181 deletions
400-SOURCECODE/AIAHTML5.API/Constants/AIAConstants.cs
... | ... | @@ -18,6 +18,10 @@ namespace AIAHTML5.API.Constants |
18 | 18 | public const string KEY_NAME = "name"; |
19 | 19 | public const string KEY_SLUG = "slug"; |
20 | 20 | public const string KEY_DESCRIPTION = "Description"; |
21 | + public const string KEY_LICENSE = "LICENSE"; | |
22 | + public const string KEY_EDITION = "EDITION"; | |
23 | + public const string KEY_LOGINID = "LOGINID"; | |
24 | + public const string KEY_PASSWORD = "PASSWORD"; | |
21 | 25 | |
22 | 26 | public const string PASSWORD_UPDATE_SUCCESS = "Password updated successfully"; |
23 | 27 | public const string PASSWORD_UPDATE_FAILED = "Password update failed"; | ... | ... |
400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs
... | ... | @@ -8,6 +8,8 @@ using System.Net.Http; |
8 | 8 | using System.Web.Http; |
9 | 9 | using log4net; |
10 | 10 | using AIAHTML5.API.Constants; |
11 | +using AIAHTML5.API.Models; | |
12 | +using System.Collections; | |
11 | 13 | |
12 | 14 | namespace AIAHTML5.API.Controllers |
13 | 15 | { |
... | ... | @@ -31,28 +33,164 @@ namespace AIAHTML5.API.Controllers |
31 | 33 | ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); |
32 | 34 | logger.Debug("inside POST"); |
33 | 35 | |
34 | - bool isUserAuthenticatedByDefault = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["isUserAuthenticated"]); | |
35 | - if (isUserAuthenticatedByDefault) | |
36 | + dynamic authenticationRepsonse; | |
37 | + | |
38 | + //01. check user is authenticated or not by login credential macth | |
39 | + bool isUserAuthenticated = AIAHTML5.API.Models.Users.IsUserAuthenticated(credentials); | |
40 | + | |
41 | + User objUser = new Models.User(); | |
42 | + | |
43 | + //02. Get User details | |
44 | + objUser = AIAHTML5.API.Models.Users.getUserDetails(credentials); | |
45 | + | |
46 | + if(isUserAuthenticated) | |
36 | 47 | { |
37 | - return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("true") }; | |
48 | + //03.delete past wrong login attempts of user | |
49 | + objUser.IsCorrectPassword = true; | |
50 | + int wrongAttemptDeteledCount = AIAHTML5.API.Models.Users.deletePastWrongAttempts(objUser.Id); | |
51 | + if (wrongAttemptDeteledCount < 0) | |
52 | + { | |
53 | + logger.Fatal("Unable to delete past wrong login attempts for userId= "+objUser.Id); | |
54 | + } | |
55 | + | |
56 | + if (objUser.UserType == AIAHTML5.API.Models.User.SUPER_ADMIN || objUser.UserType == AIAHTML5.API.Models.User.GENERAL_ADMIN) | |
57 | + { | |
58 | + objUser.Modules = AIAHTML5.API.Models.Users.getAllModulesList(); | |
59 | + AIAHTML5.API.Models.Users.insertLoginDetails(objUser.Id); | |
60 | + } | |
61 | + else | |
62 | + { | |
63 | + //03. get the license id for aUTHENTICATED USER | |
64 | + objUser.LicenseId = AIAHTML5.API.Models.Users.getLicenseIdForThisUser(objUser.Id, "license"); | |
65 | + objUser.EditionId = AIAHTML5.API.Models.Users.getLicenseIdForThisUser(objUser.Id, "edition"); | |
66 | + | |
67 | + //04.insert Log login details | |
68 | + //AIAHTML5.API.Models.Users.insertLoginDetails(objUser.Id); | |
69 | + //Commented above code inserts if the user license ~ subscription expired as well | |
70 | + | |
71 | + //05.Check user is active or not | |
72 | + //objUser.IsActive = AIAHTML5.API.Models.Users.isUSerActive(objUser); //Id suggested but passed userInfo to avoid multiple database hitting | |
73 | + | |
74 | + //if (objUser.IsActive) | |
75 | + //{ //Commenting as Inactive userid returns from here | |
76 | + //5.1 check the License expiration | |
77 | + //objUser.License.IsActive = AIAHTML5.API.Models.Users.isLicenseActive(objUser.LicenseId); | |
78 | + objUser.License = AIAHTML5.API.Models.Users.getLicenseDetails(objUser.LicenseId); | |
79 | + objUser.LicenseSubscriptions = AIAHTML5.API.Models.Users.getLicenseSubscriptionDetails(objUser.LicenseId); | |
80 | + objUser.SubscriptionExpirationDateString = AIAHTML5.API.Models.Users.SubscriptionExpirationDateString(objUser.LicenseId); | |
81 | + | |
82 | + //5.2 Check for subscription Expiration [Promoted for case if license inactive along with subscription expired] | |
83 | + if (!string.IsNullOrEmpty(objUser.SubscriptionExpirationDateString)) | |
84 | + { | |
85 | + objUser.IsSubscriptionExpired = true; | |
86 | + } | |
87 | + if (objUser.License.IsActive) | |
88 | + { | |
89 | + // send message to the UI for license expiration | |
90 | + //5.2 Check for subscription Expiration | |
91 | + //Insert user login details | |
92 | + AIAHTML5.API.Models.Users.insertLoginDetails(objUser.Id); | |
93 | + objUser.Modules = AIAHTML5.API.Models.Users.getModuleListByLicenseId(objUser.LicenseId); | |
94 | + | |
95 | + if (!objUser.License.IsTermAccepted) | |
96 | + { | |
97 | + ArrayList termsList = AIAHTML5.API.Models.Users.getTermsOfServiceText(); | |
98 | + foreach (Hashtable item in termsList) | |
99 | + { | |
100 | + objUser.TermsOfServiceTitle = item["title"].ToString(); | |
101 | + objUser.TermsOfServiceText = item["content"].ToString(); | |
102 | + } | |
103 | + } | |
104 | + } | |
105 | + //else | |
106 | + //{ | |
107 | + // //6. | |
108 | + | |
109 | + | |
110 | + // // now return this list to the UI | |
111 | + //} | |
112 | + //} | |
113 | + //else | |
114 | + //{ | |
115 | + // // send message back to th UI that user is inactive | |
116 | + //} | |
117 | + } | |
38 | 118 | |
39 | 119 | } |
40 | 120 | else |
41 | 121 | { |
122 | + bool isCorrectLoginId = AIAHTML5.API.Models.Users.isCredentialCorrect(credentials, objUser, "loginId"); | |
123 | + //bool isCorrectPassword = AIAHTML5.API.Models.Users.isCredentialCorrect(credentials, userInfo, "password"); | |
42 | 124 | |
43 | - dynamic authenticationRepsonse = AIAHTML5.API.Models.Users.GetUserDetailsForAuthenticatedUser(credentials); | |
44 | - if (Convert.ToString(authenticationRepsonse) != AIAConstants.USER_NOT_FOUND && Convert.ToString(authenticationRepsonse) != AIAConstants.ERROR_IN_FECTHING_DETAILS && Convert.ToString(authenticationRepsonse)!= AIAConstants.SQL_CONNECTION_ERROR) | |
125 | + if (!isCorrectLoginId) | |
45 | 126 | { |
46 | - //string userDetails = Newtonsoft.Json.JsonConvert.SerializeObject(authenticationRepsonse); | |
47 | - return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(authenticationRepsonse) }; | |
127 | + objUser = null; | |
48 | 128 | } |
49 | 129 | else |
50 | 130 | { |
51 | - return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(authenticationRepsonse) }; | |
131 | + objUser.IsCorrectPassword = false; | |
132 | + objUser.IncorrectLoginAttemptCount = AIAHTML5.API.Models.Users.checkNoOfWrongAttempts(objUser.Id) + 1; | |
133 | + //01. insert wrong attempt in dtabase | |
134 | + if (objUser.IncorrectLoginAttemptCount == 1) | |
135 | + { | |
136 | + int insertedCount = AIAHTML5.API.Models.Users.insertWrongAttemptofUser(objUser.Id); | |
137 | + } | |
138 | + else | |
139 | + { | |
140 | + int updateCount = AIAHTML5.API.Models.Users.saveWrongAttemptofUser(objUser.Id); | |
141 | + if (updateCount < 0) | |
142 | + { | |
143 | + //Put the log in log file | |
144 | + logger.Fatal("Unable to Update past wrong login attempts for userId= " + objUser.Id); | |
145 | + } | |
146 | + else | |
147 | + { | |
148 | + | |
149 | + //02. check no of wrong attempts | |
150 | + //userInfo.IncorrectLoginAttemptCount = AIAHTML5.API.Models.Users.checkNoOfWrongAttempts(userInfo.Id); | |
151 | + //if (userInfo.IncorrectLoginAttemptCount >= 5) | |
152 | + //{ | |
153 | + // userInfo.IsBlocked = true; | |
154 | + // // send block message | |
155 | + //} | |
156 | + //else | |
157 | + //{ | |
158 | + // // send message back to UI for login fail | |
159 | + //} | |
52 | 160 | |
161 | + if (objUser.IncorrectLoginAttemptCount > 4) | |
162 | + { | |
163 | + objUser.IsBlocked = true; | |
164 | + objUser.LoginFailureCauseId = ErrorHelper.E_USER_ID_BLOCKED_24_HRS; | |
165 | + } | |
166 | + } | |
167 | + } | |
168 | + if (objUser.License != null && !string.IsNullOrEmpty(objUser.License.AccountNumber)) | |
169 | + { | |
170 | + int result = AIAHTML5.API.Models.Users.insertUserLoginLog(objUser.License.AccountNumber, objUser.LoginFailureCauseId, null, objUser.EditionId.ToString(), null); | |
171 | + if (result < 0) | |
172 | + logger.Fatal("Unable to insert wrong attempt detail in UserLoginLog table for accountNumber= " + objUser.License.AccountNumber); | |
173 | + } | |
53 | 174 | } |
54 | 175 | } |
55 | - } | |
176 | + | |
177 | + if(objUser!=null) | |
178 | + authenticationRepsonse = JsonConvert.SerializeObject(objUser); | |
179 | + else | |
180 | + authenticationRepsonse = AIAConstants.USER_NOT_FOUND; | |
181 | + | |
182 | + //if (Convert.ToString(authenticationRepsonse) != AIAConstants.USER_NOT_FOUND && Convert.ToString(authenticationRepsonse) != AIAConstants.ERROR_IN_FECTHING_DETAILS && Convert.ToString(authenticationRepsonse)!= AIAConstants.SQL_CONNECTION_ERROR) | |
183 | + //{ | |
184 | + // //string userDetails = Newtonsoft.Json.JsonConvert.SerializeObject(authenticationRepsonse); | |
185 | + // return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(authenticationRepsonse) }; | |
186 | + //} | |
187 | + //else | |
188 | + //{ | |
189 | + return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(authenticationRepsonse) }; | |
190 | + | |
191 | + //} | |
192 | + } | |
193 | + | |
56 | 194 | |
57 | 195 | // PUT api/authenticate/5 |
58 | 196 | public void Put(int id, [FromBody]string value) | ... | ... |
400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs
... | ... | @@ -59,7 +59,7 @@ namespace AIAHTML5.API.Models |
59 | 59 | return ds; |
60 | 60 | } |
61 | 61 | |
62 | - protected ArrayList GetUserModules() | |
62 | + public ArrayList GetUserModules() | |
63 | 63 | { |
64 | 64 | ArrayList arrUserModules = new ArrayList(); |
65 | 65 | Hashtable userModuleHash = null; |
... | ... | @@ -176,133 +176,10 @@ namespace AIAHTML5.API.Models |
176 | 176 | { |
177 | 177 | objUser = null; |
178 | 178 | } |
179 | - | |
180 | - if (objUser != null) | |
181 | - { | |
182 | - Hashtable licenseEditionHash = objModel.GetUserLicenseIdEditionIdByUserId(objUser.Id); | |
183 | - foreach (DictionaryEntry de in licenseEditionHash) | |
184 | - { | |
185 | - if (de.Key.ToString() == AIAConstants.LICENSE_KEY_ID) | |
186 | - objUser.LicenseId = Convert.ToInt32(de.Value); | |
187 | - if (de.Key.ToString() == AIAConstants.EDITION_KEY_ID) | |
188 | - objUser.EditionId = Convert.ToInt32(de.Value); | |
189 | - } | |
190 | - | |
191 | - if (objUser.LicenseId != 0) | |
192 | - { | |
193 | - objUser.License = objModel.GetLicenseDetailsByLicenseId(objUser.LicenseId); | |
194 | - objUser.LicenseSubscriptions = objModel.GetLicenseSubscriptionDetailsByLicenseId(objUser.LicenseId); | |
195 | - } | |
196 | - else | |
197 | - { | |
198 | - objUser.License = null; | |
199 | - } | |
200 | - | |
201 | - BlockedUser blockedUser = objModel.GetBlockedUserByUserId(objUser.Id); | |
202 | - | |
203 | - if (blockedUser != null) | |
204 | - { | |
205 | - DateTime LoginTime = (DateTime)blockedUser.LoginTime; | |
206 | - DateTime blockTime = LoginTime.AddDays(1); | |
207 | - var difference = DateTime.Compare(DateTime.Now, blockTime); | |
208 | - if (difference >= 0) | |
209 | - { | |
210 | - objUser.IsBlocked = false; | |
211 | - } | |
212 | - else | |
213 | - { | |
214 | - objUser.IsBlocked = true; | |
215 | - objUser.IncorrectLoginAttemptCount = objModel.GetIncorrectLoginAttempts(objUser.Id); | |
216 | - } | |
217 | - } | |
218 | - else | |
219 | - { | |
220 | - objUser.IsBlocked = false; | |
221 | - } | |
222 | - | |
223 | - if (!objUser.IsBlocked) | |
224 | - { | |
225 | - if (!string.Equals(objUser.Password, password)) | |
226 | - { | |
227 | - objUser.IsCorrectPassword = false; | |
228 | - objUser.IncorrectLoginAttemptCount = objModel.GetIncorrectLoginAttempts(objUser.Id) + 1; | |
229 | - | |
230 | - objUser.LoginFailureCauseId = ErrorHelper.E_PASSWORD_NOT_MATCH; | |
231 | - | |
232 | - if (objUser.IncorrectLoginAttemptCount == 1) | |
233 | - { | |
234 | - objModel.InsertIncorrectLoginAttempts(objUser.Id); | |
235 | - } | |
236 | - else | |
237 | - { | |
238 | - objModel.UpdateIncorrectLoginAttempts(objUser.Id); | |
239 | - | |
240 | - if (objUser.IncorrectLoginAttemptCount > 4) | |
241 | - { | |
242 | - objUser.IsBlocked = true; | |
243 | - objUser.LoginFailureCauseId = ErrorHelper.E_USER_ID_BLOCKED_24_HRS; | |
244 | - } | |
245 | - } | |
246 | - if (objUser.License != null && !string.IsNullOrEmpty(objUser.License.AccountNumber)) | |
247 | - { | |
248 | - objModel.InsertUserLoginLog(objUser.License.AccountNumber, objUser.LoginFailureCauseId, null, objUser.EditionId.ToString(), null); | |
249 | - } | |
250 | - } | |
251 | - else | |
252 | - { | |
253 | - if (objUser.UserType == User.SUPER_ADMIN || objUser.UserType == User.GENERAL_ADMIN) | |
254 | - { | |
255 | - objUser.IsCorrectPassword = true; | |
256 | - objUser.Modules = objModel.GetUserModules(); | |
257 | - | |
258 | - objModel.InsertLoginDetails(objUser.Id); | |
259 | - objModel.DeleteIncorrectLoginAttempts(objUser.Id); | |
260 | - } | |
261 | - else | |
262 | - { | |
263 | - objUser.IsCorrectPassword = true; | |
264 | - | |
265 | - if (objUser.License != null) | |
266 | - { | |
267 | - if (objUser.LicenseSubscriptions != null) | |
268 | - { | |
269 | - DateTime? subscriptionValidThrough = objUser.LicenseSubscriptions.SubscriptionValidThrough; | |
270 | - if (subscriptionValidThrough != null && subscriptionValidThrough.Value.Date >= DateTime.Now.Date) | |
271 | - { | |
272 | - ArrayList allModulesList = objModel.GetUserModules(); | |
273 | - ArrayList licensedModulesList = objModel.GetModuleStatusByLicenseId(objUser.LicenseId); | |
274 | - | |
275 | - ArrayList userModuleList = objModel.GetUserModulesList(allModulesList, licensedModulesList); | |
276 | - objUser.Modules = userModuleList; | |
277 | - | |
278 | - if (!objUser.License.IsTermAccepted) | |
279 | - { | |
280 | - ArrayList termsList = DBModel.GetTermsOfServiceText(); | |
281 | - foreach (Hashtable item in termsList) | |
282 | - { | |
283 | - objUser.TermsOfServiceTitle = item["title"].ToString(); | |
284 | - objUser.TermsOfServiceText = item["content"].ToString(); | |
285 | - } | |
286 | - } | |
287 | - objModel.InsertLoginDetails(objUser.Id); | |
288 | - objModel.DeleteIncorrectLoginAttempts(objUser.Id); | |
289 | - } | |
290 | - else | |
291 | - { | |
292 | - objUser.IsSubscriptionExpired = true; | |
293 | - objUser.SubscriptionExpirationDateString = objUser.LicenseSubscriptions.SubscriptionValidThrough.Value.Date.ToString("MM/dd/yyyy").ToString(); | |
294 | - } | |
295 | - } | |
296 | - } | |
297 | - } | |
298 | - } | |
299 | - } | |
300 | - } | |
301 | - | |
302 | 179 | return objUser; |
303 | 180 | } |
304 | 181 | |
305 | - protected Hashtable GetUserLicenseIdEditionIdByUserId(int userId) | |
182 | + public Hashtable GetUserLicenseDetailByUserId(int userId) | |
306 | 183 | { |
307 | 184 | Hashtable hash = new Hashtable(); |
308 | 185 | |
... | ... | @@ -313,7 +190,7 @@ namespace AIAHTML5.API.Models |
313 | 190 | DataSet ds = new DataSet(); |
314 | 191 | |
315 | 192 | cmd.Connection = conn; |
316 | - cmd.CommandText = "GetLicenseIdEditionIdByUserId"; | |
193 | + cmd.CommandText = "GetLicenseDetailByUserId"; | |
317 | 194 | cmd.CommandType = CommandType.StoredProcedure; |
318 | 195 | |
319 | 196 | param = new SqlParameter("@iUserId", userId); |
... | ... | @@ -331,7 +208,7 @@ namespace AIAHTML5.API.Models |
331 | 208 | return hash; |
332 | 209 | } |
333 | 210 | |
334 | - protected ArrayList GetModuleStatusByLicenseId(int licenseId) | |
211 | + public ArrayList GetUserModulesByLicenseId(int licenseId) | |
335 | 212 | { |
336 | 213 | ArrayList userModulelist = new ArrayList(); |
337 | 214 | Hashtable modulesHash; |
... | ... | @@ -343,7 +220,7 @@ namespace AIAHTML5.API.Models |
343 | 220 | SqlParameter param; |
344 | 221 | |
345 | 222 | cmd.Connection = conn; |
346 | - cmd.CommandText = "GetModuleStatusByLicenseId"; | |
223 | + cmd.CommandText = "GetUserModulesByLicenseId"; | |
347 | 224 | cmd.CommandType = CommandType.StoredProcedure; |
348 | 225 | |
349 | 226 | param = new SqlParameter("@iLicenseId", licenseId); |
... | ... | @@ -358,16 +235,15 @@ namespace AIAHTML5.API.Models |
358 | 235 | foreach (DataRow dr in dt.Rows) |
359 | 236 | { |
360 | 237 | modulesHash = new Hashtable(); |
361 | - modulesHash.Add("Id", dr["Id"]); | |
362 | - modulesHash.Add("Title", dr["Title"]); | |
363 | - modulesHash.Add("Status", dr["Status"]); | |
238 | + modulesHash.Add("name", dr["Title"]); | |
239 | + modulesHash.Add("slug", dr["Slug"]); | |
364 | 240 | userModulelist.Add(modulesHash); |
365 | 241 | } |
366 | 242 | |
367 | 243 | return userModulelist; |
368 | 244 | } |
369 | 245 | |
370 | - protected ArrayList GetUserModulesList(ArrayList allModules, ArrayList modulesByLicense) | |
246 | + public ArrayList GetUserModulesList(ArrayList allModules, ArrayList modulesByLicense) | |
371 | 247 | { |
372 | 248 | ArrayList userModules = new ArrayList(); |
373 | 249 | Hashtable moduleHash; |
... | ... | @@ -536,7 +412,7 @@ namespace AIAHTML5.API.Models |
536 | 412 | return result; |
537 | 413 | } |
538 | 414 | |
539 | - protected LicenseSubscriptionDetails GetLicenseSubscriptionDetailsByLicenseId(int licenseId) | |
415 | + public LicenseSubscriptionDetails GetLicenseSubscriptionDetailsByLicenseId(int licenseId) | |
540 | 416 | { |
541 | 417 | ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); |
542 | 418 | logger.Debug(" Inside GetLicenseSubscriptionDetailsByLicenseId for LicenseId = " + licenseId); |
... | ... | @@ -627,7 +503,7 @@ namespace AIAHTML5.API.Models |
627 | 503 | return lsd; |
628 | 504 | } |
629 | 505 | |
630 | - protected License GetLicenseDetailsByLicenseId(int licenseId) | |
506 | + public License GetLicenseDetailsByLicenseId(int licenseId) | |
631 | 507 | { |
632 | 508 | ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); |
633 | 509 | logger.Debug(" inside GetLicenseDetailsByLicenseId for LicenseId = " + licenseId); |
... | ... | @@ -740,7 +616,7 @@ namespace AIAHTML5.API.Models |
740 | 616 | return result; |
741 | 617 | } |
742 | 618 | |
743 | - protected static ArrayList GetTermsOfServiceText() | |
619 | + internal static ArrayList GetTermsOfServiceText() | |
744 | 620 | { |
745 | 621 | ArrayList arrTermsOfService = new ArrayList(); |
746 | 622 | Hashtable contentHash = null; |
... | ... | @@ -759,7 +635,7 @@ namespace AIAHTML5.API.Models |
759 | 635 | return arrTermsOfService; |
760 | 636 | } |
761 | 637 | |
762 | - protected int InsertLoginDetails(int userId) | |
638 | + internal int InsertLoginDetails(int userId) | |
763 | 639 | { |
764 | 640 | ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); |
765 | 641 | logger.Debug(" inside InsertLoginDetails for UserId= " + userId); |
... | ... | @@ -785,7 +661,7 @@ namespace AIAHTML5.API.Models |
785 | 661 | return result; |
786 | 662 | } |
787 | 663 | |
788 | - protected int InsertIncorrectLoginAttempts(int userId) | |
664 | + public int InsertIncorrectLoginAttempts(int userId) | |
789 | 665 | { |
790 | 666 | ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); |
791 | 667 | logger.Debug(" inside InsertIncorrectLoginAttempts for UserId= " + userId); |
... | ... | @@ -810,7 +686,7 @@ namespace AIAHTML5.API.Models |
810 | 686 | return result; |
811 | 687 | } |
812 | 688 | |
813 | - protected int GetIncorrectLoginAttempts(int userId) | |
689 | + public int GetIncorrectLoginAttempts(int userId) | |
814 | 690 | { |
815 | 691 | ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); |
816 | 692 | logger.Debug(" inside GetIncorrectLoginAttempts for UserId = " + userId); |
... | ... | @@ -844,7 +720,7 @@ namespace AIAHTML5.API.Models |
844 | 720 | return count; |
845 | 721 | } |
846 | 722 | |
847 | - protected int UpdateIncorrectLoginAttempts(int userId) | |
723 | + internal int UpdateIncorrectLoginAttempts(int userId) | |
848 | 724 | { |
849 | 725 | ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); |
850 | 726 | logger.Debug(" inside UpdateIncorrectLoginAttempts for UserId= " + userId); |
... | ... | @@ -870,7 +746,7 @@ namespace AIAHTML5.API.Models |
870 | 746 | return result; |
871 | 747 | } |
872 | 748 | |
873 | - protected int DeleteIncorrectLoginAttempts(int userId) | |
749 | + public int DeleteIncorrectLoginAttempts(int userId) | |
874 | 750 | { |
875 | 751 | ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); |
876 | 752 | logger.Debug(" inside DeleteIncorrectLoginAttempts for UserId= " + userId); |
... | ... | @@ -916,7 +792,7 @@ namespace AIAHTML5.API.Models |
916 | 792 | return failureCauseList; |
917 | 793 | } |
918 | 794 | |
919 | - protected int InsertUserLoginLog(string accountNumber, Int16 failureId, string referalUrl, string edition, string httpReferer) | |
795 | + internal int InsertUserLoginLog(string accountNumber, Int16 failureId, string referalUrl, string edition, string httpReferer) | |
920 | 796 | { |
921 | 797 | ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); |
922 | 798 | logger.Debug(" inside InsertUserLoginLog for AccountNumber= " + accountNumber); |
... | ... | @@ -1068,5 +944,56 @@ namespace AIAHTML5.API.Models |
1068 | 944 | |
1069 | 945 | return result; |
1070 | 946 | } |
947 | + | |
948 | + internal static bool ValidateUserAuthenticity(string username, string password) | |
949 | + { | |
950 | + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); | |
951 | + logger.Debug(" Inside ValidateUserAuthenticity for Username = " + username + ", Password: " + password); | |
952 | + | |
953 | + User objUser = new User(); | |
954 | + DBModel objModel = new DBModel(); | |
955 | + | |
956 | + conn = new SqlConnection(dbConnectionString); | |
957 | + cmd = new SqlCommand(); | |
958 | + SqlDataAdapter da = new SqlDataAdapter(); | |
959 | + SqlParameter param; | |
960 | + DataSet ds = new DataSet(); | |
961 | + | |
962 | + cmd.Connection = conn; | |
963 | + cmd.CommandText = "GetUserDetailsByLoginId"; | |
964 | + cmd.CommandType = CommandType.StoredProcedure; | |
965 | + | |
966 | + param = new SqlParameter("@sLoginId", username); | |
967 | + param.Direction = ParameterDirection.Input; | |
968 | + param.DbType = DbType.String; | |
969 | + cmd.Parameters.Add(param); | |
970 | + | |
971 | + da.SelectCommand = cmd; | |
972 | + DataTable dt = new DataTable(); | |
973 | + da.Fill(dt); | |
974 | + | |
975 | + bool result = false; | |
976 | + | |
977 | + if (dt.Rows.Count > 0) | |
978 | + { | |
979 | + foreach (DataRow dr in dt.Rows) | |
980 | + { | |
981 | + foreach (DataColumn dc in dt.Columns) | |
982 | + { | |
983 | + if (dc.ColumnName == "LoginId") | |
984 | + objUser.LoginId = dr[dc].ToString(); | |
985 | + if (dc.ColumnName == "Password") | |
986 | + objUser.Password = dr[dc].ToString(); | |
987 | + } | |
988 | + } | |
989 | + | |
990 | + if ((string.Equals(username.ToUpper(), objUser.LoginId.ToUpper())) && (string.Equals(password, objUser.Password))) | |
991 | + result = true; | |
992 | + else | |
993 | + result = false; | |
994 | + } | |
995 | + | |
996 | + return result; | |
997 | + } | |
1071 | 998 | } |
1072 | 999 | } |
1073 | 1000 | \ No newline at end of file | ... | ... |
400-SOURCECODE/AIAHTML5.API/Models/Users.cs
... | ... | @@ -23,26 +23,6 @@ namespace AIAHTML5.API.Models |
23 | 23 | |
24 | 24 | try |
25 | 25 | { |
26 | - //var client = new MongoClient(); | |
27 | - //var db = client.GetDatabase(Settings.Default.database); | |
28 | - | |
29 | - //var collection = db.GetCollection<dynamic>("Users"); | |
30 | - | |
31 | - //FilterDefinition<dynamic>[] filterCondition = { Builders<dynamic>.Filter.Eq("loginId", credentials["username"].ToString()), | |
32 | - // Builders<dynamic>.Filter.Eq("password", credentials["password"].ToString())}; | |
33 | - | |
34 | - //dynamic userDetails = collection.Find(Builders<dynamic>.Filter.And(filterCondition)).SingleOrDefault(); | |
35 | - | |
36 | - | |
37 | - //if (userDetails != null) | |
38 | - //{ | |
39 | - // logger.Debug("userDetails.loginId= " + userDetails.loginId); | |
40 | - // return userDetails; | |
41 | - //} | |
42 | - //else | |
43 | - //{ | |
44 | - // return AIAConstants.USER_NOT_FOUND; | |
45 | - //} | |
46 | 26 | User user = DBModel.GetUserDetailsByLoginIdAndPassword(credentials["username"].ToString(), credentials["password"].ToString()); |
47 | 27 | //string userDetails = DBModel.GetUserDetailsByLoginId2(credentials["username"].ToString()); |
48 | 28 | |
... | ... | @@ -206,5 +186,213 @@ namespace AIAHTML5.API.Models |
206 | 186 | |
207 | 187 | return result; |
208 | 188 | } |
189 | + | |
190 | + internal static bool IsUserAuthenticated(Newtonsoft.Json.Linq.JObject credentials) | |
191 | + { | |
192 | + bool isAuthenticatedUser = DBModel.ValidateUserAuthenticity(credentials["username"].ToString(), credentials["password"].ToString()); | |
193 | + | |
194 | + return isAuthenticatedUser; | |
195 | + } | |
196 | + | |
197 | + internal static User getLoggedinUserDetail(Newtonsoft.Json.Linq.JObject credentials) | |
198 | + { | |
199 | + User user = DBModel.GetUserDetailsByLoginIdAndPassword(credentials["username"].ToString(), credentials["password"].ToString()); | |
200 | + | |
201 | + return user; | |
202 | + } | |
203 | + | |
204 | + internal static User getUserDetails(Newtonsoft.Json.Linq.JObject credentials) | |
205 | + { | |
206 | + User user = DBModel.GetUserDetailsByLoginIdAndPassword(credentials["username"].ToString(), credentials["password"].ToString()); | |
207 | + | |
208 | + return user; | |
209 | + } | |
210 | + | |
211 | + internal static int getLicenseIdForThisUser(int userId, string key) | |
212 | + { | |
213 | + ArrayList arrLicense = new ArrayList(); | |
214 | + DBModel objModel = new DBModel(); | |
215 | + int licenseId = 0 , editionId = 0, result = 0; | |
216 | + Hashtable licenseEditionHash = objModel.GetUserLicenseDetailByUserId(userId); | |
217 | + foreach (DictionaryEntry de in licenseEditionHash) | |
218 | + { | |
219 | + if (de.Key.ToString() == AIAConstants.LICENSE_KEY_ID) | |
220 | + licenseId = Convert.ToInt32(de.Value); | |
221 | + if (de.Key.ToString() == AIAConstants.EDITION_KEY_ID) | |
222 | + editionId = Convert.ToInt32(de.Value); | |
223 | + } | |
224 | + | |
225 | + if (string.Equals(key.ToUpper(), AIAConstants.KEY_LICENSE)) | |
226 | + result = licenseId; | |
227 | + if (string.Equals(key.ToUpper(), AIAConstants.KEY_EDITION)) | |
228 | + result = editionId; | |
229 | + return result; | |
230 | + } | |
231 | + | |
232 | + internal static int insertLoginDetails(int userId) | |
233 | + { | |
234 | + int result = 0; | |
235 | + DBModel objModel = new DBModel(); | |
236 | + | |
237 | + result = objModel.InsertLoginDetails(userId); | |
238 | + | |
239 | + return result; | |
240 | + } | |
241 | + | |
242 | + internal static bool isUSerActive(User user) | |
243 | + { | |
244 | + if (user.IsActive) | |
245 | + return true; | |
246 | + else | |
247 | + return false; | |
248 | + } | |
249 | + | |
250 | + internal static string SubscriptionExpirationDateString(int licenseId) | |
251 | + { | |
252 | + DBModel objModel = new DBModel(); | |
253 | + LicenseSubscriptionDetails licenseSubscription = objModel.GetLicenseSubscriptionDetailsByLicenseId(licenseId); | |
254 | + string subscritptionExpirationDateString = null; | |
255 | + | |
256 | + if (licenseSubscription != null) | |
257 | + { | |
258 | + DateTime? subscriptionValidThrough = licenseSubscription.SubscriptionValidThrough; | |
259 | + if (subscriptionValidThrough != null && subscriptionValidThrough.Value.Date >= DateTime.Now.Date) | |
260 | + { | |
261 | + subscritptionExpirationDateString = null; | |
262 | + } | |
263 | + else | |
264 | + { | |
265 | + subscritptionExpirationDateString = licenseSubscription.SubscriptionValidThrough.Value.Date.ToString("MM/dd/yyyy").ToString(); | |
266 | + } | |
267 | + } | |
268 | + return subscritptionExpirationDateString; | |
269 | + } | |
270 | + | |
271 | + internal static ArrayList getModuleListByLicenseId(int licenseId) | |
272 | + { | |
273 | + DBModel objModel = new DBModel(); | |
274 | + ArrayList licensedModulesList = objModel.GetUserModulesByLicenseId(licenseId); | |
275 | + | |
276 | + return licensedModulesList; | |
277 | + } | |
278 | + | |
279 | + internal static int deletePastWrongAttempts(int userId) | |
280 | + { | |
281 | + int result = 0; | |
282 | + DBModel objModel = new DBModel(); | |
283 | + | |
284 | + result = objModel.DeleteIncorrectLoginAttempts(userId); | |
285 | + | |
286 | + return result; | |
287 | + } | |
288 | + | |
289 | + internal static int insertWrongAttemptofUser(int userId) | |
290 | + { | |
291 | + int result = 0; | |
292 | + DBModel objModel = new DBModel(); | |
293 | + | |
294 | + result = objModel.InsertIncorrectLoginAttempts(userId); | |
295 | + | |
296 | + return result; | |
297 | + } | |
298 | + | |
299 | + internal static int checkNoOfWrongAttempts(int userId) | |
300 | + { | |
301 | + int result = 0; | |
302 | + DBModel objModel = new DBModel(); | |
303 | + | |
304 | + result = objModel.GetIncorrectLoginAttempts(userId); | |
305 | + | |
306 | + return result; | |
307 | + } | |
308 | + | |
309 | + internal static int saveWrongAttemptofUser(int userId) | |
310 | + { | |
311 | + int result = 0; | |
312 | + DBModel objModel = new DBModel(); | |
313 | + | |
314 | + result = objModel.UpdateIncorrectLoginAttempts(userId); | |
315 | + | |
316 | + return result; | |
317 | + } | |
318 | + | |
319 | + internal static bool isLicenseActive(int licenseId) | |
320 | + { | |
321 | + DBModel objModel = new DBModel(); | |
322 | + License userLicense = objModel.GetLicenseDetailsByLicenseId(licenseId); | |
323 | + | |
324 | + if (userLicense.IsActive) | |
325 | + return true; | |
326 | + else | |
327 | + return false; | |
328 | + } | |
329 | + | |
330 | + internal static License getLicenseDetails(int licenseId) | |
331 | + { | |
332 | + DBModel objModel = new DBModel(); | |
333 | + License userLicense = objModel.GetLicenseDetailsByLicenseId(licenseId); | |
334 | + | |
335 | + return userLicense; | |
336 | + } | |
337 | + | |
338 | + internal static LicenseSubscriptionDetails getLicenseSubscriptionDetails(int licenseId) | |
339 | + { | |
340 | + DBModel objModel = new DBModel(); | |
341 | + LicenseSubscriptionDetails userSubscriptionDetail = objModel.GetLicenseSubscriptionDetailsByLicenseId(licenseId); | |
342 | + | |
343 | + return userSubscriptionDetail; | |
344 | + } | |
345 | + | |
346 | + internal static bool isCredentialCorrect(Newtonsoft.Json.Linq.JObject credentials, User user, string key) | |
347 | + { | |
348 | + bool result = false; | |
349 | + if (user != null) | |
350 | + { | |
351 | + if (string.Equals(key.ToUpper(), AIAConstants.KEY_LOGINID)) | |
352 | + { | |
353 | + if (string.Equals(credentials["username"].ToString().ToUpper(), user.LoginId.ToUpper())) | |
354 | + result = true; | |
355 | + else | |
356 | + result = false; | |
357 | + } | |
358 | + | |
359 | + if (string.Equals(key.ToUpper(), AIAConstants.KEY_PASSWORD)) | |
360 | + { | |
361 | + if (string.Equals(credentials["password"].ToString(), user.Password)) | |
362 | + result = true; | |
363 | + else | |
364 | + result = false; | |
365 | + } | |
366 | + } | |
367 | + | |
368 | + return result; | |
369 | + } | |
370 | + | |
371 | + internal static int insertUserLoginLog(string accountNumber, Int16 failureId, string referalUrl, string edition, string httpReferer) | |
372 | + { | |
373 | + int result = 0; | |
374 | + DBModel objModel = new DBModel(); | |
375 | + result = objModel.InsertUserLoginLog(accountNumber, failureId, null, edition, null); | |
376 | + | |
377 | + return result; | |
378 | + } | |
379 | + | |
380 | + | |
381 | + internal static ArrayList getTermsOfServiceText() | |
382 | + { | |
383 | + ArrayList arrTermsOfService = new ArrayList(); | |
384 | + DBModel objModel = new DBModel(); | |
385 | + arrTermsOfService = DBModel.GetTermsOfServiceText(); | |
386 | + | |
387 | + return arrTermsOfService; | |
388 | + } | |
389 | + | |
390 | + internal static ArrayList getAllModulesList() | |
391 | + { | |
392 | + DBModel objModel = new DBModel(); | |
393 | + ArrayList modulesList = objModel.GetUserModules(); | |
394 | + | |
395 | + return modulesList; | |
396 | + } | |
209 | 397 | } |
210 | 398 | } |
211 | 399 | \ No newline at end of file | ... | ... |
400-SOURCECODE/AIAHTML5.Web/app/controllers/HomeController.js
... | ... | @@ -342,11 +342,29 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic |
342 | 342 | try { |
343 | 343 | var userInfo = JSON.parse(currentUserDetails); |
344 | 344 | |
345 | - if (userInfo.loginId != undefined || userInfo.loginId != "" || userInfo.loginId != null) { | |
346 | - $rootScope.isVisibleLogin = false; | |
347 | - $rootScope.userData = userInfo; | |
348 | - $rootScope.userModules = userInfo.Modules; | |
349 | - if ($rootScope.refreshcheck == null) { | |
345 | + if (userInfo.LoginId != undefined || userInfo.LoginId != "" || userInfo.LoginId != null) { | |
346 | + if (userInfo.License.IsTermAccepted) { | |
347 | + $rootScope.userData = userInfo; | |
348 | + $rootScope.userModules = userInfo.Modules; | |
349 | + $rootScope.isVisibleLogin = false; | |
350 | + //$rootScope.haveRoleAdmin = true; | |
351 | + $rootScope.licenseeAccountNumber = userInfo.License.AccountNumber; | |
352 | + | |
353 | + if ($rootScope.refreshcheck == null) { | |
354 | + $location.path('/'); | |
355 | + } | |
356 | + | |
357 | + } | |
358 | + else { | |
359 | + if ($('#dvTerms').length > 0) { | |
360 | + $('#dvTerms').html(userInfo.TermsOfServiceText); | |
361 | + } | |
362 | + $rootScope.isVisibleLogin = true; | |
363 | + $('#dvTermCondition').fadeIn(); | |
364 | + $rootScope.userData = userInfo; | |
365 | + $rootScope.userModules = userInfo.Modules; | |
366 | + //$rootScope.haveRoleAdmin = true; | |
367 | + $rootScope.licenseeAccountNumber = userInfo.License.AccountNumber; | |
350 | 368 | $location.path('/'); |
351 | 369 | } |
352 | 370 | } |
... | ... | @@ -521,24 +539,26 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic |
521 | 539 | userEmailId = split[1]; |
522 | 540 | } |
523 | 541 | |
524 | - //document.location = '/'; | |
525 | - | |
526 | 542 | AuthenticationService.UnblockUser(userEmailId) |
527 | 543 | .then( |
528 | 544 | function (result) { |
529 | 545 | if (result == LoginMessageConstants.USER_UNBLOCK_SUCCESS) { |
530 | 546 | $rootScope.errorMessage = LoginMessageConstants.USER_UNBLOCK_SUCCESS_MESSAGE; |
531 | 547 | $("#messageModal").modal('show'); |
548 | + $rootScope.isVisibleLogin = true; | |
532 | 549 | //$('#messageModal.btn-primary').click(function () { |
533 | - // document.location = '/'; | |
550 | + //$location.path('/'); | |
534 | 551 | //}); |
552 | + document.location.href = "/" | |
535 | 553 | } |
536 | 554 | else { |
537 | 555 | $rootScope.errorMessage = LoginMessageConstants.USER_ALREADY_UNBLOCKED; |
538 | - //$("#messageModal").modal('show'); | |
556 | + $("#messageModal").modal('show'); | |
557 | + $rootScope.isVisibleLogin = true; | |
539 | 558 | //$('#messageModal.btn-primary').click(function () { |
540 | - // document.location = '/'; | |
559 | + //$location.path('/'); | |
541 | 560 | //}); |
561 | + document.location.href = "/" | |
542 | 562 | } |
543 | 563 | }, |
544 | 564 | function (error) { |
... | ... | @@ -3775,7 +3795,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic |
3775 | 3795 | |
3776 | 3796 | |
3777 | 3797 | if ((localStorage.getItem('loggedInUserDetails') == null) && ($rootScope.isVisibleLogin == false)) { |
3778 | - if ($location.url().indexOf('?') == -1) | |
3798 | + if ($location.url().indexOf('?em') == -1 && $location.url().indexOf('?unb') == -1) | |
3779 | 3799 | $rootScope.LogoutUser(); |
3780 | 3800 | |
3781 | 3801 | ... | ... |