Commit 196259b76b6588b0be20f7d01e5aa6c231bad03d

Authored by Utkarsh Singh
1 parent 1ff541b2

Committing updated restructured code

150-DOCUMENTATION/002-DBScripts/GetUserModulesByLicenseId.sql 0 → 100644
  1 +-- =============================================
  2 +-- Author: <Author,,Name>
  3 +-- Create date: <Create Date,,>
  4 +-- Description: <Description,,>
  5 +-- =============================================
  6 +CREATE PROCEDURE [dbo].[GetUserModulesByLicenseId]
  7 + -- Add the parameters for the stored procedure here
  8 + @iLicenseId int
  9 +AS
  10 +BEGIN
  11 + IF 1=0 BEGIN
  12 + SET FMTONLY OFF
  13 + END
  14 + -- SET NOCOUNT ON added to prevent extra result sets from
  15 + -- interfering with SELECT statements.
  16 + SET NOCOUNT ON;
  17 +
  18 + -- Insert statements for procedure here
  19 + SELECT ResourceModule.Id,ResourceModule.Title, ResourceModule.Slug
  20 + FROM ResourceModule
  21 + INNER JOIN ModuleToLicense ON ResourceModule.Id = ModuleToLicense.ModuleId
  22 + WHERE ModuleToLicense.Status = 1
  23 + AND ModuleToLicense.LicenseId = @iLicenseId
  24 +
  25 +END
0 26 \ No newline at end of file
... ...
400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs
... ... @@ -38,70 +38,81 @@ 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   - User objUser = new Models.User();
  41 + User userInfo = new Models.User();
42 42  
43 43 //02. Get User details
44   - objUser = AIAHTML5.API.Models.Users.getUserDetails(credentials);
  44 + userInfo = AIAHTML5.API.Models.Users.getUserDetails(credentials);
