Commit 821ed448f1e62aa38ceb063960ca6e86b1473bf6
1 parent
ae698151
started chnaging the code but need to sit with Utkarsh/Amrita to get all the points to be covered.
Showing
3 changed files
with
41 additions
and
43 deletions
400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs
... | ... | @@ -33,31 +33,35 @@ namespace AIAHTML5.API.Controllers |
33 | 33 | ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); |
34 | 34 | logger.Debug("inside POST"); |
35 | 35 | |
36 | - dynamic authenticationRepsonse; | |
36 | + dynamic authenticationRepsonse; | |
37 | 37 | |
38 | - try | |
39 | - { | |
38 | + try | |
39 | + { | |
40 | 40 | |
41 | - //01.get the user detail for autheticate user | |
41 | + //01.get the user detail to autheticate user | |
42 | 42 | User userInfo = AIAHTML5.API.Models.Users.getUserDetails(credentials); |
43 | 43 | |
44 | - if (userInfo.Id > 0) | |
45 | - { | |
46 | - // Check user is authenticated or not by login credential macth | |
47 | - bool isUserAuthenticated = AIAHTML5.API.Models.Users.IsUserAuthenticated(credentials, userInfo); | |
44 | + if (userInfo!= null) | |
45 | + { | |
46 | + // Check user is authenticated or not by login credential math | |
47 | + bool isUserAuthenticated = AIAHTML5.API.Models.Users.checkUserAuthenticity(credentials, userInfo); | |
48 | + | |
49 | + DateTime blockTime; | |
50 | + bool isUserBlocked; | |
48 | 51 | |
49 | - // check if user is blocked | |
50 | - DateTime blockTime; | |
51 | - bool isUserBlocked = AIAHTML5.API.Models.Users.isUserBlocked(userInfo.Id, out blockTime); | |
52 | + if (isUserAuthenticated) | |
53 | + { | |
52 | 54 | |
53 | - if (isUserAuthenticated && !isUserBlocked) | |
54 | - { | |
55 | - //01. Get User details | |
56 | - //userInfo = AIAHTML5.API.Models.Users.getUserDetails(credentials); | |
55 | + //01. assigning isCorrectPassword to true 'required for internal processing' | |
56 | + userInfo.IsCorrectPassword = true; | |
57 | 57 | |
58 | - //02. assigning isCorrectPassword to true 'required for internal processing' | |
59 | - userInfo.IsCorrectPassword = true; | |
58 | + //02. check if user is blocked | |
59 | + | |
60 | + isUserBlocked = AIAHTML5.API.Models.Users.checkUserBlockStatus(userInfo.Id, out blockTime); | |
60 | 61 | |
62 | + | |
63 | + if(!isUserBlocked) | |
64 | + { | |
61 | 65 | //04.delete past wrong login attempts of user |
62 | 66 | int wrongAttemptDeteledCount = AIAHTML5.API.Models.Users.deletePastWrongAttempts(userInfo.Id); |
63 | 67 | if (wrongAttemptDeteledCount < 0) |
... | ... | @@ -145,6 +149,7 @@ namespace AIAHTML5.API.Controllers |
145 | 149 | |
146 | 150 | authenticationRepsonse = JsonConvert.SerializeObject(userInfo); |
147 | 151 | } |
152 | + } | |
148 | 153 | else |
149 | 154 | { |
150 | 155 | //compare block time of user with current time if user is blocked | ... | ... |
400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs
... | ... | @@ -118,8 +118,8 @@ namespace AIAHTML5.API.Models |
118 | 118 | DataTable dt = new DataTable(); |
119 | 119 | da.Fill(dt); |
120 | 120 | |
121 | - | |
122 | - if (dt.Rows.Count > 0) | |
121 | + | |
122 | + if (dt!= null && dt.Rows.Count > 0) | |
123 | 123 | { |
124 | 124 | foreach (DataRow dr in dt.Rows) |
125 | 125 | { |
... | ... | @@ -145,10 +145,7 @@ namespace AIAHTML5.API.Models |
145 | 145 | objUser.IsActive = Convert.ToBoolean(dr["IsActive"]); |
146 | 146 | } |
147 | 147 | } |
148 | - else | |
149 | - { | |
150 | - objUser = new User(); | |
151 | - } | |
148 | + | |
152 | 149 | } |
153 | 150 | catch (SqlException ex) |
154 | 151 | { |
... | ... | @@ -850,10 +847,10 @@ namespace AIAHTML5.API.Models |
850 | 847 | return result; |
851 | 848 | } |
852 | 849 | |
853 | - internal BlockedUser GetBlockedUserByUserId(int userId) | |
850 | + internal BlockedUser GetUserBlockedStatusByUserId(int userId) | |
854 | 851 | { |
855 | - ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); | |
856 | - logger.Debug(" inside GetBlockedUserByUserId for UserId= " + userId); | |
852 | + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); | |
853 | + logger.Debug(" inside GetUserBlockedStatusByUserId for UserId= " + userId); | |
857 | 854 | |
858 | 855 | BlockedUser blockedUser = new BlockedUser(); |
859 | 856 | DataTable dt = null; |
... | ... | @@ -868,9 +865,9 @@ namespace AIAHTML5.API.Models |
868 | 865 | SqlDataAdapter da = new SqlDataAdapter(); |
869 | 866 | da.SelectCommand = cmd; |
870 | 867 | dt = new DataTable(); |
871 | - da.Fill(dt); | |
872 | - | |
873 | - if (dt.Rows.Count > 0) | |
868 | + da.Fill(dt); | |
869 | + | |
870 | + if (dt!= null && dt.Rows.Count > 0) | |
874 | 871 | { |
875 | 872 | foreach (DataRow dr in dt.Rows) |
876 | 873 | { |
... | ... | @@ -884,10 +881,7 @@ namespace AIAHTML5.API.Models |
884 | 881 | blockedUser.LoginTime = Convert.ToDateTime(dr["LoginTime"]); |
885 | 882 | } |
886 | 883 | } |
887 | - else | |
888 | - { | |
889 | - blockedUser = new BlockedUser (); | |
890 | - } | |
884 | + | |
891 | 885 | } |
892 | 886 | catch (SqlException ex) |
893 | 887 | { | ... | ... |
400-SOURCECODE/AIAHTML5.API/Models/Users.cs
... | ... | @@ -196,7 +196,7 @@ namespace AIAHTML5.API.Models |
196 | 196 | return result; |
197 | 197 | } |
198 | 198 | |
199 | - internal static bool IsUserAuthenticated(Newtonsoft.Json.Linq.JObject credentials, User user) | |
199 | + internal static bool checkUserAuthenticity(Newtonsoft.Json.Linq.JObject credentials, User user) | |
200 | 200 | { |
201 | 201 | bool isAuthenticatedUser = DBModel.ValidateUserAuthenticity(credentials["username"].ToString(), credentials["password"].ToString(), user); |
202 | 202 | |
... | ... | @@ -549,27 +549,26 @@ namespace AIAHTML5.API.Models |
549 | 549 | return modulesList; |
550 | 550 | } |
551 | 551 | |
552 | - internal static bool isUserBlocked(int userId, out DateTime blockTime) | |
552 | + internal static bool checkUserBlockStatus(int userId, out DateTime blockTime) | |
553 | 553 | { |
554 | 554 | ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); |
555 | 555 | logger.Debug("inside isUserBlocked for UserId =" + userId); |
556 | - bool result = false; | |
556 | + bool isUserBlocked = false; | |
557 | 557 | blockTime = new DateTime(); |
558 | 558 | |
559 | 559 | try |
560 | 560 | { |
561 | - | |
562 | - | |
561 | + | |
563 | 562 | DBModel objModel = new DBModel(); |
564 | - BlockedUser blockedUser = objModel.GetBlockedUserByUserId(userId); | |
563 | + BlockedUser blockedUser = objModel.GetUserBlockedStatusByUserId(userId); | |
565 | 564 | |
566 | - if (blockedUser.Id> 0) | |
565 | + if (blockedUser!= null) | |
567 | 566 | { |
568 | 567 | blockTime = blockedUser.LoginTime; |
569 | - result = true; | |
568 | + isUserBlocked = true; | |
570 | 569 | } |
571 | 570 | else |
572 | - result = false; | |
571 | + isUserBlocked = false; | |
573 | 572 | } |
574 | 573 | |
575 | 574 | catch (Exception e) |
... | ... | @@ -578,7 +577,7 @@ namespace AIAHTML5.API.Models |
578 | 577 | throw; |
579 | 578 | } |
580 | 579 | |
581 | - return result; | |
580 | + return isUserBlocked; | |
582 | 581 | } |
583 | 582 | } |
584 | 583 | } |
585 | 584 | \ No newline at end of file | ... | ... |