diff --git a/400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs b/400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs
index eabac69..f01acf6 100644
--- a/400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs
+++ b/400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs
@@ -35,217 +35,280 @@ namespace AIAHTML5.API.Controllers
dynamic authenticationRepsonse;
- //01. check user is authenticated or not by login credential macth
- //bool isUserAuthenticated = AIAHTML5.API.Models.Users.IsUserAuthenticated(credentials);
-
- //Above code commented to reduce db hitting for same result set
- // get user details based on credentials provided
- dynamic userInfo = AIAHTML5.API.Models.Users.getUserDetails(credentials);
-
- if (userInfo != null && Convert.ToString(userInfo) != AIAConstants.SQL_CONNECTION_ERROR)
+ try
{
- //check is user authenticated
- bool isUserAuthenticated = AIAHTML5.API.Models.Users.IsUserAuthenticated(credentials, userInfo);
- // check if user is blocked
- DateTime blockTime;
- bool isUserBlocked = AIAHTML5.API.Models.Users.isUserBlocked(userInfo.Id, out blockTime);
+ //01. check user is authenticated or not by login credential macth
+ //bool isUserAuthenticated = AIAHTML5.API.Models.Users.IsUserAuthenticated(credentials);
+
+ //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);
- if (isUserAuthenticated && !isUserBlocked)
+ if (userInfo.Id > 0)
{
- //01. Get User details
- //userInfo = AIAHTML5.API.Models.Users.getUserDetails(credentials);
+ //check is user authenticated
+ bool isUserAuthenticated = AIAHTML5.API.Models.Users.IsUserAuthenticated(credentials, userInfo);
- //02. assigning isCorrectPassword to true 'required for internal processing'
- userInfo.IsCorrectPassword = true;
+ // check if user is blocked
+ DateTime blockTime;
+ bool isUserBlocked = AIAHTML5.API.Models.Users.isUserBlocked(userInfo.Id, out blockTime);
- //04.delete past wrong login attempts of user
- int wrongAttemptDeteledCount = AIAHTML5.API.Models.Users.deletePastWrongAttempts(userInfo.Id);
- if (wrongAttemptDeteledCount < 0)
+ if (isUserAuthenticated && !isUserBlocked)
{
- logger.Fatal("Unable to delete past wrong login attempts for userId= " + userInfo.Id);
- }
+ //01. Get User details
+ //userInfo = AIAHTML5.API.Models.Users.getUserDetails(credentials);
- //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);
+ //02. assigning isCorrectPassword to true 'required for internal processing'
+ userInfo.IsCorrectPassword = true;
- userInfo.LicenseId = licenseId;
- userInfo.EditionId = editionId;
+ //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.2 Check user is active or not
+ //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);
- //05.3 get license details
- userInfo.LicenseInfo = AIAHTML5.API.Models.Users.getLicenseDetails(userInfo.LicenseId);
+ userInfo.LicenseId = licenseId;
+ userInfo.EditionId = editionId;
- //05.4 get licenseSubscription details
- userInfo.LicenseSubscriptions = AIAHTML5.API.Models.Users.getLicenseSubscriptionDetails(userInfo.LicenseId);
+ //05.2 Check user is active or not
- //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);
+ //05.3 get license details
+ userInfo.LicenseInfo = AIAHTML5.API.Models.Users.getLicenseDetails(userInfo.LicenseId);
- // 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.Id > 0)
{
- if (!userInfo.LicenseInfo.IsTermAccepted)
+ //05.4 get licenseSubscription details
+ 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 = false;
+
+ if (userInfo.LicenseSubscriptions.Id > 0)
{
- ArrayList termsList = AIAHTML5.API.Models.Users.getTermsOfServiceText();
- foreach (Hashtable item in termsList)
- {
- userInfo.TermsOfServiceTitle = item["title"].ToString();
- userInfo.TermsOfServiceText = item["content"].ToString();
- }
+ 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
{
- userInfo.Modules = AIAHTML5.API.Models.Users.getModuleListByLicenseId(userInfo.LicenseId);
+ //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
+ //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
- {
- //compare block time of user with current time if user is blocked
- DateTime blockDuration = blockTime.AddDays(1);
- var difference = DateTime.Compare(DateTime.Now, blockDuration);
+ authenticationRepsonse = JsonConvert.SerializeObject(userInfo);
+ }
+ else
+ {
+ //compare block time of user with current time if user is blocked
+ DateTime blockDuration = blockTime.AddDays(1);
+ var difference = DateTime.Compare(DateTime.Now, blockDuration);
- //check if credentials are valid credentials
- bool isCorrectLoginId, isCorrectPassword;
- AIAHTML5.API.Models.Users.isCredentialCorrect(credentials, out isCorrectLoginId, out isCorrectPassword);
+ //check if credentials are valid credentials
+ bool isCorrectLoginId, isCorrectPassword;
+ AIAHTML5.API.Models.Users.isCredentialCorrect(credentials, userInfo, out isCorrectLoginId, out isCorrectPassword);
- if (isUserBlocked)
- {
- if (difference >= 0)
+ if (isUserBlocked)
{
- if (isCorrectPassword)
+ if (difference >= 0)
{
- userInfo.IsBlocked = false;
- userInfo.IsCorrectPassword = true;
-
- int wrongAttemptDeteledCount = AIAHTML5.API.Models.Users.deletePastWrongAttempts(userInfo.Id);
- if (wrongAttemptDeteledCount < 0)
+ if (isCorrectPassword)
{
- logger.Fatal("Unable to delete past wrong login attempts for userId= " + userInfo.Id);
- }
+ userInfo.IsBlocked = false;
+ userInfo.IsCorrectPassword = true;
- //05. Now get the module list- for ADMIN (superadmin/ general admin) by default all module loads
+ 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);
+ }
- 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
- //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);
+ if (userInfo.UserType == AIAHTML5.API.Models.User.SUPER_ADMIN || userInfo.UserType == AIAHTML5.API.Models.User.GENERAL_ADMIN)
+ {
+ userInfo.Modules = AIAHTML5.API.Models.Users.getAllModulesList();
- userInfo.LicenseId = licenseId;
- userInfo.EditionId = 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);
- //05.2 Check user is active or not
+ 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.3 get license/ licenseSubscription 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;
+ if (userInfo.LicenseInfo.Id > 0)
+ {
+ //05.4
+ 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;
+ bool isLicenseExpired = false;
- // 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)
+ if (userInfo.LicenseSubscriptions.Id > 0)
{
- ArrayList termsList = AIAHTML5.API.Models.Users.getTermsOfServiceText();
- foreach (Hashtable item in termsList)
- {
- userInfo.TermsOfServiceTitle = item["title"].ToString();
- userInfo.TermsOfServiceText = item["content"].ToString();
- }
+ 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
{
- userInfo.Modules = AIAHTML5.API.Models.Users.getModuleListByLicenseId(userInfo.LicenseId);
+ //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
- //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;
+ }
+ }
+
}
+
}
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);
- }
+ 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;
@@ -269,88 +332,39 @@ namespace AIAHTML5.API.Controllers
userInfo.LoginFailureCauseId = ErrorHelper.E_USER_ID_BLOCKED_24_HRS;
}
}
-
}
-
}
- else
- {
- 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)
+ // unreachable code detected as license is null
+ //if (userInfo.License != null && !string.IsNullOrEmpty(userInfo.License.AccountNumber))
//{
- // // send message back to th UI that login id is incorrect
- // authenticationRepsonse = AIAConstants.USER_NOT_FOUND;
+ // int result = AIAHTML5.API.Models.Users.insertUserLoginLog(userInfo.License.AccountNumber, userInfo.LoginFailureCauseId, null, userInfo.EditionId.ToString(), null);
+ // if (result < 0)
+ // logger.Fatal("Unable to insert wrong attempt detail in UserLoginLog table for accountNumber= " + userInfo.License.AccountNumber);
//}
- //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)
- {
- //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;
- }
- }
- }
+ authenticationRepsonse = JsonConvert.SerializeObject(userInfo);
+ //}
}
- // unreachable code detected as license is null
- //if (userInfo.License != null && !string.IsNullOrEmpty(userInfo.License.AccountNumber))
- //{
- // int result = AIAHTML5.API.Models.Users.insertUserLoginLog(userInfo.License.AccountNumber, userInfo.LoginFailureCauseId, null, userInfo.EditionId.ToString(), null);
- // if (result < 0)
- // logger.Fatal("Unable to insert wrong attempt detail in UserLoginLog table for accountNumber= " + userInfo.License.AccountNumber);
- //}
-
- authenticationRepsonse = JsonConvert.SerializeObject(userInfo);
- //}
+ }
+ else
+ {
+ authenticationRepsonse = AIAConstants.USER_NOT_FOUND;
}
}
- else if (Convert.ToString(userInfo) != AIAConstants.SQL_CONNECTION_ERROR)
- {
- authenticationRepsonse = AIAConstants.USER_NOT_FOUND;
- }
- else
+ catch (Exception e)
{
+
+ logger.Fatal("Exception occured for loginId =" + credentials["username"].ToString() + " and password= " + credentials["password"].ToString() + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace);
+
+ ArrayList supportMailList = UserUtility.GetSupportMailList();
+ string mailSubject = "SQL Exception intimation mail";
+ string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace;
+ UserUtility.SendEmail(credentials, supportMailList, "", mailSubject, mailBody);
+
authenticationRepsonse = AIAConstants.SQL_CONNECTION_ERROR;
}
- //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) };
-
- //}
}
diff --git a/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs b/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs
index a085cd7..f499b90 100644
--- a/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs
+++ b/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs
@@ -89,12 +89,12 @@ namespace AIAHTML5.API.Models
return arrUserModules;
}
- internal static dynamic GetUserDetailsByLoginId(string loginId)
+ internal static User GetUserDetailsByLoginId(string loginId)
{
ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
logger.Debug(" Inside GetUserDetailsByLoginId for LoginId = " + loginId);
- dynamic objUser = null;
+ User objUser = null;
DBModel objModel = new DBModel();
try
@@ -117,6 +117,7 @@ namespace AIAHTML5.API.Models
da.SelectCommand = cmd;
DataTable dt = new DataTable();
da.Fill(dt);
+
if (dt.Rows.Count > 0)
{
@@ -124,6 +125,7 @@ namespace AIAHTML5.API.Models
{
int tempVal;
DateTime date;
+ objUser = new User();
objUser.Id = Convert.ToInt32(dr["Id"]);
objUser.FirstName = dr["FirstName"].ToString();
@@ -145,7 +147,7 @@ namespace AIAHTML5.API.Models
}
else
{
- objUser = null;
+ objUser = new User();
}
}
catch (SqlException ex)
@@ -299,7 +301,7 @@ namespace AIAHTML5.API.Models
ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
logger.Debug(" Inside GetUserDetailsByEmailId for emailId = " + emailId);
- User objUser = new User();
+ User objUser = null;
DBModel objModel = new DBModel();
try
@@ -334,6 +336,7 @@ namespace AIAHTML5.API.Models
{
int tempVal;
DateTime date;
+ objUser = new User();
objUser.Id = Convert.ToInt32(dr["Id"]);
objUser.FirstName = dr["FirstName"].ToString();
@@ -356,7 +359,7 @@ namespace AIAHTML5.API.Models
}
else
{
- objUser = null;
+ objUser = new User ();
}
}
catch (SqlException ex)
@@ -454,7 +457,7 @@ namespace AIAHTML5.API.Models
}
else
{
- lsd = null;
+ lsd = new LicenseSubscriptionDetails ();
}
}
@@ -528,7 +531,7 @@ namespace AIAHTML5.API.Models
}
else
{
- license = null;
+ license = new License ();
}
}
catch (Exception ex)
@@ -883,7 +886,7 @@ namespace AIAHTML5.API.Models
}
else
{
- blockedUser = null;
+ blockedUser = new BlockedUser ();
}
}
catch (SqlException ex)
@@ -935,7 +938,7 @@ namespace AIAHTML5.API.Models
}
else
{
- blockedUser = null;
+ blockedUser = new BlockedUser();
}
}
catch (SqlException ex)
diff --git a/400-SOURCECODE/AIAHTML5.API/Models/Users.cs b/400-SOURCECODE/AIAHTML5.API/Models/Users.cs
index 897e13a..338d625 100644
--- a/400-SOURCECODE/AIAHTML5.API/Models/Users.cs
+++ b/400-SOURCECODE/AIAHTML5.API/Models/Users.cs
@@ -97,7 +97,7 @@ namespace AIAHTML5.API.Models
//dynamic userDetails;
- if (objUser != null)
+ if (objUser.Id > 0)
{
logger.Debug("userDetails.loginId= " + objUser.LoginId);
//return userDetails = JsonConvert.SerializeObject(objUser);
@@ -203,11 +203,11 @@ namespace AIAHTML5.API.Models
return isAuthenticatedUser;
}
- internal static dynamic getUserDetails(Newtonsoft.Json.Linq.JObject credentials)
+ internal static User getUserDetails(Newtonsoft.Json.Linq.JObject credentials)
{
ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
logger.Debug("inside getUserDetails for loginId =" + credentials["username"].ToString() + " and password= " + credentials["password"].ToString());
- dynamic userDetails = null;
+ User userDetails = null;
try
{
@@ -217,13 +217,13 @@ namespace AIAHTML5.API.Models
{
logger.Fatal("Exception in getUserDetails for loginId =" + credentials["username"].ToString() + " and password= " + credentials["password"].ToString() + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace);
+ throw;
+ //ArrayList supportMailList = UserUtility.GetSupportMailList();
+ //string mailSubject = "SQL Exception intimation mail";
+ //string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace;
+ //UserUtility.SendEmail(credentials, supportMailList, "", mailSubject, mailBody);
- ArrayList supportMailList = UserUtility.GetSupportMailList();
- string mailSubject = "SQL Exception intimation mail";
- string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace;
- UserUtility.SendEmail(credentials, supportMailList, "", mailSubject, mailBody);
-
- userDetails = AIAConstants.SQL_CONNECTION_ERROR;
+ //userDetails = AIAConstants.SQL_CONNECTION_ERROR;
}
return userDetails;
@@ -260,13 +260,7 @@ namespace AIAHTML5.API.Models
catch (Exception e)
{
logger.Fatal("Exception in getLicenseIdForThisUser for UserId =" + userId + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace);
-
- //ArrayList supportMailList = UserUtility.GetSupportMailList();
- //string mailSubject = "SQL Exception intimation mail";
- //string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace;
- //UserUtility.SendEmail(credentials, supportMailList, "", mailSubject, mailBody);
-
- //userDetails = AIAConstants.SQL_CONNECTION_ERROR;
+ throw;
}
}
@@ -285,13 +279,7 @@ namespace AIAHTML5.API.Models
catch (Exception e)
{
logger.Fatal("Exception in insertLoginDetails for UserId =" + userId + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace);
-
- //ArrayList supportMailList = UserUtility.GetSupportMailList();
- //string mailSubject = "SQL Exception intimation mail";
- //string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace;
- //UserUtility.SendEmail(credentials, supportMailList, "", mailSubject, mailBody);
-
- //userDetails = AIAConstants.SQL_CONNECTION_ERROR;
+ throw;
}
return result;
@@ -310,7 +298,7 @@ namespace AIAHTML5.API.Models
expirationDate = string.Empty;
bool isLicenseExpired = false;
- if (subscriptionDetail != null)
+ if (subscriptionDetail.Id > 0)
{
DateTime? subscriptionValidThrough = subscriptionDetail.SubscriptionValidThrough;
if (subscriptionValidThrough != null && subscriptionValidThrough.Value.Date >= DateTime.Now.Date)
@@ -342,13 +330,7 @@ namespace AIAHTML5.API.Models
catch (Exception e)
{
logger.Fatal("Exception in getModuleListByLicenseId for LicenseId =" + licenseId + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace);
-
- //ArrayList supportMailList = UserUtility.GetSupportMailList();
- //string mailSubject = "SQL Exception intimation mail";
- //string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace;
- //UserUtility.SendEmail(credentials, supportMailList, "", mailSubject, mailBody);
-
- //userDetails = AIAConstants.SQL_CONNECTION_ERROR;
+ throw;
}
return licensedModulesList;
@@ -370,13 +352,7 @@ namespace AIAHTML5.API.Models
catch (Exception e)
{
logger.Fatal("Exception in deletePastWrongAttempts for UserId =" + userId + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace);
-
- //ArrayList supportMailList = UserUtility.GetSupportMailList();
- //string mailSubject = "SQL Exception intimation mail";
- //string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace;
- //UserUtility.SendEmail(credentials, supportMailList, "", mailSubject, mailBody);
-
- //userDetails = AIAConstants.SQL_CONNECTION_ERROR;
+ throw;
}
return result;
}
@@ -397,13 +373,7 @@ namespace AIAHTML5.API.Models
catch (Exception e)
{
logger.Fatal("Exception in checkNoOfWrongAttempts for UserId =" + userId + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace);
-
- //ArrayList supportMailList = UserUtility.GetSupportMailList();
- //string mailSubject = "SQL Exception intimation mail";
- //string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace;
- //UserUtility.SendEmail(credentials, supportMailList, "", mailSubject, mailBody);
-
- //userDetails = AIAConstants.SQL_CONNECTION_ERROR;
+ throw;
}
return result;
}
@@ -432,13 +402,7 @@ namespace AIAHTML5.API.Models
catch (Exception e)
{
logger.Fatal("Exception in saveWrongAttemptofUser for UserId =" + userId + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace);
-
- //ArrayList supportMailList = UserUtility.GetSupportMailList();
- //string mailSubject = "SQL Exception intimation mail";
- //string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace;
- //UserUtility.SendEmail(credentials, supportMailList, "", mailSubject, mailBody);
-
- //userDetails = AIAConstants.SQL_CONNECTION_ERROR;
+ throw;
}
return result;
@@ -464,13 +428,7 @@ namespace AIAHTML5.API.Models
catch (Exception e)
{
logger.Fatal("Exception in isLicenseActive for LicenseId =" + licenseId + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace);
-
- //ArrayList supportMailList = UserUtility.GetSupportMailList();
- //string mailSubject = "SQL Exception intimation mail";
- //string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace;
- //UserUtility.SendEmail(credentials, supportMailList, "", mailSubject, mailBody);
-
- //userDetails = AIAConstants.SQL_CONNECTION_ERROR;
+ throw;
}
return result;
}
@@ -490,13 +448,7 @@ namespace AIAHTML5.API.Models
catch (Exception e)
{
logger.Fatal("Exception in getLicenseDetails for LicenseId =" + licenseId + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace);
-
- //ArrayList supportMailList = UserUtility.GetSupportMailList();
- //string mailSubject = "SQL Exception intimation mail";
- //string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace;
- //UserUtility.SendEmail(credentials, supportMailList, "", mailSubject, mailBody);
-
- //userDetails = AIAConstants.SQL_CONNECTION_ERROR;
+ throw;
}
return userLicense;
}
@@ -515,25 +467,17 @@ namespace AIAHTML5.API.Models
catch (Exception e)
{
logger.Fatal("Exception in getLicenseSubscriptionDetails for LicenseId =" + licenseId + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace);
-
- //ArrayList supportMailList = UserUtility.GetSupportMailList();
- //string mailSubject = "SQL Exception intimation mail";
- //string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace;
- //UserUtility.SendEmail(credentials, supportMailList, "", mailSubject, mailBody);
-
- //userDetails = AIAConstants.SQL_CONNECTION_ERROR;
+ throw;
}
return userSubscriptionDetail;
}
- internal static void isCredentialCorrect(Newtonsoft.Json.Linq.JObject credentials, out bool isCorrectLoginId, out bool isCorrectPassword)
+ internal static void isCredentialCorrect(Newtonsoft.Json.Linq.JObject credentials, User userInfo, out bool isCorrectLoginId, out bool isCorrectPassword)
{
isCorrectLoginId = false;
- isCorrectPassword = false;
+ isCorrectPassword = false;
- User userInfo = Users.getUserDetails(credentials);
-
- if (userInfo != null)
+ if (userInfo.Id> 0)
{
if (string.Equals(credentials["username"].ToString().ToUpper(), userInfo.LoginId.ToUpper()))
isCorrectLoginId = true;
@@ -560,13 +504,7 @@ namespace AIAHTML5.API.Models
catch (Exception e)
{
logger.Fatal("Exception in insertUserLoginLog for accountNumber =" + accountNumber + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace);
-
- //ArrayList supportMailList = UserUtility.GetSupportMailList();
- //string mailSubject = "SQL Exception intimation mail";
- //string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace;
- //UserUtility.SendEmail(credentials, supportMailList, "", mailSubject, mailBody);
-
- //userDetails = AIAConstants.SQL_CONNECTION_ERROR;
+ throw;
}
return result;
}
@@ -587,13 +525,7 @@ namespace AIAHTML5.API.Models
catch (Exception e)
{
logger.Fatal("Exception in getTermsOfServiceText, Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace);
-
- //ArrayList supportMailList = UserUtility.GetSupportMailList();
- //string mailSubject = "SQL Exception intimation mail";
- //string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace;
- //UserUtility.SendEmail(credentials, supportMailList, "", mailSubject, mailBody);
-
- //userDetails = AIAConstants.SQL_CONNECTION_ERROR;
+ throw;
}
return arrTermsOfService;
}
@@ -612,13 +544,7 @@ namespace AIAHTML5.API.Models
catch (Exception e)
{
logger.Fatal("Exception in getAllModulesList, Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace);
-
- //ArrayList supportMailList = UserUtility.GetSupportMailList();
- //string mailSubject = "SQL Exception intimation mail";
- //string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace;
- //UserUtility.SendEmail(credentials, supportMailList, "", mailSubject, mailBody);
-
- //userDetails = AIAConstants.SQL_CONNECTION_ERROR;
+ throw;
}
return modulesList;
}
@@ -637,7 +563,7 @@ namespace AIAHTML5.API.Models
DBModel objModel = new DBModel();
BlockedUser blockedUser = objModel.GetBlockedUserByUserId(userId);
- if (blockedUser != null)
+ if (blockedUser.Id> 0)
{
blockTime = blockedUser.LoginTime;
result = true;
@@ -649,13 +575,7 @@ namespace AIAHTML5.API.Models
catch (Exception e)
{
logger.Fatal("Exception in isUserBlocked for UserId =" + userId + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace);
-
- //ArrayList supportMailList = UserUtility.GetSupportMailList();
- //string mailSubject = "SQL Exception intimation mail";
- //string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace;
- //UserUtility.SendEmail(credentials, supportMailList, "", mailSubject, mailBody);
-
- //userDetails = AIAConstants.SQL_CONNECTION_ERROR;
+ throw;
}
return result;
diff --git a/400-SOURCECODE/AIAHTML5.API/Utility/EmailUtility.cs b/400-SOURCECODE/AIAHTML5.API/Utility/EmailUtility.cs
index 7b55008..50480e8 100644
--- a/400-SOURCECODE/AIAHTML5.API/Utility/EmailUtility.cs
+++ b/400-SOURCECODE/AIAHTML5.API/Utility/EmailUtility.cs
@@ -1,136 +1,136 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web;
-using System.Configuration;
-using System.Collections;
-using System.Xml;
-using System.Text;
-using System.IO;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+using System.Configuration;
+using System.Collections;
+using System.Xml;
+using System.Text;
+using System.IO;
using System.Net.Mail;
-using log4net;
-
-namespace AIAHTML5.API.Utility
-{
-
- public class EmailUtility
- {
- public string sFromAddress { get; set; }
- public List sToAddresses { get; set; }
- public List sBccAddresses { get; set; }
- public string sHostName { get; set; }
- public string sSubject { get; set; }
- public int iPort { get; set; }
- public bool bEnableSsl { get; set; }
- public string sUserName { get; set; }
- public string sPassword { get; set; }
- public bool bIsBodyHtml { get; set; }
- public List sAttachments { get; set; }
- public string sBodyText { get; set; }
- public AlternateView sAlternateView { get; set; }
-
- public void SendMail(MailMessage mm)
- {
- SmtpClient smtp = new SmtpClient();
- smtp.Host = ConfigurationManager.AppSettings["SMTPAddress"];
- smtp.EnableSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableSSL"]);
- System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential(mm.From.ToString(), ConfigurationManager.AppSettings["SenderPassword"]);
- smtp.Credentials = NetworkCred;
- smtp.Port = Convert.ToInt32(ConfigurationManager.AppSettings["SMTPPort"]);
-
- smtp.Send(mm);
- }
-
- public void SendSmtpEmail()
+using log4net;
+
+namespace AIAHTML5.API.Utility
+{
+
+ public class EmailUtility
+ {
+ public string sFromAddress { get; set; }
+ public List sToAddresses { get; set; }
+ public List sBccAddresses { get; set; }
+ public string sHostName { get; set; }
+ public string sSubject { get; set; }
+ public int iPort { get; set; }
+ public bool bEnableSsl { get; set; }
+ public string sUserName { get; set; }
+ public string sPassword { get; set; }
+ public bool bIsBodyHtml { get; set; }
+ public List sAttachments { get; set; }
+ public string sBodyText { get; set; }
+ public AlternateView sAlternateView { get; set; }
+
+ public void SendMail(MailMessage mm)
+ {
+ SmtpClient smtp = new SmtpClient();
+ smtp.Host = ConfigurationManager.AppSettings["SMTPAddress"];
+ smtp.EnableSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableSSL"]);
+ System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential(mm.From.ToString(), ConfigurationManager.AppSettings["SenderPassword"]);
+ smtp.Credentials = NetworkCred;
+ smtp.Port = Convert.ToInt32(ConfigurationManager.AppSettings["SMTPPort"]);
+
+ smtp.Send(mm);
+ }
+
+ public void SendSmtpEmail()
{
ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
- logger.Debug("inside SendSmtpEmail");
-
- try
- {
- MailMessage sMail = new MailMessage();
- SmtpClient SmtpServer = new SmtpClient(sHostName);
- string recipientEmailAddress = string.Empty;
-
-
- if (sToAddresses != null)
- {
- foreach (var sItem in sToAddresses)
- {
+ logger.Debug("inside SendSmtpEmail");
+
+ try
+ {
+ MailMessage sMail = new MailMessage();
+ SmtpClient SmtpServer = new SmtpClient(sHostName);
+ string recipientEmailAddress = string.Empty;
+
+
+ if (sToAddresses != null)
+ {
+ foreach (var sItem in sToAddresses)
+ {
sMail.To.Add(sItem);
- logger.Debug("sToAddresses= " + sItem);
- }
- }
-
- if (sBccAddresses != null)
- {
- foreach (var sItem in sBccAddresses)
- {
+ logger.Debug("sToAddresses= " + sItem);
+ }
+ }
+
+ if (sBccAddresses != null)
+ {
+ foreach (var sItem in sBccAddresses)
+ {
sMail.Bcc.Add(sItem);
- logger.Debug("sBccAddresses= " + sItem);
-
- }
- }
-
- sMail.IsBodyHtml = bIsBodyHtml;
-
- if (sAlternateView != null)
- {
+ logger.Debug("sBccAddresses= " + sItem);
+
+ }
+ }
+
+ sMail.IsBodyHtml = bIsBodyHtml;
+
+ if (sAlternateView != null)
+ {
sMail.AlternateViews.Add(sAlternateView);
- logger.Debug("sAlternateView= " + sAlternateView);
-
- }
- else
- {
+ logger.Debug("sAlternateView= " + sAlternateView);
+
+ }
+ else
+ {
sMail.Body = sBodyText;
- logger.Debug("sMail.Body= " + sBodyText);
-
- }
-
+ logger.Debug("sMail.Body= " + sBodyText);
+
+ }
+
sMail.Subject = sSubject;
- logger.Debug("sMail.Subject= " + sSubject);
-
- if (sAttachments != null)
- {
- foreach (var sItem in sAttachments)
- {
+ logger.Debug("sMail.Subject= " + sSubject);
+
+ if (sAttachments != null)
+ {
+ foreach (var sItem in sAttachments)
+ {
sMail.Attachments.Add(sItem);
- logger.Debug("sAttachments= " + sAttachments);
-
-
- }
+ logger.Debug("sAttachments= " + sAttachments);
+
+
+ }
}
- logger.Debug("sUserName= " + sUserName + ", sPassword= " + sPassword);
-
- SmtpServer.Port = iPort;
- SmtpServer.Credentials = new System.Net.NetworkCredential(sUserName, sPassword);
- SmtpServer.EnableSsl = bEnableSsl;
-
- using (MailMessage mm = new MailMessage(sFromAddress, sMail.To.ToString()))
- {
- mm.Subject = sSubject;
- mm.IsBodyHtml = bIsBodyHtml;
-
- if (sAlternateView != null)
- {
- mm.AlternateViews.Add(sAlternateView);
- }
- else
- {
- mm.Body = sBodyText;
- }
-
- mm.IsBodyHtml = true;
+ logger.Debug("sUserName= " + sUserName + ", sPassword= " + sPassword);
+
+ SmtpServer.Port = iPort;
+ SmtpServer.Credentials = new System.Net.NetworkCredential(sUserName, sPassword);
+ SmtpServer.EnableSsl = bEnableSsl;
+
+ using (MailMessage mm = new MailMessage(sFromAddress, sMail.To.ToString()))
+ {
+ mm.Subject = sSubject;
+ mm.IsBodyHtml = bIsBodyHtml;
+
+ if (sAlternateView != null)
+ {
+ mm.AlternateViews.Add(sAlternateView);
+ }
+ else
+ {
+ mm.Body = sBodyText;
+ }
+
+ mm.IsBodyHtml = true;
SendMail(mm);
- logger.Debug("after sending email");
- }
-
- }
- catch (Exception ex)
+ logger.Debug("after sending email");
+ }
+
+ }
+ catch (Exception ex)
{
- logger.Fatal("exception in SendSmtpEmail.msg= " + ex.Message + ", stacktarce= " + ex.StackTrace);
- throw ex;
- }
- }
- }
+ logger.Fatal("exception in SendSmtpEmail.msg= " + ex.Message + ", stacktarce= " + ex.StackTrace);
+ throw ex;
+ }
+ }
+ }
}
\ No newline at end of file