45 45  
46 46 if(isUserAuthenticated)
47 47 {
  48 + //04.insert Log login details
  49 + AIAHTML5.API.Models.Users.insertLoginDetails(userInfo.Id);
  50 +
48 51 //03.delete past wrong login attempts of user
49   - objUser.IsCorrectPassword = true;
50   - int wrongAttemptDeteledCount = AIAHTML5.API.Models.Users.deletePastWrongAttempts(objUser.Id);
  52 + userInfo.IsCorrectLoginId = true;
  53 + userInfo.IsCorrectPassword = true;
  54 +
  55 + int wrongAttemptDeteledCount = AIAHTML5.API.Models.Users.deletePastWrongAttempts(userInfo.Id);
51 56 if (wrongAttemptDeteledCount < 0)
52 57 {
53   - logger.Fatal("Unable to delete past wrong login attempts for userId= "+objUser.Id);
  58 + logger.Fatal("Unable to delete past wrong login attempts for userId= "+userInfo.Id);
54 59 }
55 60  
56   - if (objUser.UserType == AIAHTML5.API.Models.User.SUPER_ADMIN || objUser.UserType == AIAHTML5.API.Models.User.GENERAL_ADMIN)
  61 + // for ADMIN (superadmin/ general admin) users by default all module loads
  62 + if (userInfo.UserType == AIAHTML5.API.Models.User.SUPER_ADMIN || userInfo.UserType == AIAHTML5.API.Models.User.GENERAL_ADMIN)
57 63 {
58   - objUser.Modules = AIAHTML5.API.Models.Users.getAllModulesList();
59   - AIAHTML5.API.Models.Users.insertLoginDetails(objUser.Id);
  64 + userInfo.Modules = AIAHTML5.API.Models.Users.getAllModulesList();
  65 +
60 66 }
61 67 else
62 68 {
63 69 //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   -
  70 + userInfo.LicenseId = AIAHTML5.API.Models.Users.getLicenseIdForThisUser(userInfo.Id, "license");
  71 + userInfo.EditionId = AIAHTML5.API.Models.Users.getLicenseIdForThisUser(userInfo.Id, "edition");
  72 +
71 73 //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
  74 + // Below statement required as tl says it is required for better code readability
  75 + userInfo.IsActive = userInfo.IsActive;
73 76  
74   - //if (objUser.IsActive)
75   - //{ //Commenting as Inactive userid returns from here
76   - //5.1 check the License expiration
  77 +
  78 + //5.1 get license/ licenseSubscription details
77 79 //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);
  80 + userInfo.License = AIAHTML5.API.Models.Users.getLicenseDetails(userInfo.LicenseId);
  81 + userInfo.LicenseSubscriptions = AIAHTML5.API.Models.Users.getLicenseSubscriptionDetails(userInfo.LicenseId);
  82 +
  83 + //5.2 check the License expiration irespective of either user is active or not because on AIA
  84 + //we shows the License expiration message for inactive users too
  85 + bool isLicenseSubscriptionExpired = false;
  86 + string expirationDate = AIAHTML5.API.Models.Users.getLicenseExpirationDate(userInfo.LicenseId,out isLicenseSubscriptionExpired);
81 87  
  88 + // send message to the UI for license expiration
82 89 //5.2 Check for subscription Expiration [Promoted for case if license inactive along with subscription expired]
83   - if (!string.IsNullOrEmpty(objUser.SubscriptionExpirationDateString))
  90 + if (isLicenseSubscriptionExpired)
84 91 {
85   - objUser.IsSubscriptionExpired = true;
  92 + userInfo.IsSubscriptionExpired = isLicenseSubscriptionExpired;
  93 + userInfo.SubscriptionExpirationDate = expirationDate;
86 94 }
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);
  95 +
  96 + if (userInfo.License.IsActive)
  97 + {
  98 + //Insert user login details
  99 + //AIAHTML5.API.Models.Users.insertLoginDetails(objUser.Id);
94 100  
95   - if (!objUser.License.IsTermAccepted)
96   - {
97   - ArrayList termsList = AIAHTML5.API.Models.Users.getTermsOfServiceText();
98   - foreach (Hashtable item in termsList)
  101 + if (!userInfo.License.IsTermAccepted)
  102 + {
  103 + ArrayList termsList = AIAHTML5.API.Models.Users.getTermsOfServiceText();
  104 + foreach (Hashtable item in termsList)
  105 + {
  106 + userInfo.TermsOfServiceTitle = item["title"].ToString();
  107 + userInfo.TermsOfServiceText = item["content"].ToString();
  108 + }
  109 + }
  110 + else
99 111 {
100   - objUser.TermsOfServiceTitle = item["title"].ToString();
101   - objUser.TermsOfServiceText = item["content"].ToString();
  112 + userInfo.Modules = AIAHTML5.API.Models.Users.getModuleListByLicenseId(userInfo.LicenseId);
102 113 }
103 114 }
104   - }
  115 +
105 116 //else
106 117 //{
107 118 // //6.
... ... @@ -119,34 +130,38 @@ namespace AIAHTML5.API.Controllers
119 130 }
120 131 else
121 132 {
122   - bool isCorrectLoginId = AIAHTML5.API.Models.Users.isCredentialCorrect(credentials, objUser, "loginId");
123   - //bool isCorrectPassword = AIAHTML5.API.Models.Users.isCredentialCorrect(credentials, userInfo, "password");
  133 + bool isCorrectLoginId = AIAHTML5.API.Models.Users.isCredentialCorrect(credentials, userInfo, "loginId");
124 134  
125 135 if (!isCorrectLoginId)
126 136 {
127   - objUser = null;
  137 + // send message back to th UI that login id is incorrect
  138 + userInfo.IsCorrectLoginId = isCorrectLoginId;
128 139 }
129 140 else
130 141 {
131   - objUser.IsCorrectPassword = false;
132   - objUser.IncorrectLoginAttemptCount = AIAHTML5.API.Models.Users.checkNoOfWrongAttempts(objUser.Id) + 1;
133   - objUser.LoginFailureCauseId = ErrorHelper.E_PASSWORD_NOT_MATCH;
134   - //01. insert wrong attempt in dtabase
135   - if (objUser.IncorrectLoginAttemptCount == 1)
136   - {
137   - int insertedCount = AIAHTML5.API.Models.Users.insertWrongAttemptofUser(objUser.Id);
138   - }
139   - else
  142 + userInfo.IsCorrectLoginId = true;
  143 + bool isCorrectPassword = AIAHTML5.API.Models.Users.isCredentialCorrect(credentials, userInfo, "password");
  144 +
  145 + if (!isCorrectPassword)
140 146 {
141   - int updateCount = AIAHTML5.API.Models.Users.saveWrongAttemptofUser(objUser.Id);
  147 + // send message back to th UI that password is incorrect
  148 + userInfo.IsCorrectPassword = false;
  149 +
  150 + //get wrong attempt count of user
  151 + userInfo.IncorrectLoginAttemptCount = AIAHTML5.API.Models.Users.checkNoOfWrongAttempts(userInfo.Id) + 1;
  152 + userInfo.LoginFailureCauseId = ErrorHelper.E_PASSWORD_NOT_MATCH;
  153 +
  154 + //01. insert wrong attempt in dtabase
  155 + int updateCount = AIAHTML5.API.Models.Users.saveWrongAttemptofUser(userInfo.Id);
  156 +
142 157 if (updateCount < 0)
143 158 {
144 159 //Put the log in log file
145   - logger.Fatal("Unable to Update past wrong login attempts for userId= " + objUser.Id);
  160 + logger.Fatal("Unable to Update past wrong login attempts for userId= " + userInfo.Id);
146 161 }
147 162 else
148 163 {
149   -
  164 +
150 165 //02. check no of wrong attempts
151 166 //userInfo.IncorrectLoginAttemptCount = AIAHTML5.API.Models.Users.checkNoOfWrongAttempts(userInfo.Id);
152 167 //if (userInfo.IncorrectLoginAttemptCount >= 5)
... ... @@ -159,24 +174,25 @@ namespace AIAHTML5.API.Controllers
159 174 // // send message back to UI for login fail
160 175 //}
161 176  
162   - if (objUser.IncorrectLoginAttemptCount > 4)
  177 + if (userInfo.IncorrectLoginAttemptCount > 4)
163 178 {
164   - objUser.IsBlocked = true;
165   - objUser.LoginFailureCauseId = ErrorHelper.E_USER_ID_BLOCKED_24_HRS;
  179 + userInfo.IsBlocked = true;
  180 + userInfo.LoginFailureCauseId = ErrorHelper.E_USER_ID_BLOCKED_24_HRS;
166 181 }
167 182 }
168 183 }
169   - //if (objUser.License != null && !string.IsNullOrEmpty(objUser.License.AccountNumber))
  184 + // unreachable code detected as license is null
  185 + //if (userInfo.License != null && !string.IsNullOrEmpty(userInfo.License.AccountNumber))
170 186 //{
171   - // int result = AIAHTML5.API.Models.Users.insertUserLoginLog(objUser.License.AccountNumber, objUser.LoginFailureCauseId, null, objUser.EditionId.ToString(), null);
  187 + // int result = AIAHTML5.API.Models.Users.insertUserLoginLog(userInfo.License.AccountNumber, userInfo.LoginFailureCauseId, null, userInfo.EditionId.ToString(), null);
172 188 // if (result < 0)
173   - // logger.Fatal("Unable to insert wrong attempt detail in UserLoginLog table for accountNumber= " + objUser.License.AccountNumber);
  189 + // logger.Fatal("Unable to insert wrong attempt detail in UserLoginLog table for accountNumber= " + userInfo.License.AccountNumber);
174 190 //}
175 191 }
176 192 }
177 193  
178   - if(objUser!=null)
179   - authenticationRepsonse = JsonConvert.SerializeObject(objUser);
  194 + if(userInfo.IsCorrectLoginId)
  195 + authenticationRepsonse = JsonConvert.SerializeObject(userInfo);
