diff --git a/400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs b/400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs
index 724c185..f077e3c 100644
--- a/400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs
+++ b/400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs
@@ -38,146 +38,285 @@ namespace AIAHTML5.API.Controllers
//01. check user is authenticated or not by login credential macth
//bool isUserAuthenticated = AIAHTML5.API.Models.Users.IsUserAuthenticated(credentials);
- //Above code commented to reduce dbhitting for same result set
-
+ //Above code commented to reduce db hitting for same result set
+ // get user details based on credentials provided
User userInfo = AIAHTML5.API.Models.Users.getUserDetails(credentials);
- //check is user authenticated
- bool isUserAuthenticated = AIAHTML5.API.Models.Users.IsUserAuthenticated(credentials, userInfo);
-
- if (isUserAuthenticated)
+ if (userInfo != null)
{
+ //check is user authenticated
+ bool isUserAuthenticated = AIAHTML5.API.Models.Users.IsUserAuthenticated(credentials, userInfo);
- //01. Get User details
- //userInfo = AIAHTML5.API.Models.Users.getUserDetails(credentials);
+ // check if user is blocked
+ DateTime blockTime;
+ bool isUserBlocked = AIAHTML5.API.Models.Users.isUserBlocked(userInfo.Id, out blockTime);
- //02. assigning isCorrectPassword to true 'required for internal processing'
- userInfo.IsCorrectPassword = true;
+ if (isUserAuthenticated && !isUserBlocked)
+ {
+ //01. Get User details
+ //userInfo = AIAHTML5.API.Models.Users.getUserDetails(credentials);
- //03.insert Log login details
- // Below statement executing irrespective of the fact user license inactive
- //AIAHTML5.API.Models.Users.insertLoginDetails(userInfo.Id);
+ //02. assigning isCorrectPassword to true 'required for internal processing'
+ userInfo.IsCorrectPassword = true;
- //04.delete past wrong login attempts of user
- int wrongAttemptDeteledCount = AIAHTML5.API.Models.Users.deletePastWrongAttempts(userInfo.Id);
- if (wrongAttemptDeteledCount <= 0)
- {
- logger.Fatal("Unable to delete past wrong login attempts for userId= " + userInfo.Id);
- }
+ //04.delete past wrong login attempts of user
+ int wrongAttemptDeteledCount = AIAHTML5.API.Models.Users.deletePastWrongAttempts(userInfo.Id);
+ if (wrongAttemptDeteledCount < 0)
+ {
+ logger.Fatal("Unable to delete past wrong login attempts for userId= " + userInfo.Id);
+ }
- //05. Now get the module list- for ADMIN (superadmin/ general admin) by default all module loads
- if (userInfo.UserType == AIAHTML5.API.Models.User.SUPER_ADMIN || userInfo.UserType == AIAHTML5.API.Models.User.GENERAL_ADMIN)
- {
- userInfo.Modules = AIAHTML5.API.Models.Users.getAllModulesList();
+ //05. Now get the module list- for ADMIN (superadmin/ general admin) by default all module loads
+ if (userInfo.UserType == AIAHTML5.API.Models.User.SUPER_ADMIN || userInfo.UserType == AIAHTML5.API.Models.User.GENERAL_ADMIN)
+ {
+ userInfo.Modules = AIAHTML5.API.Models.Users.getAllModulesList();
- //Insert user login detail
- AIAHTML5.API.Models.Users.insertLoginDetails(userInfo.Id);
- }
- else
- {
- //CORRECT CODE
- //05.1 For normal user need to get the license details, get the license id for aUTHENTICATED USER
- int licenseId, editionId;
- AIAHTML5.API.Models.Users.getLicenseIdForThisUser(userInfo.Id, out licenseId, out editionId);
+ //Insert user login detail
+ AIAHTML5.API.Models.Users.insertLoginDetails(userInfo.Id);
+ }
+ else
+ {
+ //05.1 For normal user need to get the license details, get the license id for authenticated user
+ int licenseId, editionId;
+ AIAHTML5.API.Models.Users.getLicenseIdForThisUser(userInfo.Id, out licenseId, out editionId);
- userInfo.LicenseId = licenseId;
- userInfo.EditionId = editionId;
+ userInfo.LicenseId = licenseId;
+ userInfo.EditionId = editionId;
- //05.2 Check user is active or not
-
+ //05.2 Check user is active or not
- //05.3 get license/ licenseSubscription details
- userInfo.LicenseInfo = AIAHTML5.API.Models.Users.getLicenseDetails(userInfo.LicenseId);
- //05.4
- userInfo.LicenseSubscriptions = AIAHTML5.API.Models.Users.getLicenseSubscriptionDetails(userInfo.LicenseId);
+ //05.3 get license details
+ userInfo.LicenseInfo = AIAHTML5.API.Models.Users.getLicenseDetails(userInfo.LicenseId);
- //05.5 check the License expiration irespective of either user is active or not because on AIA
- //we shows the License expiration message for inactive users too
- string expirationDate = null;
+ //05.4 get licenseSubscription details
+ userInfo.LicenseSubscriptions = AIAHTML5.API.Models.Users.getLicenseSubscriptionDetails(userInfo.LicenseId);
- bool isLicenseExpired = AIAHTML5.API.Models.Users.checkIfLicenseExpired(userInfo.LicenseSubscriptions, out expirationDate);
+ //05.5 check the License expiration irespective of either user is active or not because on AIA
+ //we shows the License expiration message for inactive users too
+ string expirationDate = null;
- // send message to the UI for license expiration
- //05.6 Check for subscription Expiration [Promoted for case if license inactive along with subscription expired]
- if (isLicenseExpired)
- {
- userInfo.IsSubscriptionExpired = isLicenseExpired;
- userInfo.SubscriptionExpirationDate = expirationDate;
- }
- else
- {
- //05.6.1
- if (userInfo.LicenseInfo.IsActive)
+ bool isLicenseExpired = AIAHTML5.API.Models.Users.checkIfLicenseExpired(userInfo.LicenseSubscriptions, out expirationDate);
+
+ // send message to the UI for license expiration
+ //05.6 Check for subscription Expiration [Promoted for case if license inactive along with subscription expired]
+ if (isLicenseExpired)
+ {
+ userInfo.IsSubscriptionExpired = isLicenseExpired;
+ userInfo.SubscriptionExpirationDate = expirationDate;
+ }
+ else
{
- if (!userInfo.LicenseInfo.IsTermAccepted)
+ //05.6.1
+ if (userInfo.LicenseInfo.IsActive)
{
- ArrayList termsList = AIAHTML5.API.Models.Users.getTermsOfServiceText();
- foreach (Hashtable item in termsList)
+ if (!userInfo.LicenseInfo.IsTermAccepted)
+ {
+ ArrayList termsList = AIAHTML5.API.Models.Users.getTermsOfServiceText();
+ foreach (Hashtable item in termsList)
+ {
+ userInfo.TermsOfServiceTitle = item["title"].ToString();
+ userInfo.TermsOfServiceText = item["content"].ToString();
+ }
+ }
+ else
{
- userInfo.TermsOfServiceTitle = item["title"].ToString();
- userInfo.TermsOfServiceText = item["content"].ToString();
+ userInfo.Modules = AIAHTML5.API.Models.Users.getModuleListByLicenseId(userInfo.LicenseId);
+
+ //Insert user login detail
+ AIAHTML5.API.Models.Users.insertLoginDetails(userInfo.Id);
}
}
else
{
- userInfo.Modules = AIAHTML5.API.Models.Users.getModuleListByLicenseId(userInfo.LicenseId);
+ //05.6.1.1
+ // return message of license inactive
+ // property value assigned. Separate return statement not required
- //Insert user login detail
- AIAHTML5.API.Models.Users.insertLoginDetails(userInfo.Id);
}
- }
- else
- {
- //05.6.1.1
- // return message of license inactive
- // property value assigned. Separate return statement not required
}
-
}
- }
- authenticationRepsonse = JsonConvert.SerializeObject(userInfo);
- }
- else
- {
- bool isCorrectLoginId, isCorrectPassword;
- AIAHTML5.API.Models.Users.isCredentialCorrect(credentials, out isCorrectLoginId, out isCorrectPassword);
-
- if (!isCorrectLoginId)
- {
- // send message back to th UI that login id is incorrect
- authenticationRepsonse = AIAConstants.USER_NOT_FOUND;
+ authenticationRepsonse = JsonConvert.SerializeObject(userInfo);
}
else
{
- //getting userDetails
- userInfo = AIAHTML5.API.Models.Users.getUserDetails(credentials);
+ //compare block time of user with current time if user is blocked
+ DateTime blockDuration = blockTime.AddDays(1);
+ var difference = DateTime.Compare(DateTime.Now, blockDuration);
- if (!isCorrectPassword)
+ //check if credentials are valid credentials
+ bool isCorrectLoginId, isCorrectPassword;
+ AIAHTML5.API.Models.Users.isCredentialCorrect(credentials, out isCorrectLoginId, out isCorrectPassword);
+
+ if (isUserBlocked)
{
- // send message back to th UI that password is incorrect
- userInfo.IsCorrectPassword = false;
+ if (difference >= 0)
+ {
+ if (isCorrectPassword)
+ {
+ userInfo.IsBlocked = false;
+ userInfo.IsCorrectPassword = true;
- //get wrong attempt count of user
- userInfo.IncorrectLoginAttemptCount = AIAHTML5.API.Models.Users.checkNoOfWrongAttempts(userInfo.Id) +1;
- userInfo.LoginFailureCauseId = ErrorHelper.E_PASSWORD_NOT_MATCH;
+ int wrongAttemptDeteledCount = AIAHTML5.API.Models.Users.deletePastWrongAttempts(userInfo.Id);
+ if (wrongAttemptDeteledCount < 0)
+ {
+ logger.Fatal("Unable to delete past wrong login attempts for userId= " + userInfo.Id);
+ }
- //01. insert wrong attempt in dtabase
- int updateCount = AIAHTML5.API.Models.Users.saveWrongAttemptofUser(userInfo.Id);
+ //05. Now get the module list- for ADMIN (superadmin/ general admin) by default all module loads
+
+ if (userInfo.UserType == AIAHTML5.API.Models.User.SUPER_ADMIN || userInfo.UserType == AIAHTML5.API.Models.User.GENERAL_ADMIN)
+ {
+ userInfo.Modules = AIAHTML5.API.Models.Users.getAllModulesList();
+
+ //Insert user login detail
+ AIAHTML5.API.Models.Users.insertLoginDetails(userInfo.Id);
+ }
+ else
+ {
+ //05.1 For normal user need to get the license details, get the license id for aUTHENTICATED USER
+ int licenseId, editionId;
+ AIAHTML5.API.Models.Users.getLicenseIdForThisUser(userInfo.Id, out licenseId, out editionId);
+
+ userInfo.LicenseId = licenseId;
+ userInfo.EditionId = editionId;
+
+ //05.2 Check user is active or not
+
+
+ //05.3 get license/ licenseSubscription details
+ userInfo.LicenseInfo = AIAHTML5.API.Models.Users.getLicenseDetails(userInfo.LicenseId);
+
+ //05.4
+ userInfo.LicenseSubscriptions = AIAHTML5.API.Models.Users.getLicenseSubscriptionDetails(userInfo.LicenseId);
+
+ //05.5 check the License expiration irespective of either user is active or not because on AIA
+ //we shows the License expiration message for inactive users too
+ string expirationDate = null;
+
+ bool isLicenseExpired = AIAHTML5.API.Models.Users.checkIfLicenseExpired(userInfo.LicenseSubscriptions, out expirationDate);
+
+ // send message to the UI for license expiration
+ //05.6 Check for subscription Expiration [Promoted for case if license inactive along with subscription expired]
+ if (isLicenseExpired)
+ {
+ userInfo.IsSubscriptionExpired = isLicenseExpired;
+ userInfo.SubscriptionExpirationDate = expirationDate;
+ }
+ else
+ {
+ //05.6.1
+ if (userInfo.LicenseInfo.IsActive)
+ {
+ if (!userInfo.LicenseInfo.IsTermAccepted)
+ {
+ ArrayList termsList = AIAHTML5.API.Models.Users.getTermsOfServiceText();
+ foreach (Hashtable item in termsList)
+ {
+ userInfo.TermsOfServiceTitle = item["title"].ToString();
+ userInfo.TermsOfServiceText = item["content"].ToString();
+ }
+ }
+ else
+ {
+ userInfo.Modules = AIAHTML5.API.Models.Users.getModuleListByLicenseId(userInfo.LicenseId);
+
+ //Insert user login detail
+ AIAHTML5.API.Models.Users.insertLoginDetails(userInfo.Id);
+ }
+ }
+ else
+ {
+ //05.6.1.1
+ // return message of license inactive
+ // property value assigned. Separate return statement not required
+
+ }
+
+ }
+ }
+ }
+ else
+ {
+ int wrongAttemptDeteledCount = AIAHTML5.API.Models.Users.deletePastWrongAttempts(userInfo.Id);
+ if (wrongAttemptDeteledCount < 0)
+ {
+ logger.Fatal("Unable to delete past wrong login attempts for userId= " + userInfo.Id);
+ }
+
+ // send message back to th UI that password is incorrect
+ userInfo.IsCorrectPassword = false;
+
+ //get wrong attempt count of user
+ userInfo.IncorrectLoginAttemptCount = AIAHTML5.API.Models.Users.checkNoOfWrongAttempts(userInfo.Id) + 1;
+ userInfo.LoginFailureCauseId = ErrorHelper.E_PASSWORD_NOT_MATCH;
+
+ //01. insert wrong attempt in dtabase
+ int updateCount = AIAHTML5.API.Models.Users.saveWrongAttemptofUser(userInfo.Id);
+
+ if (updateCount < 0)
+ {
+ //Put the log in log file
+ logger.Fatal("Unable to Update past wrong login attempts for userId= " + userInfo.Id);
+ }
+ else
+ {
+ if (userInfo.IncorrectLoginAttemptCount > 4)
+ {
+ userInfo.IsBlocked = true;
+ userInfo.LoginFailureCauseId = ErrorHelper.E_USER_ID_BLOCKED_24_HRS;
+ }
+ }
+
+ }
- if (updateCount < 0)
- {
- //Put the log in log file
- logger.Fatal("Unable to Update past wrong login attempts for userId= " + userInfo.Id);
}
else
{
- if (userInfo.IncorrectLoginAttemptCount > 4)
+ userInfo.IsBlocked = true;
+ }
+ }
+
+ else
+ {
+
+ //bool isCorrectLoginId, isCorrectPassword;
+ //AIAHTML5.API.Models.Users.isCredentialCorrect(credentials, out isCorrectLoginId, out isCorrectPassword);
+
+ //below code commented as way of retrieving data changed 'very first line in this method'
+ //if (!isCorrectLoginId)
+ //{
+ // // send message back to th UI that login id is incorrect
+ // authenticationRepsonse = AIAConstants.USER_NOT_FOUND;
+ //}
+ //else
+ //{
+ if (!isCorrectPassword)
+ {
+ // send message back to th UI that password is incorrect
+ userInfo.IsCorrectPassword = false;
+
+ //get wrong attempt count of user
+ userInfo.IncorrectLoginAttemptCount = AIAHTML5.API.Models.Users.checkNoOfWrongAttempts(userInfo.Id) + 1;
+ userInfo.LoginFailureCauseId = ErrorHelper.E_PASSWORD_NOT_MATCH;
+
+ //01. insert wrong attempt in dtabase
+ int updateCount = AIAHTML5.API.Models.Users.saveWrongAttemptofUser(userInfo.Id);
+
+ if (updateCount < 0)
{
- userInfo.IsBlocked = true;
- userInfo.LoginFailureCauseId = ErrorHelper.E_USER_ID_BLOCKED_24_HRS;
+ //Put the log in log file
+ logger.Fatal("Unable to Update past wrong login attempts for userId= " + userInfo.Id);
+ }
+ else
+ {
+ if (userInfo.IncorrectLoginAttemptCount > 4)
+ {
+ userInfo.IsBlocked = true;
+ userInfo.LoginFailureCauseId = ErrorHelper.E_USER_ID_BLOCKED_24_HRS;
+ }
}
}
}
@@ -190,8 +329,13 @@ namespace AIAHTML5.API.Controllers
//}
authenticationRepsonse = JsonConvert.SerializeObject(userInfo);
+ //}
}
}
+ else
+ {
+ authenticationRepsonse = AIAConstants.USER_NOT_FOUND;
+ }
//if (Convert.ToString(authenticationRepsonse) != AIAConstants.USER_NOT_FOUND && Convert.ToString(authenticationRepsonse) != AIAConstants.ERROR_IN_FECTHING_DETAILS && Convert.ToString(authenticationRepsonse)!= AIAConstants.SQL_CONNECTION_ERROR)
//{
diff --git a/400-SOURCECODE/AIAHTML5.API/Models/Users.cs b/400-SOURCECODE/AIAHTML5.API/Models/Users.cs
index a395b4d..943ce1f 100644
--- a/400-SOURCECODE/AIAHTML5.API/Models/Users.cs
+++ b/400-SOURCECODE/AIAHTML5.API/Models/Users.cs
@@ -219,13 +219,19 @@ namespace AIAHTML5.API.Models
ArrayList arrLicense = new ArrayList();
DBModel objModel = new DBModel();
Hashtable licenseEditionHash = objModel.GetLicenseDetailByUserId(userId);
- foreach (DictionaryEntry de in licenseEditionHash)
- {
- if (de.Key.ToString() == AIAConstants.LICENSE_KEY_ID)
- licenseId = Convert.ToInt32(de.Value);
- if (de.Key.ToString() == AIAConstants.EDITION_KEY_ID)
- editionId = Convert.ToInt32(de.Value);
- }
+
+ if (licenseEditionHash.ContainsKey(AIAConstants.LICENSE_KEY_ID))
+ licenseId = Convert.ToInt32(licenseEditionHash[AIAConstants.LICENSE_KEY_ID]);
+
+ if (licenseEditionHash.ContainsKey(AIAConstants.EDITION_KEY_ID))
+ editionId = Convert.ToInt32(licenseEditionHash[AIAConstants.EDITION_KEY_ID]);
+ //foreach (DictionaryEntry de in licenseEditionHash)
+ //{
+ // if (de.Key.ToString() == AIAConstants.LICENSE_KEY_ID)
+ // licenseId = Convert.ToInt32(de.Value);
+ // if (de.Key.ToString() == AIAConstants.EDITION_KEY_ID)
+ // editionId = Convert.ToInt32(de.Value);
+ //}
}
internal static int insertLoginDetails(int userId)
@@ -385,5 +391,20 @@ namespace AIAHTML5.API.Models
return modulesList;
}
+
+ internal static bool isUserBlocked(int userId, out DateTime blockTime)
+ {
+ blockTime = new DateTime();
+ DBModel objModel = new DBModel();
+ BlockedUser blockedUser = objModel.GetBlockedUserByUserId(userId);
+
+ if (blockedUser != null)
+ {
+ blockTime = blockedUser.LoginTime;
+ return true;
+ }
+ else
+ return false;
+ }
}
}
\ No newline at end of file