diff --git a/400-SOURCECODE/AIAHTML5.API/AIAHTML5.API.csproj b/400-SOURCECODE/AIAHTML5.API/AIAHTML5.API.csproj
index 7291cd2..3fffdac 100644
--- a/400-SOURCECODE/AIAHTML5.API/AIAHTML5.API.csproj
+++ b/400-SOURCECODE/AIAHTML5.API/AIAHTML5.API.csproj
@@ -108,6 +108,7 @@
+
diff --git a/400-SOURCECODE/AIAHTML5.API/Constants/AIAConstants.cs b/400-SOURCECODE/AIAHTML5.API/Constants/AIAConstants.cs
index f37b114..ea87561 100644
--- a/400-SOURCECODE/AIAHTML5.API/Constants/AIAConstants.cs
+++ b/400-SOURCECODE/AIAHTML5.API/Constants/AIAConstants.cs
@@ -18,10 +18,6 @@ namespace AIAHTML5.API.Constants
public const string KEY_NAME = "name";
public const string KEY_SLUG = "slug";
public const string KEY_DESCRIPTION = "Description";
- public const string KEY_LICENSE = "LICENSE";
- public const string KEY_EDITION = "EDITION";
- public const string KEY_LOGINID = "LOGINID";
- public const string KEY_PASSWORD = "PASSWORD";
public const string PASSWORD_UPDATE_SUCCESS = "Password updated successfully";
public const string PASSWORD_UPDATE_FAILED = "Password update failed";
diff --git a/400-SOURCECODE/AIAHTML5.API/Constants/DBConstants.cs b/400-SOURCECODE/AIAHTML5.API/Constants/DBConstants.cs
new file mode 100644
index 0000000..1e75e3c
--- /dev/null
+++ b/400-SOURCECODE/AIAHTML5.API/Constants/DBConstants.cs
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+
+namespace AIAHTML5.API.Constants
+{
+ public class DBConstants
+ {
+ public const string GET_ALL_MODULES = "GetAllModuleStatusWithSlug";
+ public const string GET_USER_DELAILS_BY_LOGIN_ID = "GetUserDetailsByLoginId";
+ public const string GET_LICENSE_DETAILS_BY_USER_ID = "GetLicenseDetailByUserId";
+ public const string GET_USER_MODULES_BY_LICENSE_ID = "GetUserModulesByLicenseId";
+ public const string GET_USER_DETAILS_BY_EMAILID = "GetUserInfoByEmailId";
+
+ public const string UPDATE_USER_PASSWORD = "UpdateUserPassword";
+ public const string GET_SUBSCRIPTION_DETAILS_BY_LICENSE_ID = "GetSubscriptionDetailsByLicenseId";
+ public const string GET_LICENSE_DETAILS_BY_ID = "GetLicenseDetailsById";
+ public const string UPDATE_LICENSE_TERM_STATUS = "UpdateLicenseTermAcceptedStatus";
+ public const string GET_TERMS_OF_SERVICE_TEXT = "GetTermsOfServiceText";
+ public const string INSERT_LOGIN_DETAIL = "InsertLoginDetail";
+ public const string INSERT_INCORRECT_LOGIN_ATTEMPTS = "InsertIncorrectLoginAttempt";
+ public const string GET_INCORRECT_LOGIN_ATTEMPTS = "GetIncorrectLoginAttempt";
+ public const string UPDATE_INCORRECT_LOGIN_ATTEMPTS = "UpdateIncorrectLoginAttempts";
+ public const string DELETE_INCORRECT_LOGIN_ATTEMPTS = "DeleteIncorrectLoginAttempts";
+ public const string GET_ALL_LOGIN_FAILURE_CAUSES = "GetAllLoginFailureCauses";
+ public const string INSERT_LOGIN_ERROR_LOG = "InsertLoginErrorLog";
+ public const string GET_BLOCKED_USER_BY_USER_ID = "GetBlockedUserByUserId";
+ public const string GET_BLOCKED_USERS_BY_USER_TYPE = "GetBlockedUserByUserType";
+ }
+}
\ No newline at end of file
diff --git a/400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs b/400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs
index 2892170..724c185 100644
--- a/400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs
+++ b/400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs
@@ -34,113 +34,126 @@ namespace AIAHTML5.API.Controllers
logger.Debug("inside POST");
dynamic authenticationRepsonse;
-
+
//01. check user is authenticated or not by login credential macth
- bool isUserAuthenticated = AIAHTML5.API.Models.Users.IsUserAuthenticated(credentials);
+ //bool isUserAuthenticated = AIAHTML5.API.Models.Users.IsUserAuthenticated(credentials);
+
+ //Above code commented to reduce dbhitting for same result set
- User userInfo = new Models.User();
+ User userInfo = AIAHTML5.API.Models.Users.getUserDetails(credentials);
+ //check is user authenticated
+ bool isUserAuthenticated = AIAHTML5.API.Models.Users.IsUserAuthenticated(credentials, userInfo);
- //02. Get User details
- userInfo = AIAHTML5.API.Models.Users.getUserDetails(credentials);
- if(isUserAuthenticated)
+ if (isUserAuthenticated)
{
- //04.insert Log login details
- AIAHTML5.API.Models.Users.insertLoginDetails(userInfo.Id);
- //03.delete past wrong login attempts of user
- userInfo.IsCorrectLoginId = true;
+ //01. Get User details
+ //userInfo = AIAHTML5.API.Models.Users.getUserDetails(credentials);
+
+ //02. assigning isCorrectPassword to true 'required for internal processing'
userInfo.IsCorrectPassword = true;
- int wrongAttemptDeteledCount = AIAHTML5.API.Models.Users.deletePastWrongAttempts(userInfo.Id);
- if (wrongAttemptDeteledCount < 0)
+ //03.insert Log login details
+ // Below statement executing irrespective of the fact user license inactive
+ //AIAHTML5.API.Models.Users.insertLoginDetails(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);
+ logger.Fatal("Unable to delete past wrong login attempts for userId= " + userInfo.Id);
}
- // for ADMIN (superadmin/ general admin) users by default all module loads
+ //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
{
- //03. get the license id for aUTHENTICATED USER
- userInfo.LicenseId = AIAHTML5.API.Models.Users.getLicenseIdForThisUser(userInfo.Id, "license");
- userInfo.EditionId = AIAHTML5.API.Models.Users.getLicenseIdForThisUser(userInfo.Id, "edition");
-
- //05.Check user is active or not
- // Below statement required as tl says it is required for better code readability
- userInfo.IsActive = userInfo.IsActive;
+ //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);
+
+ userInfo.LicenseId = licenseId;
+ userInfo.EditionId = editionId;
+ //05.2 Check user is active or not
- //5.1 get license/ licenseSubscription details
- //objUser.License.IsActive = AIAHTML5.API.Models.Users.isLicenseActive(objUser.LicenseId);
- userInfo.License = AIAHTML5.API.Models.Users.getLicenseDetails(userInfo.LicenseId);
- userInfo.LicenseSubscriptions = AIAHTML5.API.Models.Users.getLicenseSubscriptionDetails(userInfo.LicenseId);
-
- //5.2 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
- bool isLicenseSubscriptionExpired = false;
- string expirationDate = AIAHTML5.API.Models.Users.getLicenseExpirationDate(userInfo.LicenseId,out isLicenseSubscriptionExpired);
-
- // send message to the UI for license expiration
- //5.2 Check for subscription Expiration [Promoted for case if license inactive along with subscription expired]
- if (isLicenseSubscriptionExpired)
- {
- userInfo.IsSubscriptionExpired = isLicenseSubscriptionExpired;
- userInfo.SubscriptionExpirationDate = expirationDate;
- }
-
- if (userInfo.License.IsActive)
- {
- //Insert user login details
- //AIAHTML5.API.Models.Users.insertLoginDetails(objUser.Id);
- if (!userInfo.License.IsTermAccepted)
- {
- ArrayList termsList = AIAHTML5.API.Models.Users.getTermsOfServiceText();
- foreach (Hashtable item in termsList)
- {
- userInfo.TermsOfServiceTitle = item["title"].ToString();
- userInfo.TermsOfServiceText = item["content"].ToString();
- }
- }
- else
+ //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.Modules = AIAHTML5.API.Models.Users.getModuleListByLicenseId(userInfo.LicenseId);
+ userInfo.TermsOfServiceTitle = item["title"].ToString();
+ userInfo.TermsOfServiceText = item["content"].ToString();
}
}
-
- //else
- //{
- // //6.
+ 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
- // // now return this list to the UI
- //}
- //}
- //else
- //{
- // // send message back to th UI that user is inactive
- //}
+ }
+
+ }
}
+ authenticationRepsonse = JsonConvert.SerializeObject(userInfo);
}
else
{
- bool isCorrectLoginId = AIAHTML5.API.Models.Users.isCredentialCorrect(credentials, userInfo, "loginId");
+ 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
- userInfo.IsCorrectLoginId = isCorrectLoginId;
+ authenticationRepsonse = AIAConstants.USER_NOT_FOUND;
}
else
{
- userInfo.IsCorrectLoginId = true;
- bool isCorrectPassword = AIAHTML5.API.Models.Users.isCredentialCorrect(credentials, userInfo, "password");
+ //getting userDetails
+ userInfo = AIAHTML5.API.Models.Users.getUserDetails(credentials);
if (!isCorrectPassword)
{
@@ -148,7 +161,7 @@ namespace AIAHTML5.API.Controllers
userInfo.IsCorrectPassword = false;
//get wrong attempt count of user
- userInfo.IncorrectLoginAttemptCount = AIAHTML5.API.Models.Users.checkNoOfWrongAttempts(userInfo.Id) + 1;
+ userInfo.IncorrectLoginAttemptCount = AIAHTML5.API.Models.Users.checkNoOfWrongAttempts(userInfo.Id) +1;
userInfo.LoginFailureCauseId = ErrorHelper.E_PASSWORD_NOT_MATCH;
//01. insert wrong attempt in dtabase
@@ -161,19 +174,6 @@ namespace AIAHTML5.API.Controllers
}
else
{
-
- //02. check no of wrong attempts
- //userInfo.IncorrectLoginAttemptCount = AIAHTML5.API.Models.Users.checkNoOfWrongAttempts(userInfo.Id);
- //if (userInfo.IncorrectLoginAttemptCount >= 5)
- //{
- // userInfo.IsBlocked = true;
- // // send block message
- //}
- //else
- //{
- // // send message back to UI for login fail
- //}
-
if (userInfo.IncorrectLoginAttemptCount > 4)
{
userInfo.IsBlocked = true;
@@ -188,25 +188,22 @@ namespace AIAHTML5.API.Controllers
// if (result < 0)
// logger.Fatal("Unable to insert wrong attempt detail in UserLoginLog table for accountNumber= " + userInfo.License.AccountNumber);
//}
+
+ authenticationRepsonse = JsonConvert.SerializeObject(userInfo);
}
}
- if(userInfo.IsCorrectLoginId)
- 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)
- //{
- // //string userDetails = Newtonsoft.Json.JsonConvert.SerializeObject(authenticationRepsonse);
- // return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(authenticationRepsonse) };
- //}
- //else
- //{
- return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(authenticationRepsonse) };
-
- //}
- }
+ //if (Convert.ToString(authenticationRepsonse) != AIAConstants.USER_NOT_FOUND && Convert.ToString(authenticationRepsonse) != AIAConstants.ERROR_IN_FECTHING_DETAILS && Convert.ToString(authenticationRepsonse)!= AIAConstants.SQL_CONNECTION_ERROR)
+ //{
+ // //string userDetails = Newtonsoft.Json.JsonConvert.SerializeObject(authenticationRepsonse);
+ // return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(authenticationRepsonse) };
+ //}
+ //else
+ //{
+ return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(authenticationRepsonse) };
+
+ //}
+ }
// PUT api/authenticate/5
diff --git a/400-SOURCECODE/AIAHTML5.API/Models/User.cs b/400-SOURCECODE/AIAHTML5.API/Models/User.cs
index 1b38b41..1f8201a 100644
--- a/400-SOURCECODE/AIAHTML5.API/Models/User.cs
+++ b/400-SOURCECODE/AIAHTML5.API/Models/User.cs
@@ -24,7 +24,6 @@ namespace AIAHTML5.API.Models
public string UserType { get; set; }
public int UserTypeId { get; set; }
public bool IsActive { get; set; }
- public bool IsCorrectLoginId { get; set; }
public bool IsCorrectPassword { get; set; }
public int IncorrectLoginAttemptCount { get; set; }
public bool IsBlocked { get; set; }
@@ -34,7 +33,7 @@ namespace AIAHTML5.API.Models
public ArrayList Modules { get; set; }
- public License License { get; set; }
+ public License LicenseInfo { get; set; }
public LicenseSubscriptionDetails LicenseSubscriptions { get; set; }
public bool IsSubscriptionExpired { get; set; }
public string SubscriptionExpirationDate { get; set; }
diff --git a/400-SOURCECODE/AIAHTML5.API/Models/Users.cs b/400-SOURCECODE/AIAHTML5.API/Models/Users.cs
index 82d7b83..a395b4d 100644
--- a/400-SOURCECODE/AIAHTML5.API/Models/Users.cs
+++ b/400-SOURCECODE/AIAHTML5.API/Models/Users.cs
@@ -23,7 +23,7 @@ namespace AIAHTML5.API.Models
try
{
- User user = DBModel.GetUserDetailsByLoginIdAndPassword(credentials["username"].ToString(), credentials["password"].ToString());
+ User user = DBModel.GetUserDetailsByLoginId(credentials["username"].ToString());
//string userDetails = DBModel.GetUserDetailsByLoginId2(credentials["username"].ToString());
if (user != null)
@@ -196,33 +196,29 @@ namespace AIAHTML5.API.Models
return result;
}
- internal static bool IsUserAuthenticated(Newtonsoft.Json.Linq.JObject credentials)
+ internal static bool IsUserAuthenticated(Newtonsoft.Json.Linq.JObject credentials, User user)
{
- bool isAuthenticatedUser = DBModel.ValidateUserAuthenticity(credentials["username"].ToString(), credentials["password"].ToString());
+ bool isAuthenticatedUser = DBModel.ValidateUserAuthenticity(credentials["username"].ToString(), credentials["password"].ToString(), user);
return isAuthenticatedUser;
}
- internal static User getLoggedinUserDetail(Newtonsoft.Json.Linq.JObject credentials)
- {
- User user = DBModel.GetUserDetailsByLoginIdAndPassword(credentials["username"].ToString(), credentials["password"].ToString());
-
- return user;
- }
-
internal static User getUserDetails(Newtonsoft.Json.Linq.JObject credentials)
{
- User user = DBModel.GetUserDetailsByLoginIdAndPassword(credentials["username"].ToString(), credentials["password"].ToString());
+ User user = DBModel.GetUserDetailsByLoginId(credentials["username"].ToString());
return user;
}
- internal static int getLicenseIdForThisUser(int userId, string key)
+ internal static void getLicenseIdForThisUser(int userId, out int licenseId, out int editionId)
{
+ //assigning below variable to avoid compiler error for unassignd out params
+ licenseId = 0;
+ editionId = 0;
+
ArrayList arrLicense = new ArrayList();
DBModel objModel = new DBModel();
- int licenseId = 0 , editionId = 0, result = 0;
- Hashtable licenseEditionHash = objModel.GetUserLicenseDetailByUserId(userId);
+ Hashtable licenseEditionHash = objModel.GetLicenseDetailByUserId(userId);
foreach (DictionaryEntry de in licenseEditionHash)
{
if (de.Key.ToString() == AIAConstants.LICENSE_KEY_ID)
@@ -230,12 +226,6 @@ namespace AIAHTML5.API.Models
if (de.Key.ToString() == AIAConstants.EDITION_KEY_ID)
editionId = Convert.ToInt32(de.Value);
}
-
- if (string.Equals(key.ToUpper(), AIAConstants.KEY_LICENSE))
- result = licenseId;
- if (string.Equals(key.ToUpper(), AIAConstants.KEY_EDITION))
- result = editionId;
- return result;
}
internal static int insertLoginDetails(int userId)
@@ -256,16 +246,14 @@ namespace AIAHTML5.API.Models
return false;
}
- internal static string getLicenseExpirationDate(int licenseId, out bool isLicenseExpired)
+ internal static bool checkIfLicenseExpired(LicenseSubscriptionDetails subscriptionDetail, out string expirationDate)
{
- isLicenseExpired = false;
- DBModel objModel = new DBModel();
- LicenseSubscriptionDetails licenseSubscription = objModel.GetLicenseSubscriptionDetailsByLicenseId(licenseId);
- string subscritptionExpirationDate = null;
+ expirationDate = string.Empty;
+ bool isLicenseExpired = false;
- if (licenseSubscription != null)
+ if (subscriptionDetail != null)
{
- DateTime? subscriptionValidThrough = licenseSubscription.SubscriptionValidThrough;
+ DateTime? subscriptionValidThrough = subscriptionDetail.SubscriptionValidThrough;
if (subscriptionValidThrough != null && subscriptionValidThrough.Value.Date >= DateTime.Now.Date)
{
isLicenseExpired = false;
@@ -273,10 +261,10 @@ namespace AIAHTML5.API.Models
else
{
isLicenseExpired = true;
- subscritptionExpirationDate = licenseSubscription.SubscriptionValidThrough.Value.Date.ToString("MM/dd/yyyy").ToString();
+ expirationDate = subscriptionDetail.SubscriptionValidThrough.Value.Date.ToString("MM/dd/yyyy").ToString();
}
}
- return subscritptionExpirationDate;
+ return isLicenseExpired;
}
internal static ArrayList getModuleListByLicenseId(int licenseId)
@@ -352,29 +340,23 @@ namespace AIAHTML5.API.Models
return userSubscriptionDetail;
}
- internal static bool isCredentialCorrect(Newtonsoft.Json.Linq.JObject credentials, User user, string key)
+ internal static void isCredentialCorrect(Newtonsoft.Json.Linq.JObject credentials, out bool isCorrectLoginId, out bool isCorrectPassword)
{
- bool result = false;
- if (user != null)
+ isCorrectLoginId = false;
+ isCorrectPassword = false;
+
+ User userInfo = Users.getUserDetails(credentials);
+
+ if (userInfo != null)
{
- if (string.Equals(key.ToUpper(), AIAConstants.KEY_LOGINID))
- {
- if (string.Equals(credentials["username"].ToString().ToUpper(), user.LoginId.ToUpper()))
- result = true;
- else
- result = false;
- }
+ if (string.Equals(credentials["username"].ToString().ToUpper(), userInfo.LoginId.ToUpper()))
+ isCorrectLoginId = true;
- if (string.Equals(key.ToUpper(), AIAConstants.KEY_PASSWORD))
+ if (string.Equals(credentials["password"].ToString(), userInfo.Password))
{
- if (string.Equals(credentials["password"].ToString(), user.Password))
- result = true;
- else
- result = false;
+ isCorrectPassword = true;
}
}
-
- return result;
}
internal static int insertUserLoginLog(string accountNumber, Int16 failureId, string referalUrl, string edition, string httpReferer)
@@ -399,7 +381,7 @@ namespace AIAHTML5.API.Models
internal static ArrayList getAllModulesList()
{
DBModel objModel = new DBModel();
- ArrayList modulesList = objModel.GetUserModules();
+ ArrayList modulesList = objModel.GetAllModules();
return modulesList;
}