180 196 else
181 197 authenticationRepsonse = AIAConstants.USER_NOT_FOUND;
182 198  
... ...
400-SOURCECODE/AIAHTML5.API/Controllers/LicenseTermConditionController.cs
... ... @@ -8,6 +8,7 @@ using log4net;
8 8 using AIAHTML5.API.Constants;
9 9 using Newtonsoft.Json;
10 10 using Newtonsoft.Json.Linq;
  11 +using AIAHTML5.API.Models;
11 12  
12 13 namespace AIAHTML5.API.Controllers
13 14 {
... ... @@ -26,19 +27,30 @@ namespace AIAHTML5.API.Controllers
26 27 }
27 28  
28 29 // POST api/licensetermcondition
29   - public HttpResponseMessage Post([FromBody]string licenseeAccountNumber)
  30 + public HttpResponseMessage Post([FromBody]JObject userLicenseInfo)
30 31 {
31 32 ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
32 33 logger.Debug("inside POST");
33 34 HttpResponseMessage response = null;
34 35  
35   - dynamic result = AIAHTML5.API.Models.Users.UpdateLicenseTerm(licenseeAccountNumber);
  36 + int licenseId = Convert.ToInt32(userLicenseInfo["userLicenseId"]);
  37 + User user = new User();
  38 + dynamic userModules = null; // assigned to avoid unassigned local variable compilation error;
  39 +
  40 + dynamic result = AIAHTML5.API.Models.Users.UpdateLicenseTerm(userLicenseInfo);
36 41 if (Convert.ToString(result) != AIAConstants.SQL_CONNECTION_ERROR)
37 42 {
38 43 if (Convert.ToInt32(result) > 0)
39   - response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.LICENSE_TERM_CONDITION_UPDATE_SUCCESS) };
  44 + {
  45 + user.Modules = Users.getModuleListByLicenseId(licenseId);
  46 + userModules = JsonConvert.SerializeObject(user);
  47 +
  48 + response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(userModules) };
  49 + }
40 50 else
  51 + {
41 52 response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.LICENSE_TERM_CONDITION_UPDATE_FAILED) };
  53 + }
42 54 }
43 55 else
44 56 {
... ...