Commit cd969d4f25ef618a4c117d82e3f44c68b236e18f
1 parent
26cb5ca9
check licence if not user isActive
Showing
1 changed file
with
158 additions
and
153 deletions
400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs
... | ... | @@ -33,62 +33,57 @@ 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; | |
37 | - DateTime blockTime; | |
38 | - bool isUserBlocked; | |
36 | + dynamic authenticationRepsonse; | |
37 | + DateTime blockTime; | |
38 | + bool isUserBlocked; | |
39 | 39 | |
40 | - try | |
41 | - { | |
40 | + try | |
41 | + { | |
42 | 42 | |
43 | 43 | //01.get the user detail to autheticate the user |
44 | - User userInfo = AIAHTML5.API.Models.Users.getUserDetails(credentials); | |
45 | - | |
46 | - if (userInfo!= null) | |
47 | - { | |
48 | - // Check user is authenticated or not by login credential match | |
49 | - bool isUserAuthenticated = AIAHTML5.API.Models.Users.checkUserAuthenticity(credentials, userInfo); | |
50 | - | |
51 | - if (isUserAuthenticated) | |
52 | - { | |
53 | - | |
54 | - //01. assigning isCorrectPassword to true 'required for internal processing' | |
55 | - userInfo.IsCorrectPassword = true; | |
56 | - | |
57 | - //02. check if user is blocked | |
58 | - if(userInfo.IsActive){ | |
59 | - | |
60 | - isUserBlocked = AIAHTML5.API.Models.Users.checkUserBlockStatus(userInfo.Id, out blockTime); | |
61 | - | |
62 | - | |
63 | - if(!isUserBlocked) | |
64 | - { | |
65 | - //04.delete past wrong login attempts of user | |
66 | - int wrongAttemptDeteledCount = AIAHTML5.API.Models.Users.deletePastWrongAttempts(userInfo.Id); | |
67 | - if (wrongAttemptDeteledCount < 0) | |
68 | - { | |
69 | - logger.Fatal("Unable to delete past wrong login attempts for userId= " + userInfo.Id); | |
70 | - } | |
44 | + User userInfo = AIAHTML5.API.Models.Users.getUserDetails(credentials); | |
71 | 45 | |
72 | - //05. Now get the module list- for ADMIN (superadmin/ general admin) by default all module loads | |
73 | - GetModulesBasedOnUserType(userInfo); | |
46 | + if (userInfo != null) | |
47 | + { | |
48 | + // 02 Check user is authenticated or not by login credential match | |
49 | + bool isUserAuthenticated = AIAHTML5.API.Models.Users.checkUserAuthenticity(credentials, userInfo); | |
74 | 50 | |
75 | - // authenticationRepsonse = JsonConvert.SerializeObject(userInfo); | |
76 | - } | |
77 | - | |
78 | - else | |
51 | + if (isUserAuthenticated) | |
79 | 52 | { |
80 | - //compare block time of user with current time if user is blocked | |
81 | - DateTime blockDuration = blockTime.AddDays(1); | |
82 | - var difference = DateTime.Compare(DateTime.Now, blockDuration); | |
83 | - | |
84 | - //check if credentials are valid credentials | |
85 | - //bool isCorrectLoginId, isCorrectPassword; | |
86 | - //AIAHTML5.API.Models.Users.isCredentialCorrect(credentials, userInfo, out isCorrectLoginId, out isCorrectPassword); | |
87 | - | |
88 | - if (difference >= 0) | |
53 | + if (userInfo.IsActive) | |
54 | + { | |
55 | + //03. check if user is blocked | |
56 | + isUserBlocked = AIAHTML5.API.Models.Users.checkUserBlockStatus(userInfo.Id, out blockTime); | |
57 | + | |
58 | + if (!isUserBlocked) | |
89 | 59 | { |
90 | - //means 24 hours block time is finished | |
91 | - userInfo.IsBlocked = false; | |
60 | + //04.delete past wrong login attempts of user | |
61 | + int wrongAttemptDeteledCount = AIAHTML5.API.Models.Users.deletePastWrongAttempts(userInfo.Id); | |
62 | + if (wrongAttemptDeteledCount < 0) | |
63 | + { | |
64 | + logger.Fatal("Unable to delete past wrong login attempts for userId= " + userInfo.Id); | |
65 | + } | |
66 | + //05. | |
67 | + GetModulesBasedOnUserType(userInfo); | |
68 | + | |
69 | + // authenticationRepsonse = JsonConvert.SerializeObject(userInfo); | |
70 | + } | |
71 | + | |
72 | + else | |
73 | + { | |
74 | + | |
75 | + //compare block time of user with current time if user is blocked | |
76 | + DateTime blockDuration = blockTime.AddDays(1); | |
77 | + var difference = DateTime.Compare(DateTime.Now, blockDuration); | |
78 | + | |
79 | + //check if credentials are valid credentials | |
80 | + //bool isCorrectLoginId, isCorrectPassword; | |
81 | + //AIAHTML5.API.Models.Users.isCredentialCorrect(credentials, userInfo, out isCorrectLoginId, out isCorrectPassword); | |
82 | + | |
83 | + if (difference >= 0) | |
84 | + { | |
85 | + //means 24 hours block time is finished | |
86 | + userInfo.IsBlocked = false; | |
92 | 87 | |
93 | 88 | int wrongAttemptDeteledCount = AIAHTML5.API.Models.Users.deletePastWrongAttempts(userInfo.Id); |
94 | 89 | if (wrongAttemptDeteledCount < 0) |
... | ... | @@ -98,70 +93,69 @@ namespace AIAHTML5.API.Controllers |
98 | 93 | |
99 | 94 | //05. Now get the module list- for ADMIN (superadmin/ general admin) by default all module loads |
100 | 95 | GetModulesBasedOnUserType(userInfo); |
101 | - | |
102 | - } | |
103 | - else{ | |
104 | - userInfo.IsBlocked = true; | |
96 | + | |
97 | + } | |
98 | + else | |
99 | + { | |
100 | + userInfo.IsBlocked = true; | |
101 | + } | |
105 | 102 | } |
106 | - } | |
107 | - } | |
108 | - else | |
109 | - { | |
110 | - userInfo.LoginFailureCauseId = ErrorHelper.E_USER_NOT_ACTIVE; | |
111 | - } | |
112 | - } | |
113 | - | |
114 | - else | |
115 | - { | |
103 | + } | |
104 | + else | |
105 | + { | |
106 | + //CODE REVIW: validate that is this tarnslated by UI because we need to show message to user if he is inactive | |
107 | + userInfo.LoginFailureCauseId = ErrorHelper.E_USER_NOT_ACTIVE; | |
116 | 108 | |
109 | + //05.4 check the License expiration irespective of either user is active | |
110 | + //or not because on AIA, we shows the License expiration message | |
111 | + //for inactive users too | |
117 | 112 | |
118 | - //NIKITA. in this case user will come only when its is not authenticated and authenticity is checked based on userID and password | |
119 | - //and validating we have got record of user based on userd so this is the case when password is incorrect | |
120 | - userInfo.IsCorrectPassword = false; | |
121 | - if (userInfo.IsCorrectPassword == false) | |
122 | - { | |
123 | - // send message back to th UI that password is incorrect | |
124 | - // userInfo.IsCorrectPassword = false; | |
113 | + CheckLicenseStatus(userInfo); | |
125 | 114 | |
126 | - //get wrong attempt count of user | |
127 | - int previousIncorrectLoginAttempts = AIAHTML5.API.Models.Users.checkNoOfWrongAttempts(userInfo.Id); | |
128 | - userInfo.IncorrectLoginAttemptCount = previousIncorrectLoginAttempts + 1; | |
129 | - userInfo.LoginFailureCauseId = ErrorHelper.E_PASSWORD_NOT_MATCH; | |
115 | + } | |
116 | + } | |
117 | + | |
118 | + else | |
119 | + { | |
120 | + //get wrong attempt count of user | |
121 | + int previousIncorrectLoginAttempts = AIAHTML5.API.Models.Users.checkNoOfWrongAttempts(userInfo.Id); | |
122 | + userInfo.IncorrectLoginAttemptCount = previousIncorrectLoginAttempts + 1; | |
123 | + userInfo.LoginFailureCauseId = ErrorHelper.E_PASSWORD_NOT_MATCH; | |
130 | 124 | |
131 | - //01. insert wrong attempt in dtabase | |
132 | - int updateCount = AIAHTML5.API.Models.Users.saveWrongAttemptOfUser(userInfo.Id, previousIncorrectLoginAttempts); | |
125 | + //01. insert wrong attempt in dtabase | |
126 | + int updateCount = AIAHTML5.API.Models.Users.saveWrongAttemptOfUser(userInfo.Id, previousIncorrectLoginAttempts); | |
133 | 127 | |
134 | - if (updateCount < 0) | |
135 | - { | |
136 | - //Put the log in log file | |
137 | - logger.Fatal("Unable to Update past wrong login attempts for userId= " + userInfo.Id); | |
138 | - } | |
139 | - //else | |
140 | - //{ | |
141 | - if (userInfo.IncorrectLoginAttemptCount > 4) | |
142 | - { | |
143 | - userInfo.IsBlocked = true; | |
144 | - userInfo.LoginFailureCauseId = ErrorHelper.E_USER_ID_BLOCKED_24_HRS; | |
145 | - } | |
146 | - //} | |
147 | - } | |
128 | + if (updateCount < 0) | |
129 | + { | |
130 | + //Put the log in log file | |
131 | + logger.Fatal("Unable to Update past wrong login attempts for userId= " + userInfo.Id); | |
148 | 132 | } |
149 | - // unreachable code detected as license is null | |
150 | - //if (userInfo.License != null && !string.IsNullOrEmpty(userInfo.License.AccountNumber)) | |
133 | + //else | |
151 | 134 | //{ |
152 | - // int result = AIAHTML5.API.Models.Users.insertUserLoginLog(userInfo.License.AccountNumber, userInfo.LoginFailureCauseId, null, userInfo.EditionId.ToString(), null); | |
153 | - // if (result < 0) | |
154 | - // logger.Fatal("Unable to insert wrong attempt detail in UserLoginLog table for accountNumber= " + userInfo.License.AccountNumber); | |
135 | + if (userInfo.IncorrectLoginAttemptCount > 4) | |
136 | + { | |
137 | + userInfo.IsBlocked = true; | |
138 | + userInfo.LoginFailureCauseId = ErrorHelper.E_USER_ID_BLOCKED_24_HRS; | |
139 | + } | |
155 | 140 | //} |
156 | 141 | |
157 | - authenticationRepsonse = JsonConvert.SerializeObject(userInfo); | |
158 | - //} | |
159 | - } | |
160 | - | |
161 | - else | |
162 | - { | |
142 | + } | |
143 | + // unreachable code detected as license is null | |
144 | + //if (userInfo.License != null && !string.IsNullOrEmpty(userInfo.License.AccountNumber)) | |
145 | + //{ | |
146 | + // int result = AIAHTML5.API.Models.Users.insertUserLoginLog(userInfo.License.AccountNumber, userInfo.LoginFailureCauseId, null, userInfo.EditionId.ToString(), null); | |
147 | + // if (result < 0) | |
148 | + // logger.Fatal("Unable to insert wrong attempt detail in UserLoginLog table for accountNumber= " + userInfo.License.AccountNumber); | |
149 | + //} | |
150 | + | |
151 | + authenticationRepsonse = JsonConvert.SerializeObject(userInfo); | |
152 | + //} | |
153 | + } | |
154 | + | |
155 | + else | |
156 | + { | |
163 | 157 | authenticationRepsonse = AIAConstants.USER_NOT_FOUND; |
164 | - } | |
158 | + } | |
165 | 159 | } |
166 | 160 | catch (Exception e) |
167 | 161 | { |
... | ... | @@ -190,74 +184,85 @@ namespace AIAHTML5.API.Controllers |
190 | 184 | } |
191 | 185 | else |
192 | 186 | { |
193 | - //05.1 For normal user need to get the license details, get the license id for authenticated user | |
194 | - int licenseId, editionId; | |
195 | - AIAHTML5.API.Models.Users.getLicenseIdForThisUser(userInfo.Id, out licenseId, out editionId); | |
187 | + CheckLicenseStatus(userInfo); | |
196 | 188 | |
197 | - userInfo.LicenseId = licenseId; | |
198 | - userInfo.EditionId = editionId; | |
189 | + if(!userInfo.IsSubscriptionExpired){ | |
190 | + GetModulesBasedOnLicense(userInfo,false); | |
191 | + } | |
192 | + } | |
193 | + } | |
199 | 194 | |
200 | - //05.2 Check user is active or not | |
195 | + private static void CheckLicenseStatus(User userInfo) | |
196 | + { | |
197 | + //05.1 For normal user need to get the license details, get the license id for authenticated user | |
198 | + int licenseId, editionId; | |
199 | + AIAHTML5.API.Models.Users.getLicenseIdForThisUser(userInfo.Id, out licenseId, out editionId); | |
201 | 200 | |
201 | + userInfo.LicenseId = licenseId; | |
202 | + userInfo.EditionId = editionId; | |
202 | 203 | |
203 | - //05.3 get license details | |
204 | - userInfo.LicenseInfo = AIAHTML5.API.Models.Users.getLicenseDetails(userInfo.LicenseId); | |
204 | + //05.2 get license details | |
205 | + userInfo.LicenseInfo = AIAHTML5.API.Models.Users.getLicenseDetails(userInfo.LicenseId); | |
205 | 206 | |
206 | - // if (userInfo.LicenseInfo.Id > 0) | |
207 | - if (userInfo.LicenseInfo!= null) | |
208 | - { | |
209 | - //05.4 get licenseSubscription details | |
210 | - userInfo.LicenseSubscriptions = AIAHTML5.API.Models.Users.getLicenseSubscriptionDetails(userInfo.LicenseId); | |
207 | + if (userInfo.LicenseInfo != null) | |
208 | + { | |
209 | + //05.3 get licenseSubscription details | |
210 | + userInfo.LicenseSubscriptions = AIAHTML5.API.Models.Users.getLicenseSubscriptionDetails(userInfo.LicenseId); | |
211 | 211 | |
212 | - //05.5 check the License expiration irespective of either user is active or not because on AIA | |
213 | - //we shows the License expiration message for inactive users too | |
214 | - string expirationDate = null; | |
215 | - bool isLicenseExpired = false; | |
212 | + //05.4 check the License expiration irespective of either user is active or not because on AIA | |
213 | + //we shows the License expiration message for inactive users too | |
214 | + string expirationDate = null; | |
215 | + bool isLicenseExpired = false; | |
216 | 216 | |
217 | - if (userInfo.LicenseSubscriptions!= null) | |
218 | - { | |
219 | - isLicenseExpired = AIAHTML5.API.Models.Users.checkIfLicenseExpired(userInfo.LicenseSubscriptions, out expirationDate); | |
220 | - } | |
217 | + if (userInfo.LicenseSubscriptions != null) | |
218 | + { | |
219 | + isLicenseExpired = AIAHTML5.API.Models.Users.checkIfLicenseExpired(userInfo.LicenseSubscriptions, out expirationDate); | |
220 | + } | |
221 | + | |
222 | + if (isLicenseExpired) | |
223 | + { | |
224 | + userInfo.IsSubscriptionExpired = isLicenseExpired; | |
225 | + userInfo.SubscriptionExpirationDate = expirationDate; | |
226 | + } | |
227 | + } | |
228 | + | |
229 | + else | |
230 | + { | |
231 | + // Log The message that License Info Not found | |
232 | + } | |
233 | + } | |
221 | 234 | |
222 | - // send message to the UI for license expiration | |
223 | - //05.6 Check for subscription Expiration [Promoted for case if license inactive along with subscription expired] | |
224 | - if (isLicenseExpired) | |
235 | + private static void GetModulesBasedOnLicense(User userInfo, bool isLicenseExpired) | |
236 | + { | |
237 | + | |
238 | + //05.6.1 | |
239 | + if (userInfo.LicenseInfo.IsActive) | |
240 | + { | |
241 | + if (!userInfo.LicenseInfo.IsTermAccepted) | |
225 | 242 | { |
226 | - userInfo.IsSubscriptionExpired = isLicenseExpired; | |
227 | - userInfo.SubscriptionExpirationDate = expirationDate; | |
243 | + ArrayList termsList = AIAHTML5.API.Models.Users.getTermsAndConditions(); | |
244 | + foreach (Hashtable item in termsList) | |
245 | + { | |
246 | + userInfo.TermsAndConditionsTitle = item[AIAConstants.KEY_TITLE].ToString(); | |
247 | + userInfo.TermsAndConditionsText = item[AIAConstants.KEY_CONTENT].ToString(); | |
248 | + } | |
228 | 249 | } |
229 | 250 | else |
230 | 251 | { |
231 | - //05.6.1 | |
232 | - if (userInfo.LicenseInfo.IsActive) | |
233 | - { | |
234 | - if (!userInfo.LicenseInfo.IsTermAccepted) | |
235 | - { | |
236 | - ArrayList termsList = AIAHTML5.API.Models.Users.getTermsAndConditions(); | |
237 | - foreach (Hashtable item in termsList) | |
238 | - { | |
239 | - userInfo.TermsAndConditionsTitle = item[AIAConstants.KEY_TITLE].ToString(); | |
240 | - userInfo.TermsAndConditionsText = item[AIAConstants.KEY_CONTENT].ToString(); | |
241 | - } | |
242 | - } | |
243 | - else | |
244 | - { | |
245 | - userInfo.Modules = AIAHTML5.API.Models.Users.getModuleListByLicenseId(userInfo.LicenseId); | |
252 | + userInfo.Modules = AIAHTML5.API.Models.Users.getModuleListByLicenseId(userInfo.LicenseId); | |
246 | 253 | |
247 | - //Insert user login detail | |
248 | - AIAHTML5.API.Models.Users.insertLoginDetails(userInfo.Id); | |
249 | - } | |
250 | - } | |
251 | - else | |
252 | - { | |
253 | - userInfo.LoginFailureCauseId = ErrorHelper.E_LICENCE_IS_INACTIVE; | |
254 | - | |
255 | - } | |
254 | + //Insert user login detail | |
255 | + AIAHTML5.API.Models.Users.insertLoginDetails(userInfo.Id); | |
256 | 256 | } |
257 | 257 | } |
258 | + else | |
259 | + { | |
260 | + userInfo.LoginFailureCauseId = ErrorHelper.E_LICENCE_IS_INACTIVE; | |
261 | + | |
262 | + } | |
258 | 263 | } |
259 | 264 | } |
260 | - | |
265 | + | |
261 | 266 | |
262 | 267 | // PUT api/authenticate/5 |
263 | 268 | public void Put(int id, [FromBody]string value) | ... | ... |