diff --git a/150-DOCUMENTATION/002-DBScripts/DeleteIncorretLoginAttempts.sql b/150-DOCUMENTATION/002-DBScripts/DeleteIncorretLoginAttempts.sql new file mode 100644 index 0000000..d861020 --- /dev/null +++ b/150-DOCUMENTATION/002-DBScripts/DeleteIncorretLoginAttempts.sql @@ -0,0 +1,33 @@ +-- ================================================ +-- Template generated from Template Explorer using: +-- Create Procedure (New Menu).SQL +-- +-- Use the Specify Values for Template Parameters +-- command (Ctrl-Shift-M) to fill in the parameter +-- values below. +-- +-- This block of comments will not be included in +-- the definition of the procedure. +-- ================================================ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +-- ============================================= +-- Author: +-- Create date: <7/27/2017> +-- Description: +-- ============================================= +CREATE PROCEDURE DeleteIncorrectLoginAttempts + -- Add the parameters for the stored procedure here + @iUserId INT +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT OFF; + + -- Insert statements for procedure here + DELETE from IncorrectLoginAttempts where UserId =@iUserId +END +GO \ No newline at end of file diff --git a/150-DOCUMENTATION/002-DBScripts/GetAllLoginFailureCauses.sql b/150-DOCUMENTATION/002-DBScripts/GetAllLoginFailureCauses.sql new file mode 100644 index 0000000..6e9f89b --- /dev/null +++ b/150-DOCUMENTATION/002-DBScripts/GetAllLoginFailureCauses.sql @@ -0,0 +1,33 @@ +-- ================================================ +-- Template generated from Template Explorer using: +-- Create Procedure (New Menu).SQL +-- +-- Use the Specify Values for Template Parameters +-- command (Ctrl-Shift-M) to fill in the parameter +-- values below. +-- +-- This block of comments will not be included in +-- the definition of the procedure. +-- ================================================ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +-- ============================================= +-- Author: +-- Create date: <07/31/2017> +-- Description: +-- ============================================= +CREATE PROCEDURE GetAllLoginFailureCauses + -- Add the parameters for the stored procedure here + +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + -- Insert statements for procedure here + SELECT lfc.Id, lfc.Description FROM LoginFailureCause lfc +END +GO diff --git a/150-DOCUMENTATION/002-DBScripts/GetBlockedUserByUserId.sql b/150-DOCUMENTATION/002-DBScripts/GetBlockedUserByUserId.sql new file mode 100644 index 0000000..8161ea4 --- /dev/null +++ b/150-DOCUMENTATION/002-DBScripts/GetBlockedUserByUserId.sql @@ -0,0 +1,37 @@ +-- ============================================= +-- Author: <> +-- Create date: <> +-- Description: +-- ============================================= +CREATE PROCEDURE GetBlockedUserByUserId + -- Add the parameters for the stored procedure here + @userId int +AS +BEGIN + -- returns the metadata + IF 1=0 BEGIN + SET FMTONLY OFF + END + SELECT DISTINCT + AIAUser.Id, + AIAUser.FirstName, + AIAUser.LastName, + AIAUser.LoginId, + AIAUser.Password, + AIAUser.EmailId, + ISNULL(License.AccountNumber,'') AccountNumber, + IncorrectLoginAttempts.LoginTime + FROM + IncorrectLoginAttempts + INNER JOIN AIAUser ON IncorrectLoginAttempts.UserId = AIAUser.Id + INNER JOIN UserType ON AIAUser.UserTypeId = UserType.Id + LEFT JOIN AIAUserToLicenseEdition ON AIAUser.Id = AIAUserToLicenseEdition.UserId + LEFT JOIN LicenseToEdition ON AIAUserToLicenseEdition.LicenseEditionId = LicenseToEdition.Id + LEFT JOIN License ON LicenseToEdition.LicenseId = License.Id + WHERE + IncorrectLoginAttempts.CntIncorrectLogins >= 5 + AND AIAUser.Id = @userId + --AND UserType.Priority >= (SELECT UserType.Priority FROM UserType WHERE UserType.Id=@iUserTypeId) + --AND ((@iLicenseId =0) OR (License.Id = @iLicenseId)) + --AND License.IsActive = 1 +END \ No newline at end of file diff --git a/150-DOCUMENTATION/002-DBScripts/GetLicenseDetailByUserId.sql b/150-DOCUMENTATION/002-DBScripts/GetLicenseDetailByUserId.sql new file mode 100644 index 0000000..c5f00d8 --- /dev/null +++ b/150-DOCUMENTATION/002-DBScripts/GetLicenseDetailByUserId.sql @@ -0,0 +1,19 @@ +-- ============================================= +-- Author: +-- Create date: <07/31/2017> +-- Description: +-- ============================================= +CREATE PROCEDURE GetLicenseDetailByUserId + -- Add the parameters for the stored procedure here + @iUserId int +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + -- Insert statements for procedure here + SELECT LicenseId, EditionId FROM LicenseToEdition + INNER JOIN AIAUserToLicenseEdition on AIAUserToLicenseEdition.LicenseEditionId = LicenseToEdition.Id + WHERE AIAUserToLicenseEdition.UserId = @iUserId +END \ No newline at end of file diff --git a/150-DOCUMENTATION/002-DBScripts/GetUserDetailsByLoginId.sql b/150-DOCUMENTATION/002-DBScripts/GetUserDetailsByLoginId.sql new file mode 100644 index 0000000..c3854a9 --- /dev/null +++ b/150-DOCUMENTATION/002-DBScripts/GetUserDetailsByLoginId.sql @@ -0,0 +1,19 @@ +-- ============================================= +-- Author: +-- Create date: <07/18/2017> +-- Description: +-- ============================================= +CREATE PROCEDURE GetUserDetailsByLoginId + -- Add the parameters for the stored procedure here + @sLoginId VARCHAR(50) +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT OFF; + + -- Insert statements for procedure here + SELECT CreationDate, CreatorId, DeactivationDate, EmailId, FirstName, Id, IsActive, LastName, LoginId, ModifiedDate, ModifierId, Password, SecurityAnswer, SecurityQuestionId, UserTypeId FROM AIAUser WHERE (LoginId = @sLoginId) + +END + \ No newline at end of file diff --git a/150-DOCUMENTATION/002-DBScripts/GetUserModulesByLicenseId.sql b/150-DOCUMENTATION/002-DBScripts/GetUserModulesByLicenseId.sql new file mode 100644 index 0000000..233768d --- /dev/null +++ b/150-DOCUMENTATION/002-DBScripts/GetUserModulesByLicenseId.sql @@ -0,0 +1,25 @@ +-- ============================================= +-- Author: +-- Create date: +-- Description: +-- ============================================= +CREATE PROCEDURE [dbo].[GetUserModulesByLicenseId] + -- Add the parameters for the stored procedure here + @iLicenseId int +AS +BEGIN + IF 1=0 BEGIN + SET FMTONLY OFF + END + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + -- Insert statements for procedure here + SELECT ResourceModule.Id,ResourceModule.Title, ResourceModule.Slug + FROM ResourceModule + INNER JOIN ModuleToLicense ON ResourceModule.Id = ModuleToLicense.ModuleId + WHERE ModuleToLicense.Status = 1 + AND ModuleToLicense.LicenseId = @iLicenseId + +END \ No newline at end of file diff --git a/150-DOCUMENTATION/002-DBScripts/InsertIncorrectLoginAttempts.sql b/150-DOCUMENTATION/002-DBScripts/InsertIncorrectLoginAttempts.sql new file mode 100644 index 0000000..6105105 --- /dev/null +++ b/150-DOCUMENTATION/002-DBScripts/InsertIncorrectLoginAttempts.sql @@ -0,0 +1,33 @@ +-- ================================================ +-- Template generated from Template Explorer using: +-- Create Procedure (New Menu).SQL +-- +-- Use the Specify Values for Template Parameters +-- command (Ctrl-Shift-M) to fill in the parameter +-- values below. +-- +-- This block of comments will not be included in +-- the definition of the procedure. +-- ================================================ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +-- ============================================= +-- Author: +-- Create date: <7/27/2017> +-- Description: +-- ============================================= +CREATE PROCEDURE InsertIncorrectLoginAttempts + -- Add the parameters for the stored procedure here + @iUserId INT +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + -- Insert statements for procedure here + INSERT into IncorrectLoginAttempts ([UserId] , LoginTime , CntIncorrectLogins) values (@iUserId, getdate(), 1) +END +GO diff --git a/150-DOCUMENTATION/002-DBScripts/InsertLoginDetail.sql b/150-DOCUMENTATION/002-DBScripts/InsertLoginDetail.sql new file mode 100644 index 0000000..461b934 --- /dev/null +++ b/150-DOCUMENTATION/002-DBScripts/InsertLoginDetail.sql @@ -0,0 +1,33 @@ +-- ================================================ +-- Template generated from Template Explorer using: +-- Create Procedure (New Menu).SQL +-- +-- Use the Specify Values for Template Parameters +-- command (Ctrl-Shift-M) to fill in the parameter +-- values below. +-- +-- This block of comments will not be included in +-- the definition of the procedure. +-- ================================================ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +-- ============================================= +-- Author: +-- Create date: +-- Description: +-- ============================================= +CREATE PROCEDURE InsertLoginDetail + -- Add the parameters for the stored procedure here + @iUserId INT +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + -- Insert statements for procedure here + INSERT INTO LoginDetail (UserId, LoginTime) VALUES (@iUserId, GETDATE()) +END +GO diff --git a/150-DOCUMENTATION/002-DBScripts/UpdateIncorrectLoginAttempts.sql b/150-DOCUMENTATION/002-DBScripts/UpdateIncorrectLoginAttempts.sql new file mode 100644 index 0000000..dbc36e4 --- /dev/null +++ b/150-DOCUMENTATION/002-DBScripts/UpdateIncorrectLoginAttempts.sql @@ -0,0 +1,33 @@ +-- ================================================ +-- Template generated from Template Explorer using: +-- Create Procedure (New Menu).SQL +-- +-- Use the Specify Values for Template Parameters +-- command (Ctrl-Shift-M) to fill in the parameter +-- values below. +-- +-- This block of comments will not be included in +-- the definition of the procedure. +-- ================================================ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +-- ============================================= +-- Author: +-- Create date: +-- Description: +-- ============================================= +CREATE PROCEDURE UpdateIncorrectLoginAttempts + -- Add the parameters for the stored procedure here + @iUserId INT +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT OFF; + + -- Insert statements for procedure here + UPDATE IncorrectLoginAttempts set LoginTime = getdate(), CntIncorrectLogins = CntIncorrectLogins+1 where UserId = @iUserId +END +GO diff --git a/150-DOCUMENTATION/002-DBScripts/UpdateLicenseTermAcceptedStatus.sql b/150-DOCUMENTATION/002-DBScripts/UpdateLicenseTermAcceptedStatus.sql new file mode 100644 index 0000000..9f12401 --- /dev/null +++ b/150-DOCUMENTATION/002-DBScripts/UpdateLicenseTermAcceptedStatus.sql @@ -0,0 +1,17 @@ +-- ============================================= +-- Author: +-- Create date: <07/21/2017> +-- Description: +-- ============================================= +CREATE PROCEDURE UpdateLicenseTermAcceptedStatus + -- Add the parameters for the stored procedure here + @sAccountNumber char(16) +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT OFF; + + -- Insert statements for procedure here + UPDATE License SET IsTermsAccepted =1 WHERE AccountNumber = @sAccountNumber +END \ No newline at end of file diff --git a/400-SOURCECODE/AIAHTML5.API/AIAHTML5.API.csproj b/400-SOURCECODE/AIAHTML5.API/AIAHTML5.API.csproj index 5f014a3..3fffdac 100644 --- a/400-SOURCECODE/AIAHTML5.API/AIAHTML5.API.csproj +++ b/400-SOURCECODE/AIAHTML5.API/AIAHTML5.API.csproj @@ -100,6 +100,7 @@ + Designer @@ -107,12 +108,15 @@ + + + Global.asax diff --git a/400-SOURCECODE/AIAHTML5.API/Constants/AIAConstants.cs b/400-SOURCECODE/AIAHTML5.API/Constants/AIAConstants.cs index 93891e5..ea87561 100644 --- a/400-SOURCECODE/AIAHTML5.API/Constants/AIAConstants.cs +++ b/400-SOURCECODE/AIAHTML5.API/Constants/AIAConstants.cs @@ -11,11 +11,13 @@ namespace AIAHTML5.API.Constants public const string USER_NOT_FOUND = "User not found."; public const string MAIL_NOT_SENT = "Mail not sent."; public const string MAIL_SENT = "Mail sent."; + public const string SQL_CONNECTION_ERROR = "SQL Connection Error"; public const string KEY_ID = "id"; public const string KEY_TITLE = "title"; public const string KEY_NAME = "name"; public const string KEY_SLUG = "slug"; + public const string KEY_DESCRIPTION = "Description"; public const string PASSWORD_UPDATE_SUCCESS = "Password updated successfully"; public const string PASSWORD_UPDATE_FAILED = "Password update failed"; @@ -26,5 +28,12 @@ namespace AIAHTML5.API.Constants public const string LICENSE_TERM_CONDITION_UPDATE_FAILED = "License Term Accepted field update failed."; public const string KEY_CONTENT = "content"; + + public const string LICENSE_KEY_ID = "LicenseId"; + public const string EDITION_KEY_ID = "EditionId"; + + public const string USER_UNBLOCK_SUCCESS = "User unblocked"; + public const string USER_UNBLOCK_FAILED = "Unblock operation failed"; + public const string USER_ALREADY_UNBLOCKED = "User already unblocked."; } } \ No newline at end of file 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/Constants/ErrorHelper.cs b/400-SOURCECODE/AIAHTML5.API/Constants/ErrorHelper.cs new file mode 100644 index 0000000..ef97db0 --- /dev/null +++ b/400-SOURCECODE/AIAHTML5.API/Constants/ErrorHelper.cs @@ -0,0 +1,137 @@ +using System; +using System.Collections.Generic; +using System.Collections; +using System.Linq; +using System.Web; + +namespace AIAHTML5.API.Constants +{ + /// + /// This class is used to provide error description. This class contain + /// different type of error code and its description. + /// + public class ErrorHelper + { + private static ErrorHelper _instance; + private Hashtable objHash = new Hashtable(); + + + /* error Id Const */ + public const Int16 E_NO_ERROR = 0; + public const Int16 E_USER_NOT_EXIST = 1; + public const Int16 E_PASSWORD_NOT_MATCH = 2; + public const Int16 E_USER_ID_BLOCKED_24_HRS = 3; + public const Int16 E_USER_NOT_ACTIVE = 4; + public const Int16 E_USER_ID_WILL_BLOCKED = 5; + public const Int16 E_EMAIL_ID_NOT_EXIT = 6; + public const Int16 E_LICENCE_IS_INACTIVE = 7; + public const Int16 E_USER_NOT_MAP_TO_LICENCE_EDITION = 8; + public const Int16 E_NO_ROW_FOUND_LICENCE_TO_EDITION_TABLE = 9; + public const Int16 E_NO_ROW_FOUND_LICENCE_TABLE = 10; + public const Int16 E_SECURITY_QUEST_NOT_MATCH = 11; + public const Int16 E_SEQURITY_ANSWER_NOT_MATCH = 12; + public const Int16 E_FORGOT_USER_ID_EMAIL_ID_NOT_EXIT = 13; + public const Int16 E_TOTAL_NUMBER_LOGIN_EXCEED = 14; + public const Int16 E_FORGOT_PASSWORD_EMAIL_ID_NOT_EXIST = 15; + public const Int16 E_TEST_SETUP_ACCOUNT_USER_NAME_EXIST = 16; + public const Int16 E_TEST_SETUP_ACCOUNT_EMAILID_EXIST = 17; + public const Int16 E_SP_ERROR = 18; + public const Int16 E_ACCOUNT_NUMBER_NOT_EXIST = 19; + public const Int16 E_ACCOUNT_NUMBER_ALREADY_EXIST = 20; + public const Int16 E_TEST_ACCOUNT_CREATED_MAIL_COULD_NOT_SENT = 21; + public const Int16 E_MAIL_COULD_NOT_SENT = 22; + public const Int16 E_RESELLER_ACCOUNT_CREATED_MAIL_COULD_NOT_SENT = 23; + public const Int16 E_LICENSE_TERM_CONDITION = 24; + public const Int16 E_EDITION_NOT_LINKED_WITH_SITE = 25; + public const Int16 E_LOGIN_SESSION_EXPIRE = 26; + public const Int16 E_DISCOUNT_CODE_NOT_EXIST = 27; + public const Int16 E_DISCOUNT_CODE_ALREADY_EXIST = 28; + + public const Int16 E_SITE_IP_NOT_NULL = 29; + public const Int16 E_EDITION_ID_NOT_NULL = 30; + public const Int16 E_MASTER_SITEIP_NOT_EXIST = 31; + public const Int16 EDITION_ID_NOT_EXIST = 32; + public const Int16 E_ERROR_LOG = 33; + public const Int16 E_MASTER_SITE_ALREADY_EXIST = 34; + public const Int16 E_ACCOUNT_NUMBER_NOT_NULL = 35; + public const Int16 E_SITE_IP_ALREADY_EXIST = 36; + + + public const Int16 E_LICENCE_IS_EXPIRED = 37; + public const Int16 E_SINGLEACCOUNT_IS_BEING_USED = 38; + + + public const Int16 E_DATA_BASE_CONNECTION = 4060; + + + //login failure error constant + public const int ACCOUNT_NUMBER_NOT_NULL = 4; + public const int EDITION_ID_NOT_NULL = 5; + public const int ACCOUNT_NUMBER_NOT_EXIST = 1; + public const int EDITION_NOT_EXIST = 3; + public const int MASTER_SITEIP_NOT_EXIST = 2; + public const int LICENSE_INACTIVE = 6; + + + /// + /// constructor + /// + private ErrorHelper() + { + objHash.Add(E_NO_ERROR, "No Error."); + objHash.Add(E_USER_NOT_EXIST, "Invalid User ID."); + objHash.Add(E_PASSWORD_NOT_MATCH, "Invalid Password. User ID and password will be disabled if your password is entered incorrectly for five consecutive attempts. If you have forgotten your password, please click on the forgot password link. "); + objHash.Add(E_USER_ID_BLOCKED_24_HRS, "User Id is blocked."); + objHash.Add(E_USER_NOT_ACTIVE, "User Id is Inactive."); + objHash.Add(E_USER_ID_WILL_BLOCKED, "Invalid Password. Your login will be blocked for a day if you enter wrong password one more time. Click on forgot password link if you have forgotten your password. "); + objHash.Add(E_EMAIL_ID_NOT_EXIT, "Invalid e-mail ID. If you do not know your correct e-mail ID please contact A.D.A.M. technical support at techsupport@adamcorp.com or your institution's site administrator. "); + objHash.Add(E_LICENCE_IS_INACTIVE, "Your Licence Is inactive."); + objHash.Add(E_USER_NOT_MAP_TO_LICENCE_EDITION, "User is not mapped with licence edition."); + objHash.Add(E_NO_ROW_FOUND_LICENCE_TO_EDITION_TABLE, "No row found in Licence to edition table."); + objHash.Add(E_NO_ROW_FOUND_LICENCE_TABLE, "No row found in Licence table."); + objHash.Add(E_SECURITY_QUEST_NOT_MATCH, "Your security question is incorrect. "); + objHash.Add(E_SEQURITY_ANSWER_NOT_MATCH, "Your answer is incorrect. "); + objHash.Add(E_FORGOT_USER_ID_EMAIL_ID_NOT_EXIT, "Invalid e-mail ID. If you do not know your correct e-mail ID please contact A.D.A.M. technical support at {0} or your institution's site administrator. "); + //objHash.Add(E_TOTAL_NUMBER_LOGIN_EXCEED, "User ID and password has been accessed by another user. Your session is currently timed out."); + objHash.Add(E_TOTAL_NUMBER_LOGIN_EXCEED, "Currently all licenses are in use. Any account that improperly logged out should automatically reset within 5 minutes."); + objHash.Add(E_FORGOT_PASSWORD_EMAIL_ID_NOT_EXIST, "Invalid e-mail ID. Please be sure to enter the e-mail ID used when you registered your license. "); + objHash.Add(E_TEST_SETUP_ACCOUNT_USER_NAME_EXIST, "User Name already exist in system."); + objHash.Add(E_TEST_SETUP_ACCOUNT_EMAILID_EXIST, "Email Id already exist system."); + objHash.Add(E_SP_ERROR, "Error occured in store procedure."); + objHash.Add(E_ACCOUNT_NUMBER_NOT_EXIST, "Account Number does not exist in the system. "); + objHash.Add(E_ACCOUNT_NUMBER_ALREADY_EXIST, "Account Number already exist in the system."); + objHash.Add(E_TEST_ACCOUNT_CREATED_MAIL_COULD_NOT_SENT, "Test account has been created. Account number is: {0}. Mail could not be sent due to some mail server error. "); + objHash.Add(E_MAIL_COULD_NOT_SENT, "Mail could not sent due to some mail server error."); + objHash.Add(E_RESELLER_ACCOUNT_CREATED_MAIL_COULD_NOT_SENT, "Licenses Have been created. Mail could not be sent due to some mail server error. "); + objHash.Add(E_LICENSE_TERM_CONDITION, "Your license is not enabled yet. Please contact your administrator to accept the term & condition."); + objHash.Add(E_EDITION_NOT_LINKED_WITH_SITE, "Your credentials are invalid. Please contact the site administrator of your institution or contact A.D.A.M. technical support at techsupport@adamcorp.com. "); + objHash.Add(E_LOGIN_SESSION_EXPIRE, "Your session has expired. Please log in."); + objHash.Add(E_DISCOUNT_CODE_NOT_EXIST, "Discount code not exist in the system."); + objHash.Add(E_DISCOUNT_CODE_ALREADY_EXIST, "Discount code already exist in the system."); + objHash.Add(E_SITE_IP_NOT_NULL, "SiteIP cannot be null."); + objHash.Add(E_DATA_BASE_CONNECTION, "Could not connect to Database."); + objHash.Add(E_EDITION_ID_NOT_NULL, "Edition Id cannot be zero."); + objHash.Add(E_MASTER_SITEIP_NOT_EXIST, "Master Site IP does not exist in the system."); + objHash.Add(EDITION_ID_NOT_EXIST, "Edition ID does not exist in the system."); + objHash.Add(E_ERROR_LOG, "Problem in database."); + objHash.Add(E_MASTER_SITE_ALREADY_EXIST, "Account already created from this URL."); + objHash.Add(E_ACCOUNT_NUMBER_NOT_NULL, "Account number cannot be null."); + objHash.Add(E_SITE_IP_ALREADY_EXIST, "Site IP already exist."); + objHash.Add(E_LICENCE_IS_EXPIRED, "Your licence is expired since {licenseExpirationDate}."); + objHash.Add(E_SINGLEACCOUNT_IS_BEING_USED, "This account is currently locked due to improper logout or another active browser session. The account should automatically reset within 5 minutes."); + } + /// + /// This method checks if instance of ErrorHelper class is exist then it returns + /// the exist instance else it creates the ErrorHelper class instance and return it. + /// + /// ErrorHelper instance + public static ErrorHelper GetInstance() + { + if (_instance == null) + { + _instance = new ErrorHelper(); + } + return _instance; + } + } +} \ 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 980a25d..bece065 100644 --- a/400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs +++ b/400-SOURCECODE/AIAHTML5.API/Controllers/AuthenticateController.cs @@ -8,6 +8,8 @@ using System.Net.Http; using System.Web.Http; using log4net; using AIAHTML5.API.Constants; +using AIAHTML5.API.Models; +using System.Collections; namespace AIAHTML5.API.Controllers { @@ -31,28 +33,336 @@ namespace AIAHTML5.API.Controllers ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); logger.Debug("inside POST"); - bool isUserAuthenticatedByDefault = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["isUserAuthenticated"]); - if (isUserAuthenticatedByDefault) - { - return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("true") }; + dynamic authenticationRepsonse; - } - else + try { - dynamic authenticationRepsonse = AIAHTML5.API.Models.Users.GetUserDetailsForAuthenticatedUser(credentials); - if (Convert.ToString(authenticationRepsonse) != AIAConstants.USER_NOT_FOUND && Convert.ToString(authenticationRepsonse) != AIAConstants.ERROR_IN_FECTHING_DETAILS) + //01.get the user detail for autheticate user + User userInfo = AIAHTML5.API.Models.Users.getUserDetails(credentials); + + if (userInfo.Id > 0) { - //string userDetails = Newtonsoft.Json.JsonConvert.SerializeObject(authenticationRepsonse); - return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(authenticationRepsonse) }; + // Check user is authenticated or not by login credential macth + 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); + + if (isUserAuthenticated && !isUserBlocked) + { + //01. Get User details + //userInfo = AIAHTML5.API.Models.Users.getUserDetails(credentials); + + //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); + } + + //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 details + userInfo.LicenseInfo = AIAHTML5.API.Models.Users.getLicenseDetails(userInfo.LicenseId); + + if (userInfo.LicenseInfo.Id > 0) + { + //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) + { + 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[AIAConstants.KEY_TITLE].ToString(); + userInfo.TermsOfServiceText = item[AIAConstants.KEY_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 + + } + } + } + } + + 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, userInfo, out isCorrectLoginId, out isCorrectPassword); + + if (isUserBlocked) + { + if (difference >= 0) + { + if (isCorrectPassword) + { + userInfo.IsBlocked = false; + userInfo.IsCorrectPassword = true; + + 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(); + + //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); + + if (userInfo.LicenseInfo.Id > 0) + { + //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 = false; + + if (userInfo.LicenseSubscriptions.Id > 0) + { + 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[AIAConstants.KEY_TITLE].ToString(); + userInfo.TermsOfServiceText = item[AIAConstants.KEY_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; + } + } + + } + + } + 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) + //{ + // // 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) + { + //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; + } + } + } + } + // 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 { - return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(authenticationRepsonse) }; - + authenticationRepsonse = AIAConstants.USER_NOT_FOUND; } } + 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; + } + + return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(authenticationRepsonse) }; } + // PUT api/authenticate/5 public void Put(int id, [FromBody]string value) diff --git a/400-SOURCECODE/AIAHTML5.API/Controllers/ForgotUserController.cs b/400-SOURCECODE/AIAHTML5.API/Controllers/ForgotUserController.cs index 17bac89..938cde0 100644 --- a/400-SOURCECODE/AIAHTML5.API/Controllers/ForgotUserController.cs +++ b/400-SOURCECODE/AIAHTML5.API/Controllers/ForgotUserController.cs @@ -75,8 +75,8 @@ namespace AIAHTML5.API.Controllers ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); logger.Debug("inside POST in ForgotUserController for emailId = " + userInfo["emailId"]); - User userData = AIAHTML5.API.Models.Users.GetUserByEmail(userInfo); - if (Convert.ToString(userData) != AIAConstants.USER_NOT_FOUND && Convert.ToString(userData) != AIAConstants.ERROR_IN_FECTHING_DETAILS) + dynamic userData = AIAHTML5.API.Models.Users.GetUserByEmail(userInfo); + if (Convert.ToString(userData) != AIAConstants.USER_NOT_FOUND && Convert.ToString(userData) != AIAConstants.ERROR_IN_FECTHING_DETAILS && Convert.ToString(userData) != AIAConstants.SQL_CONNECTION_ERROR) { //logger.Debug("inside if in ForgotUserController userData.loginId= " + userData.LoginId); bool isMailSent = false; @@ -85,9 +85,17 @@ namespace AIAHTML5.API.Controllers if (Convert.ToBoolean(userInfo["havePassword"])) { - logger.Debug("2. havePassword= " + Convert.ToBoolean(userInfo["havePassword"])); + if (Convert.ToBoolean(userInfo["unblockUser"])) + { + logger.Debug("2. unblockUser= " + Convert.ToBoolean(userInfo["unblockUser"])); + isMailSent = AIAHTML5.API.Models.UserUtility.SendEmail(userData, Convert.ToBoolean(userInfo["havePassword"]), Convert.ToBoolean(userInfo["unblockUser"])); + } + else + { + logger.Debug("2. havePassword= " + Convert.ToBoolean(userInfo["havePassword"])); + isMailSent = AIAHTML5.API.Models.UserUtility.SendEmail(userData, Convert.ToBoolean(userInfo["havePassword"])); + } - isMailSent = AIAHTML5.API.Models.UserUtility.SendEmail(userData, Convert.ToBoolean(userInfo["havePassword"])); } else { diff --git a/400-SOURCECODE/AIAHTML5.API/Controllers/LicenseTermConditionController.cs b/400-SOURCECODE/AIAHTML5.API/Controllers/LicenseTermConditionController.cs index 88e9042..0f3d9d1 100644 --- a/400-SOURCECODE/AIAHTML5.API/Controllers/LicenseTermConditionController.cs +++ b/400-SOURCECODE/AIAHTML5.API/Controllers/LicenseTermConditionController.cs @@ -8,6 +8,7 @@ using log4net; using AIAHTML5.API.Constants; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using AIAHTML5.API.Models; namespace AIAHTML5.API.Controllers { @@ -26,18 +27,35 @@ namespace AIAHTML5.API.Controllers } // POST api/licensetermcondition - public HttpResponseMessage Post([FromBody]string licenseeAccountNumber) + public HttpResponseMessage Post([FromBody]JObject userLicenseInfo) { ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); logger.Debug("inside POST"); HttpResponseMessage response = null; - int result = AIAHTML5.API.Models.Users.UpdateLicenseTerm(licenseeAccountNumber); - if (result > 0) - response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.LICENSE_TERM_CONDITION_UPDATE_SUCCESS) }; - else - response = new HttpResponseMessage { StatusCode = HttpStatusCode.InternalServerError, Content = new StringContent(AIAConstants.LICENSE_TERM_CONDITION_UPDATE_FAILED) }; + int licenseId = Convert.ToInt32(userLicenseInfo["userLicenseId"]); + User user = new User(); + dynamic userModules = null; // assigned to avoid unassigned local variable compilation error; + + dynamic result = AIAHTML5.API.Models.Users.UpdateLicenseTerm(userLicenseInfo); + if (Convert.ToString(result) != AIAConstants.SQL_CONNECTION_ERROR) + { + if (Convert.ToInt32(result) > 0) + { + user.Modules = Users.getModuleListByLicenseId(licenseId); + userModules = JsonConvert.SerializeObject(user); + response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(userModules) }; + } + else + { + response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.LICENSE_TERM_CONDITION_UPDATE_FAILED) }; + } + } + else + { + response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.SQL_CONNECTION_ERROR) }; + } return response; } diff --git a/400-SOURCECODE/AIAHTML5.API/Controllers/ResetPasswordController.cs b/400-SOURCECODE/AIAHTML5.API/Controllers/ResetPasswordController.cs index 24ede3d..4ad2e63 100644 --- a/400-SOURCECODE/AIAHTML5.API/Controllers/ResetPasswordController.cs +++ b/400-SOURCECODE/AIAHTML5.API/Controllers/ResetPasswordController.cs @@ -35,20 +35,24 @@ namespace AIAHTML5.API.Controllers { ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); logger.Debug("inside POST"); - User userData = AIAHTML5.API.Models.Users.GetUserByEmail(userInfo); + dynamic userData = AIAHTML5.API.Models.Users.GetUserByEmail(userInfo); HttpResponseMessage response = null; - if (Convert.ToString(userData) != AIAConstants.USER_NOT_FOUND && Convert.ToString(userData) != AIAConstants.ERROR_IN_FECTHING_DETAILS) + if (Convert.ToString(userData) != AIAConstants.USER_NOT_FOUND && Convert.ToString(userData) != AIAConstants.ERROR_IN_FECTHING_DETAILS && Convert.ToString(userData) != AIAConstants.SQL_CONNECTION_ERROR) { int result = 0; if (!String.IsNullOrEmpty(userInfo["newPassword"].ToString())) { - result = AIAHTML5.API.Models.Users.UpdatePassword(userInfo); + result = AIAHTML5.API.Models.Users.UpdatePassword(userInfo, userData.LoginId, userData.EmailId); if (result > 0) response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.PASSWORD_UPDATE_SUCCESS) }; else - response = new HttpResponseMessage { StatusCode = HttpStatusCode.InternalServerError, Content = new StringContent(AIAConstants.PASSWORD_UPDATE_FAILED) }; + response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.PASSWORD_UPDATE_FAILED) }; } } + else + { + response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(userData.ToString()) }; + } return response; } diff --git a/400-SOURCECODE/AIAHTML5.API/Controllers/UnblockUserController.cs b/400-SOURCECODE/AIAHTML5.API/Controllers/UnblockUserController.cs new file mode 100644 index 0000000..408b184 --- /dev/null +++ b/400-SOURCECODE/AIAHTML5.API/Controllers/UnblockUserController.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Web.Http; +using AIAHTML5.API.Constants; +using AIAHTML5.API.Models; +using AIAHTML5.API.Utility; +using log4net; + +namespace AIAHTML5.API.Controllers +{ + public class UnblockUserController : ApiController + { + // GET api/unblockuser + public IEnumerable Get() + { + return new string[] { "value1", "value2" }; + } + + // GET api/unblockuser/5 + public string Get(int id) + { + return "value"; + } + + // POST api/unblockuser + public HttpResponseMessage Post([FromBody]string emailId) + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug("inside POST in UnblockUserController for emailId = " + emailId); + + HttpResponseMessage response = null; + + dynamic user = AIAHTML5.API.Models.DBModel.GetUserDetailsByEmailId(emailId); + if (Convert.ToString(user) != AIAConstants.USER_NOT_FOUND && Convert.ToString(user) != AIAConstants.ERROR_IN_FECTHING_DETAILS) + { + int result = 0; + + logger.Debug("1. inside if in UnblockUserController userDetails= " + user.ToString()); + + result = AIAHTML5.API.Models.DBModel.UnblockUser(user.Id); + + if (result > 0) + response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.USER_UNBLOCK_SUCCESS) }; + else + response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.USER_ALREADY_UNBLOCKED) }; + } + //else + //{ + // logger.Debug("inside else in UnblockUserController userData= " + user); + // return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(user.ToString()) }; + //} + return response; + } + + // PUT api/unblockuser/5 + public void Put(int id, [FromBody]string value) + { + } + + // DELETE api/unblockuser/5 + public void Delete(int id) + { + } + } +} \ No newline at end of file diff --git a/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs b/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs index c7a1be5..94c7570 100644 --- a/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs +++ b/400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs @@ -30,23 +30,16 @@ namespace AIAHTML5.API.Models conn.Open(); } - protected static DataSet GetSQLData(string commandText, bool isSp) + protected static DataSet GetDataFromStoredProcedure(string commandText) { ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); - logger.Debug(" inside GetSQLData for command text = " + commandText); - DataSet ds= null; + logger.Debug(" Inside GetSQLData for command text = " + commandText); + DataSet ds = null; try { conn = new SqlConnection(dbConnectionString); - if (isSp) - { - cmd = new SqlCommand(commandText, conn); - cmd.CommandType = CommandType.StoredProcedure; - } - else - { - cmd = new SqlCommand(commandText, conn); - } + cmd = new SqlCommand(commandText, conn); + cmd.CommandType = CommandType.StoredProcedure; SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; ds = new DataSet(); @@ -54,269 +47,216 @@ namespace AIAHTML5.API.Models } catch (SqlException ex) { - logger.Fatal("Exception in GetSQLData for command text =" + commandText + ", Exception= " + ex.Message); + logger.Fatal("Exception in GetSQLData for command text =" + commandText + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace); + throw; } return ds; } - protected ArrayList GetUserModules() + internal ArrayList GetAllModules() { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug(" Inside GetAllModules"); + ArrayList arrUserModules = new ArrayList(); - Hashtable userModuleHash = null; - userModuleHash = new Hashtable(); - string sp = "GetAllModuleStatusWithSlug"; + try + { + Hashtable userModuleHash = new Hashtable(); - DataSet ds = DBModel.GetSQLData(sp, true); - DataTable dt = ds.Tables[0]; + string sp = DBConstants.GET_ALL_MODULES; - foreach (DataRow drActType in dt.Rows) + DataSet ds = DBModel.GetDataFromStoredProcedure(sp); + + if (ds.Tables.Count > 0) + { + DataTable dt = ds.Tables[0]; + + foreach (DataRow drModule in dt.Rows) + { + userModuleHash = new Hashtable(); + userModuleHash.Add(AIAConstants.KEY_NAME, drModule["Name"]); + userModuleHash.Add(AIAConstants.KEY_SLUG, drModule["Slug"]); + arrUserModules.Add(userModuleHash); + } + } + } + catch (SqlException ex) { - userModuleHash = new Hashtable(); - userModuleHash.Add(AIAConstants.KEY_NAME, drActType["Name"]); - userModuleHash.Add(AIAConstants.KEY_SLUG, drActType["Slug"]); - arrUserModules.Add(userModuleHash); + logger.Fatal("Exception in GetAllModules , Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace); + throw; } return arrUserModules; } - public static dynamic GetUserDetailsByLoginIdAndPassword(string loginId, string password) + internal static User GetUserDetailsByLoginId(string loginId) { - User objUser = new User(); - DBModel objModel = new DBModel(); + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug(" Inside GetUserDetailsByLoginId for LoginId = " + loginId); - conn = new SqlConnection(dbConnectionString); - cmd = new SqlCommand(); - SqlDataAdapter da = new SqlDataAdapter(); - SqlParameter param; - DataSet ds = new DataSet(); + User objUser = null; + DBModel objModel = new DBModel(); - cmd.Connection = conn; - cmd.CommandText = "GetUserDetailsByLoginIdAndPassword"; - cmd.CommandType = CommandType.StoredProcedure; + try + { + conn = new SqlConnection(dbConnectionString); + cmd = new SqlCommand(); + SqlDataAdapter da = new SqlDataAdapter(); + SqlParameter param; + DataSet ds = new DataSet(); - param = new SqlParameter("@sLoginId", loginId); - param.Direction = ParameterDirection.Input; - param.DbType = DbType.String; - cmd.Parameters.Add(param); + cmd.Connection = conn; + cmd.CommandText = DBConstants.GET_USER_DELAILS_BY_LOGIN_ID; + cmd.CommandType = CommandType.StoredProcedure; - param = new SqlParameter("@sPassword", password); - param.Direction = ParameterDirection.Input; - param.DbType = DbType.String; - cmd.Parameters.Add(param); + param = new SqlParameter("@sLoginId", loginId); + param.Direction = ParameterDirection.Input; + param.DbType = DbType.String; + cmd.Parameters.Add(param); - da.SelectCommand = cmd; - DataTable dt = new DataTable(); - da.Fill(dt); + da.SelectCommand = cmd; + DataTable dt = new DataTable(); + da.Fill(dt); + - if (dt.Rows.Count > 0) - { - foreach (DataRow dr in dt.Rows) + if (dt.Rows.Count > 0) { - foreach (DataColumn dc in dt.Columns) + foreach (DataRow dr in dt.Rows) { - if (dc.ColumnName == "Id") - objUser.Id = Convert.ToInt32(dr[dc]); - if (dc.ColumnName == "FirstName") - objUser.FirstName = dr[dc].ToString(); - if (dc.ColumnName == "LastName") - objUser.LastName = dr[dc].ToString(); - if (dc.ColumnName == "EmailId") - objUser.EmailId = dr[dc].ToString(); - if (dc.ColumnName == "LoginId") - objUser.LoginId = dr[dc].ToString(); - if (dc.ColumnName == "Password") - objUser.Password = dr[dc].ToString(); - if (dc.ColumnName == "SecurityQuestionId") - { - int tempVal; - objUser.SecurityQuestionId = Int32.TryParse(dr[dc].ToString(), out tempVal) ? tempVal : (int?)null; - } - if (dc.ColumnName == "SecurityAnswer") - objUser.SecurityAnswer = dr[dc].ToString(); - if (dc.ColumnName == "CreatorId") - { - int tempVal; - objUser.CreatorId = Int32.TryParse(dr[dc].ToString(), out tempVal) ? tempVal : (int?)null; - } - if (dc.ColumnName == "CreationDate") - objUser.CreationDate = Convert.ToDateTime(dr[dc]); - if (dc.ColumnName == "DeactivationDate") - { - DateTime? date; - if (dr[dc] == DBNull.Value) - date = null; - else - date = (DateTime)dr[dc]; - - objUser.DeactivationDate = date; - } - if (dc.ColumnName == "ModifierId") - { - int tempVal; - objUser.ModifierId = Int32.TryParse(dr[dc].ToString(), out tempVal) ? tempVal : (int?)null; - } - if (dc.ColumnName == "ModifiedDate") - { - DateTime? date; - if (dr[dc] == DBNull.Value) - date = null; - else - date = (DateTime)dr[dc]; - - objUser.ModifiedDate = date; - } - if (dc.ColumnName == "UserTypeId") - objUser.UserType = objModel.GetUserTypeStringById(Convert.ToInt32(dr[dc])); - if (dc.ColumnName == "IsActive") - objUser.IsActive = Convert.ToBoolean(dr[dc]); - + int tempVal; + DateTime date; + objUser = new User(); + + objUser.Id = Convert.ToInt32(dr["Id"]); + objUser.FirstName = dr["FirstName"].ToString(); + objUser.LastName = dr["LastName"].ToString(); + objUser.EmailId = dr["EmailId"].ToString(); + objUser.LoginId = dr["LoginId"].ToString(); + objUser.Password = dr["Password"].ToString(); + objUser.SecurityQuestionId =Int32.TryParse(dr["SecurityQuestionId"].ToString(), out tempVal) ? tempVal : (int?)null; + objUser.SecurityAnswer = dr["SecurityAnswer"].ToString(); ; + objUser.CreatorId = Int32.TryParse(dr["CreatorId"].ToString(), out tempVal) ? tempVal : (int?)null; + objUser.CreationDate = Convert.ToDateTime(dr["CreationDate"]); + objUser.DeactivationDate = DateTime.TryParse(dr["DeactivationDate"].ToString(), out date) ? date : (DateTime?)null; + objUser.ModifierId = Int32.TryParse(dr["ModifierId"].ToString(), out tempVal) ? tempVal : (int?)null; + objUser.ModifiedDate = DateTime.TryParse(dr["ModifiedDate"].ToString(), out date) ? date : (DateTime?)null; + objUser.UserTypeId = Convert.ToInt32(dr["UserTypeId"]); + objUser.UserType = objModel.GetUserTypeStringById(Convert.ToInt32(dr["UserTypeId"])); + objUser.IsActive = Convert.ToBoolean(dr["IsActive"]); } } + else + { + objUser = new User(); + } } - - else - { - objUser = null; + catch (SqlException ex) + { + logger.Fatal("Exception in GetUserDetailsByLoginId for LoginId: " + loginId + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace); + throw; } + return objUser; + } + + internal Hashtable GetLicenseDetailByUserId(int userId) + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug(" Inside GetUserLicenseDetailByUserId for UserId = " + userId); - if (objUser != null) + Hashtable hash = new Hashtable(); + + try { + conn = new SqlConnection(dbConnectionString); + cmd = new SqlCommand(); + SqlDataAdapter adapter; + SqlParameter param; + DataSet ds = new DataSet(); - int licenseId = objModel.GetUserLicenseIdByUserId(objUser.Id); - if (licenseId != 0) - { - objUser.License = objModel.GetLicenseDetailsByLicenseId(licenseId); - objUser.LicenseSubscriptions = objModel.GetLicenseSubscriptionDetailsByLicenseId(licenseId); - } - else - { - objUser.License = null; - } + cmd.Connection = conn; + cmd.CommandText = DBConstants.GET_LICENSE_DETAILS_BY_USER_ID; + cmd.CommandType = CommandType.StoredProcedure; - if (objUser.UserType == User.SUPER_ADMIN || objUser.UserType == User.GENERAL_ADMIN) - { - objUser.Modules = objModel.GetUserModules(); - } - else + param = new SqlParameter("@iUserId", userId); + param.Direction = ParameterDirection.Input; + param.DbType = DbType.Int32; + cmd.Parameters.Add(param); + + adapter = new SqlDataAdapter(cmd); + adapter.Fill(ds); + + if (ds.Tables.Count > 0) { - if (objUser.License != null) + if (ds.Tables[0].Rows.Count > 0) { - if (objUser.LicenseSubscriptions != null) - { - DateTime? subscriptionValidThrough = objUser.LicenseSubscriptions.SubscriptionValidThrough; - if (subscriptionValidThrough != null && subscriptionValidThrough.Value.Date >= DateTime.Now.Date) - { - ArrayList allModulesList = objModel.GetUserModules(); - ArrayList licensedModulesList = objModel.GetModuleStatusByLicenseId(licenseId); - - ArrayList userModuleList = objModel.GetUserModulesList(allModulesList, licensedModulesList); - objUser.Modules = userModuleList; - - if (!objUser.License.IsTermAccepted) - { - ArrayList termsList = DBModel.GetTermsOfServiceText(); - foreach(Hashtable item in termsList) - { - objUser.TermsOfServiceTitle = item["title"].ToString(); - objUser.TermsOfServiceText = item["content"].ToString(); - } - } - } - else - { - objUser.IsSubscriptionExpired = true; - objUser.SubscriptionExpirationDateString = objUser.LicenseSubscriptions.SubscriptionValidThrough.Value.Date.ToString("MM/dd/yyyy").ToString(); - } - } + hash.Add(AIAConstants.LICENSE_KEY_ID, ds.Tables[0].Rows[0][0]); + hash.Add(AIAConstants.EDITION_KEY_ID, ds.Tables[0].Rows[0][1]); } } } + catch (SqlException ex) + { + logger.Fatal("Exception in GetUserLicenseDetailByUserId for UserId= " + userId + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace); + throw; + } - return objUser; + return hash; } - protected int GetUserLicenseIdByUserId(int userId) + internal ArrayList GetUserModulesByLicenseId(int licenseId) { - int _licenseId = 0; - conn = new SqlConnection(dbConnectionString); - cmd = new SqlCommand(); - SqlDataAdapter adapter; - SqlParameter param; - DataSet ds = new DataSet(); - - cmd.Connection = conn; - cmd.CommandText = "GetLicenseIdByUserId"; - cmd.CommandType = CommandType.StoredProcedure; - - param = new SqlParameter("@iUserId", userId); - param.Direction = ParameterDirection.Input; - param.DbType = DbType.Int32; - cmd.Parameters.Add(param); - - adapter = new SqlDataAdapter(cmd); - adapter.Fill(ds); - if (ds.Tables[0].Rows.Count > 0) - _licenseId = Convert.ToInt32(ds.Tables[0].Rows[0][0]); - return _licenseId; - } + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug(" Inside GetUserModulesByLicenseId for LicenseId = " + licenseId); - protected ArrayList GetModuleStatusByLicenseId(int licenseId) - { ArrayList userModulelist = new ArrayList(); - Hashtable modulesHash; - DataSet ds = new DataSet(); - - conn = new SqlConnection(dbConnectionString); - cmd = new SqlCommand(); - SqlDataAdapter adapter; - SqlParameter param; - cmd.Connection = conn; - cmd.CommandText = "GetModuleStatusByLicenseId"; - cmd.CommandType = CommandType.StoredProcedure; + try + { + Hashtable modulesHash; + DataSet ds = new DataSet(); - param = new SqlParameter("@iLicenseId", licenseId); - param.Direction = ParameterDirection.Input; - param.DbType = DbType.Int32; - cmd.Parameters.Add(param); + conn = new SqlConnection(dbConnectionString); + cmd = new SqlCommand(); + SqlDataAdapter adapter; + SqlParameter param; - adapter = new SqlDataAdapter(cmd); - adapter.Fill(ds); - DataTable dt = ds.Tables[0]; + cmd.Connection = conn; + cmd.CommandText = DBConstants.GET_USER_MODULES_BY_LICENSE_ID; + cmd.CommandType = CommandType.StoredProcedure; - foreach (DataRow dr in dt.Rows) - { - modulesHash = new Hashtable(); - modulesHash.Add("Id", dr["Id"]); - modulesHash.Add("Title", dr["Title"]); - modulesHash.Add("Status", dr["Status"]); - userModulelist.Add(modulesHash); - } + param = new SqlParameter("@iLicenseId", licenseId); + param.Direction = ParameterDirection.Input; + param.DbType = DbType.Int32; + cmd.Parameters.Add(param); - return userModulelist; - } + adapter = new SqlDataAdapter(cmd); + adapter.Fill(ds); + - protected ArrayList GetUserModulesList(ArrayList allModules, ArrayList modulesByLicense) - { - ArrayList userModules = new ArrayList(); - Hashtable moduleHash; - foreach (Hashtable module in allModules) - { - foreach (Hashtable userModule in modulesByLicense) + if (ds.Tables.Count > 0) { - if ((userModule["Title"].ToString().Trim() == module["name"].ToString().Trim()) && (Convert.ToBoolean(userModule["Status"]) == true)) - { - moduleHash = new Hashtable(); - moduleHash.Add("name", userModule["Title"]); - moduleHash.Add("slug", module["slug"]); + DataTable dt = ds.Tables[0]; - userModules.Add(moduleHash); + if (dt.Rows.Count > 0) + { + foreach (DataRow dr in dt.Rows) + { + modulesHash = new Hashtable(); + modulesHash.Add(AIAConstants.KEY_NAME, dr["Title"]); + modulesHash.Add(AIAConstants.KEY_SLUG, dr["Slug"]); + userModulelist.Add(modulesHash); + } } } } - return userModules; + catch (SqlException ex) + { + logger.Fatal("Exception in GetUserModulesByLicenseId for LicenseId = " + licenseId + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace); + throw; + } + + return userModulelist; } protected string GetUserTypeStringById(int userTypeId) @@ -325,44 +265,48 @@ namespace AIAHTML5.API.Models switch (userTypeId) { - case 1: + case (int)UserType.SUPER_ADMIN: userType = User.SUPER_ADMIN; break; - case 2: + case (int)UserType.GENERAL_ADMIN: userType = User.GENERAL_ADMIN; break; - case 3: + case (int)UserType.DISTRICT_ADMIN: userType = User.DISTRICT_ADMIN; break; - case 4: + case (int)UserType.CLIENT_ADMIN: userType = User.CLIENT_ADMIN; break; - case 5: + case (int)UserType.SINGLE_USER: userType = User.SINGLE_USER; break; - case 6: + case (int)UserType.CONCURRENT_USER: userType = User.CONCURRENT_USER; break; - case 7: + case (int)UserType.RESELLER: userType = User.RESELLER; break; - case 8: + case (int)UserType.TEST_ACCOUNT: userType = User.TEST_ACCOUNT; break; - case 9: + case (int)UserType.SITE_USER: userType = User.SITE_USER; break; } return userType; } - public static User GetUserDetailsByEmailId(string emailId) + internal static User GetUserDetailsByEmailId(string emailId) { - User objUser = new User(); + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug(" Inside GetUserDetailsByEmailId for emailId = " + emailId); + + User objUser = null; DBModel objModel = new DBModel(); try { + conn = new SqlConnection(dbConnectionString); cmd = new SqlCommand(); SqlDataAdapter adapter; @@ -370,7 +314,7 @@ namespace AIAHTML5.API.Models DataSet ds = new DataSet(); cmd.Connection = conn; - cmd.CommandText = "GetUserInfoByEmailId"; + cmd.CommandText = DBConstants.GET_USER_DETAILS_BY_EMAILID; cmd.CommandType = CommandType.StoredProcedure; param = new SqlParameter("@sEmailId", emailId); @@ -380,96 +324,92 @@ namespace AIAHTML5.API.Models adapter = new SqlDataAdapter(cmd); adapter.Fill(ds); - DataTable dt = ds.Tables[0]; - foreach (DataRow dr in dt.Rows) + + if (ds.Tables.Count > 0) { - foreach (DataColumn dc in dt.Columns) - { - if (dc.ColumnName == "Id") - objUser.Id = Convert.ToInt32(dr[dc]); - if (dc.ColumnName == "FirstName") - objUser.FirstName = dr[dc].ToString(); - if (dc.ColumnName == "LastName") - objUser.LastName = dr[dc].ToString(); - if (dc.ColumnName == "EmailId") - objUser.EmailId = dr[dc].ToString(); - if (dc.ColumnName == "LoginId") - objUser.LoginId = dr[dc].ToString(); - if (dc.ColumnName == "Password") - objUser.Password = dr[dc].ToString(); - if (dc.ColumnName == "SecurityQuestionId") - { - int tempVal; - objUser.SecurityQuestionId = Int32.TryParse(dr[dc].ToString(), out tempVal) ? tempVal : (int?)null; - } - if (dc.ColumnName == "SecurityAnswer") - objUser.SecurityAnswer = dr[dc].ToString(); - if (dc.ColumnName == "CreatorId") - { - int tempVal; - objUser.CreatorId = Int32.TryParse(dr[dc].ToString(), out tempVal) ? tempVal : (int?)null; - } - if (dc.ColumnName == "CreationDate") - objUser.CreationDate = Convert.ToDateTime(dr[dc]); - if (dc.ColumnName == "DeactivationDate") - { - DateTime? date; - if (dr[dc] == DBNull.Value) - date = null; - else - date = (DateTime)dr[dc]; + DataTable dt = ds.Tables[0]; - objUser.DeactivationDate = date; - } - if (dc.ColumnName == "ModifierId") + if (dt.Rows.Count > 0) + { + foreach (DataRow dr in dt.Rows) { int tempVal; - objUser.ModifierId = Int32.TryParse(dr[dc].ToString(), out tempVal) ? tempVal : (int?)null; + DateTime date; + objUser = new User(); + + objUser.Id = Convert.ToInt32(dr["Id"]); + objUser.FirstName = dr["FirstName"].ToString(); + objUser.LastName = dr["LastName"].ToString(); + objUser.EmailId = dr["EmailId"].ToString(); + objUser.LoginId = dr["LoginId"].ToString(); + objUser.Password = dr["Password"].ToString(); + objUser.SecurityQuestionId = Int32.TryParse(dr["SecurityQuestionId"].ToString(), out tempVal) ? tempVal : (int?)null; + objUser.SecurityAnswer = dr["SecurityAnswer"].ToString(); ; + objUser.CreatorId = Int32.TryParse(dr["CreatorId"].ToString(), out tempVal) ? tempVal : (int?)null; + objUser.CreationDate = Convert.ToDateTime(dr["CreationDate"]); + objUser.DeactivationDate = DateTime.TryParse(dr["DeactivationDate"].ToString(), out date) ? date : (DateTime?)null; + objUser.ModifierId = Int32.TryParse(dr["ModifierId"].ToString(), out tempVal) ? tempVal : (int?)null; + objUser.ModifiedDate = DateTime.TryParse(dr["ModifiedDate"].ToString(), out date) ? date : (DateTime?)null; + objUser.UserTypeId = Convert.ToInt32(dr["UserTypeId"]); + objUser.UserType = objModel.GetUserTypeStringById(Convert.ToInt32(dr["UserTypeId"])); + objUser.IsActive = Convert.ToBoolean(dr["IsActive"]); } - if (dc.ColumnName == "ModifiedDate") - { - DateTime? date; - if (dr[dc] == DBNull.Value) - date = null; - else - date = (DateTime)dr[dc]; - - objUser.ModifiedDate = date; - } - if (dc.ColumnName == "UserTypeId") - objUser.UserType = objModel.GetUserTypeStringById(Convert.ToInt32(dr[dc])); - if (dc.ColumnName == "IsActive") - objUser.IsActive = Convert.ToBoolean(dr[dc]); - } } + else + { + objUser = new User (); + } + } + catch (SqlException ex) + { + logger.Fatal("Exception in GetUserDetailsByEmailId for emailId = " + emailId + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace); + throw; } - catch (Exception ex) - { } return objUser; } - public static int UpdateUserPassword(dynamic userInfo) + internal static int UpdateUserPassword(dynamic userInfo, string loginId, string emailId) { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug(" Inside UpdateUserPassword for LoginId: " + loginId + ", EmailId: " + emailId); + int result = 0; - conn = new SqlConnection(dbConnectionString); - cmd = new SqlCommand(); - cmd.Connection = conn; - conn.Open(); - cmd.CommandText = "UpdateUserPassword"; - cmd.CommandType = CommandType.StoredProcedure; - cmd.Parameters.AddWithValue("@sLoginId", userInfo["loginId"].ToString()); - cmd.Parameters.AddWithValue("@sEmailId", userInfo["emailId"].ToString()); - cmd.Parameters.AddWithValue("@sNewPassword", userInfo["newPassword"].ToString()); - result = cmd.ExecuteNonQuery(); - conn.Close(); + + try + { + conn = new SqlConnection(dbConnectionString); + cmd = new SqlCommand(); + cmd.Connection = conn; + conn.Open(); + cmd.CommandText = DBConstants.UPDATE_USER_PASSWORD; + cmd.CommandType = CommandType.StoredProcedure; + cmd.Parameters.AddWithValue("@sLoginId", loginId); + cmd.Parameters.AddWithValue("@sEmailId", emailId); + cmd.Parameters.AddWithValue("@sNewPassword", userInfo["newPassword"].ToString()); + result = cmd.ExecuteNonQuery(); + conn.Close(); + } + catch (SqlException ex) + { + conn.Close(); + logger.Fatal("Exception in UpdateUserPassword for LoginId: " + loginId + ", EmailId: " + emailId + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace); + throw; + } + finally + { + conn.Dispose(); + } return result; } - protected LicenseSubscriptionDetails GetLicenseSubscriptionDetailsByLicenseId(int licenseId) + internal LicenseSubscriptionDetails GetLicenseSubscriptionDetailsByLicenseId(int licenseId) { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug(" Inside GetLicenseSubscriptionDetailsByLicenseId for LicenseId = " + licenseId); + LicenseSubscriptionDetails lsd = new LicenseSubscriptionDetails(); try { @@ -480,7 +420,7 @@ namespace AIAHTML5.API.Models DataSet ds = new DataSet(); cmd.Connection = conn; - cmd.CommandText = "GetSubscriptionDetailsByLicenseId"; + cmd.CommandText = DBConstants.GET_SUBSCRIPTION_DETAILS_BY_LICENSE_ID; cmd.CommandType = CommandType.StoredProcedure; param = new SqlParameter("@iLicenseId", licenseId); @@ -489,76 +429,52 @@ namespace AIAHTML5.API.Models cmd.Parameters.Add(param); adapter = new SqlDataAdapter(cmd); - adapter.Fill(ds); - DataTable dt = ds.Tables[0]; + adapter.Fill(ds); - foreach (DataRow dr in dt.Rows) + if (ds.Tables.Count > 0) { - foreach (DataColumn dc in dt.Columns) + DataTable dt = ds.Tables[0]; + + if (dt.Rows.Count > 0) { - if (dc.ColumnName == "Id") - lsd.Id = Convert.ToInt32(dr[dc]); - if (dc.ColumnName == "LicenseId") - lsd.LicenseId = Convert.ToInt32(dr[dc]); - if (dc.ColumnName == "SubscriptionPlanId") + foreach (DataRow dr in dt.Rows) { int tempVal; - lsd.SubscriptionPlanId = Int32.TryParse(dr[dc].ToString(), out tempVal) ? tempVal : (int?)null; - } - if (dc.ColumnName == "SubscriptionValidFrom") - { - DateTime? date; - if (dr[dc] == DBNull.Value) - date = null; - else - date = (DateTime)dr[dc]; - - lsd.SubscriptionValidFrom = date; + DateTime date; + lsd.Id = Convert.ToInt32(dr["Id"]); + lsd.LicenseId = Convert.ToInt32(dr["LicenseId"]); + lsd.SubscriptionPlanId = Int32.TryParse(dr["SubscriptionPlanId"].ToString(), out tempVal) ? tempVal : (int?)null; + lsd.SubscriptionValidFrom = DateTime.TryParse(dr["SubscriptionValidFrom"].ToString(), out date) ? date : (DateTime?)null; + lsd.SubscriptionValidThrough = DateTime.TryParse(dr["SubscriptionValidThrough"].ToString(), out date) ? date : (DateTime?)null; + lsd.RenewalDate = DateTime.TryParse(dr["RenewalDate"].ToString(), out date) ? date : (DateTime?)null; + lsd.PaymentMode = dr["PaymentMode"].ToString(); + lsd.TotalAmount = Convert.ToDouble(dr["TotalAmount"]); + lsd.AmountPaid = Convert.ToDouble(dr["AmountPaid"]); + lsd.AmountPending = Convert.ToDouble(dr["AmountPending"]); + lsd.NoOfImages = Convert.ToInt32(dr["NoofImages"]); } - if (dc.ColumnName == "SubscriptionValidThrough") - { - DateTime? date; - if (dr[dc] == DBNull.Value) - date = null; - else - date = (DateTime)dr[dc]; - - lsd.SubscriptionValidThrough = date; - } - if (dc.ColumnName == "RenewelDate") - { - DateTime? date; - if (dr[dc] == DBNull.Value) - date = null; - else - date = (DateTime)dr[dc]; - - lsd.RenewalDate = date; - } - if (dc.ColumnName == "PaymentMode") - lsd.PaymentMode = dr[dc].ToString(); - if (dc.ColumnName == "TotalAmount") - lsd.TotalAmount = Convert.ToDouble(dr[dc]); - if (dc.ColumnName == "AmountPaid") - lsd.AmountPaid = Convert.ToDouble(dr[dc]); - if (dc.ColumnName == "AmountPending") - lsd.AmountPending = Convert.ToDouble(dr[dc]); - if (dc.ColumnName == "NoofImages") - lsd.NoOfImages = Convert.ToInt32(dr[dc]); } } + else + { + lsd = new LicenseSubscriptionDetails (); + } + } catch (Exception ex) { - + logger.Fatal("Exception in GetLicenseSubscriptionDetailsByLicenseId for LicenseId= " + licenseId + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace); } return lsd; } - protected License GetLicenseDetailsByLicenseId(int licenseId) + internal License GetLicenseDetailsByLicenseId(int licenseId) { - License lic = new License(); + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug(" inside GetLicenseDetailsByLicenseId for LicenseId = " + licenseId); + + License license = new License(); try { conn = new SqlConnection(dbConnectionString); @@ -568,7 +484,7 @@ namespace AIAHTML5.API.Models DataSet ds = new DataSet(); cmd.Connection = conn; - cmd.CommandText = "GetLicenseDetailsById"; + cmd.CommandText = DBConstants.GET_LICENSE_DETAILS_BY_ID; cmd.CommandType = CommandType.StoredProcedure; param = new SqlParameter("@Id", licenseId); @@ -578,89 +494,68 @@ namespace AIAHTML5.API.Models adapter = new SqlDataAdapter(cmd); adapter.Fill(ds); - DataTable dt = ds.Tables[0]; - foreach (DataRow dr in dt.Rows) + if (ds.Tables.Count > 0) { - foreach (DataColumn dc in dt.Columns) + DataTable dt = ds.Tables[0]; + if (dt.Rows.Count > 0) { - if (dc.ColumnName == "Id") - lic.Id = Convert.ToInt32(dr[dc]); - if (dc.ColumnName == "AccountNumber") - lic.AccountNumber = dr[dc].ToString(); - if (dc.ColumnName == "LicenseeFirstName") - lic.LicenseeFirstName = dr[dc].ToString(); - if (dc.ColumnName == "LicenseeLastName") - lic.LicenseeLastName = dr[dc].ToString(); - if (dc.ColumnName == "LicenseTypeId") - lic.LicenseTypeId = Convert.ToInt32(dr[dc]); - if (dc.ColumnName == "InstitutionName") - lic.InstitutionName = dr[dc].ToString(); - if (dc.ColumnName == "Address1") - lic.Address1 = dr[dc].ToString(); - if (dc.ColumnName == "Address2") - lic.Address2 = dr[dc].ToString(); - if (dc.ColumnName == "CountryId") - lic.CountryId = Convert.ToInt32(dr[dc]); - if (dc.ColumnName == "StateId") - lic.StateId = Convert.ToInt32(dr[dc]); - if (dc.ColumnName == "City") - lic.City = dr[dc].ToString(); - if (dc.ColumnName == "Zip") - lic.Zip = dr[dc].ToString(); - if (dc.ColumnName == "Phone") - lic.Phone = dr[dc].ToString(); - if (dc.ColumnName == "EmailId") - lic.EmailId = dr[dc].ToString(); - if (dc.ColumnName == "TotalLogins") - lic.TotalLogins = Convert.ToInt32(dr[dc]); - if (dc.ColumnName == "AccountTypeId") - lic.AccountTypeId = Convert.ToInt32(dr[dc]); - if (dc.ColumnName == "IsActive") - lic.IsActive = Convert.ToBoolean(dr[dc]); - if (dc.ColumnName == "IsDistrictSiteLicense") - lic.IsDistrictSiteLicense = Convert.ToBoolean(dr[dc]); - if (dc.ColumnName == "CreationDate") - lic.CreationDate = Convert.ToDateTime(dr[dc]); - if (dc.ColumnName == "ModifiedDate") + foreach (DataRow dr in dt.Rows) { - DateTime? date; - if (dr[dc] == DBNull.Value) - date = null; - else - date = (DateTime)dr[dc]; - - lic.ModifiedDate = date; + DateTime date; + license.Id = Convert.ToInt32(dr["Id"]); + license.AccountNumber = dr["AccountNumber"].ToString(); + license.LicenseeFirstName = dr["LicenseeFirstName"].ToString(); + license.LicenseeLastName = dr["LicenseeLastName"].ToString(); + license.LicenseTypeId = Convert.ToInt32(dr["LicenseTypeId"]); + license.InstitutionName = dr["InstitutionName"].ToString(); + license.Address1 = dr["Address1"].ToString(); + license.Address2 = dr["Address2"].ToString(); + license.CountryId = Convert.ToInt32(dr["CountryId"]); + license.StateId = Convert.ToInt32(dr["StateId"]); + license.City = dr["City"].ToString(); + license.Zip = dr["Zip"].ToString(); + license.Phone = dr["Phone"].ToString(); + license.EmailId = dr["EmailId"].ToString(); + license.TotalLogins = Convert.ToInt32(dr["TotalLogins"]); + license.AccountTypeId = Convert.ToInt32(dr["AccountTypeId"]); + license.IsActive = Convert.ToBoolean(dr["IsActive"]); + license.IsDistrictSiteLicense = Convert.ToBoolean(dr["IsDistrictSiteLicense"]); + license.CreationDate = Convert.ToDateTime(dr["CreationDate"]); + license.ModifiedDate = DateTime.TryParse(dr["ModifiedDate"].ToString(), out date) ? date : (DateTime?)null; + license.NoOfRenewals = Convert.ToInt32(dr["NoOfRenewals"]); + license.IsTermAccepted = Convert.ToBoolean(dr["IsTermsAccepted"]); + license.ProductId = dr["ProductId"].ToString(); } - if (dc.ColumnName == "NoOfRenewals") - lic.NoOfRenewals = Convert.ToInt32(dr[dc]); - if (dc.ColumnName == "IsTermsAccepted") - lic.IsTermAccepted = Convert.ToBoolean(dr[dc]); - if (dc.ColumnName == "ProductId") - lic.ProductId = dr[dc].ToString(); } } + else + { + license = new License (); + } } catch (Exception ex) { - + logger.Fatal("Exception in GetLicenseDetailsByLicenseId for LicenseId= " + licenseId + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace); } - return lic; + return license; } - public static int UpdateLicenseTermStatus(string accountNumber) + internal static int UpdateLicenseTermStatus(string accountNumber) { ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); - logger.Debug(" inside UpdateTermAcceptedStatus for AccountNumber = " + accountNumber); + logger.Debug(" inside UpdateLicenseTermStatus for AccountNumber = " + accountNumber); + int result = 0; + try - { + { conn = new SqlConnection(dbConnectionString); cmd = new SqlCommand(); cmd.Connection = conn; conn.Open(); - cmd.CommandText = "UpdateLicenseTermAcceptedStatus"; + cmd.CommandText = DBConstants.UPDATE_LICENSE_TERM_STATUS; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@sAccountNumber", accountNumber); result = cmd.ExecuteNonQuery(); @@ -668,29 +563,427 @@ namespace AIAHTML5.API.Models } catch (SqlException ex) { - conn.Close(); - logger.Fatal("Exception in UpdateLicenseTermStatus for AccountNumber =" + accountNumber + ", Exception= " + ex.Message); + logger.Fatal("Exception in UpdateLicenseTermStatus for AccountNumber =" + accountNumber + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace); + throw; } return result; } - protected static ArrayList GetTermsOfServiceText() + internal static ArrayList GetTermsOfServiceText() { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug(" inside GetTermsOfServiceText"); + ArrayList arrTermsOfService = new ArrayList(); - Hashtable contentHash = null; - string str = string.Empty; - string spName = "GetTermsOfServiceText"; - DataSet ds = DBModel.GetSQLData(spName, true); - DataTable dt = ds.Tables[0]; - foreach (DataRow dr in dt.Rows) + try + { + Hashtable contentHash = null; + string str = string.Empty; + string spName = DBConstants.GET_TERMS_OF_SERVICE_TEXT; + DataSet ds = DBModel.GetDataFromStoredProcedure(spName); + + if (ds.Tables.Count > 0) + { + DataTable dt = ds.Tables[0]; + if (dt.Rows.Count > 0) + { + foreach (DataRow dr in dt.Rows) + { + contentHash = new Hashtable(); + contentHash.Add(AIAConstants.KEY_TITLE, dr["Title"]); + contentHash.Add(AIAConstants.KEY_CONTENT, dr["Content"]); + arrTermsOfService.Add(contentHash); + } + } + } + } + catch (SqlException ex) { - contentHash = new Hashtable(); - contentHash.Add(AIAConstants.KEY_TITLE, dr["Title"]); - contentHash.Add(AIAConstants.KEY_CONTENT, dr["Content"]); - arrTermsOfService.Add(contentHash); + logger.Fatal("Exception in GetTermsOfServiceText, Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace); + throw; } + return arrTermsOfService; } + + internal int InsertLoginDetails(int userId) + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug(" inside InsertLoginDetails for UserId= " + userId); + + int result = 0; + try + { + conn = new SqlConnection(dbConnectionString); + cmd = new SqlCommand(); + cmd.Connection = conn; + conn.Open(); + cmd.CommandText = DBConstants.INSERT_LOGIN_DETAIL; + cmd.CommandType = CommandType.StoredProcedure; + cmd.Parameters.AddWithValue("@iUserId", userId); + result = cmd.ExecuteNonQuery(); + conn.Close(); + } + catch (SqlException ex) + { + conn.Close(); + logger.Fatal("Exception in InsertLoginDetails for UserId= " + userId + ", Exception= " + ex.Message + ", STACKTRACE=" + ex.StackTrace); + throw; + } + finally + { + conn.Dispose(); + } + + return result; + } + + internal int InsertIncorrectLoginAttempts(int userId) + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug(" inside InsertIncorrectLoginAttempts for UserId= " + userId); + + int result = 0; + try + { + conn = new SqlConnection(dbConnectionString); + cmd = new SqlCommand(); + cmd.Connection = conn; + conn.Open(); + cmd.CommandText = DBConstants.INSERT_INCORRECT_LOGIN_ATTEMPTS; + cmd.CommandType = CommandType.StoredProcedure; + cmd.Parameters.AddWithValue("@iUserId", userId); + result = cmd.ExecuteNonQuery(); + conn.Close(); + } + catch (SqlException ex) + { + conn.Close(); + logger.Fatal("Exception in InsertIncorrectLoginAttempts for UserId= " + userId + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace); + throw; + } + finally + { + conn.Dispose(); + } + return result; + } + + internal int GetIncorrectLoginAttempts(int userId) + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug(" inside GetIncorrectLoginAttempts for UserId = " + userId); + + int count = 0; + try + { + conn = new SqlConnection(dbConnectionString); + cmd = new SqlCommand(); + cmd.Connection = conn; + cmd.CommandText = DBConstants.GET_INCORRECT_LOGIN_ATTEMPTS; + cmd.CommandType = CommandType.StoredProcedure; + cmd.Parameters.AddWithValue("@iUserId", userId); + SqlDataAdapter da = new SqlDataAdapter(); + da.SelectCommand = cmd; + DataSet ds = new DataSet(); + da.Fill(ds); + + if (ds.Tables.Count > 0) + { + DataTable dt = ds.Tables[0]; + + if (dt.Rows.Count > 0) + { + foreach (DataRow dr in dt.Rows) + { + foreach (DataColumn dc in dt.Columns) + { + count = Convert.ToInt32(dr[dc]); + } + } + } + } + } + catch (SqlException ex) + { + logger.Fatal("Exception in GetIncorrectLoginAttempts for UserId = " + userId + " Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace); + throw; + } + return count; + } + + internal int UpdateIncorrectLoginAttempts(int userId) + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug(" inside UpdateIncorrectLoginAttempts for UserId= " + userId); + + int result = 0; + try + { + conn = new SqlConnection(dbConnectionString); + cmd = new SqlCommand(); + cmd.Connection = conn; + conn.Open(); + cmd.CommandText = DBConstants.UPDATE_INCORRECT_LOGIN_ATTEMPTS; + cmd.CommandType = CommandType.StoredProcedure; + cmd.Parameters.AddWithValue("@iUserId", userId); + result = cmd.ExecuteNonQuery(); + conn.Close(); + } + catch (SqlException ex) + { + conn.Close(); + logger.Fatal("Exception in UpdateIncorrectLoginAttempts for UserId= " + userId + ", Exception= " + ex.Message + ", STACKTRACE=" + ex.StackTrace); + throw; + } + finally + { + conn.Dispose(); + } + return result; + } + + public int DeleteIncorrectLoginAttempts(int userId) + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug(" inside DeleteIncorrectLoginAttempts for UserId= " + userId); + + int result = 0; + try + { + conn = new SqlConnection(dbConnectionString); + cmd = new SqlCommand(); + cmd.Connection = conn; + conn.Open(); + cmd.CommandText = DBConstants.DELETE_INCORRECT_LOGIN_ATTEMPTS; + cmd.CommandType = CommandType.StoredProcedure; + cmd.Parameters.AddWithValue("@iUserId", userId); + result = cmd.ExecuteNonQuery(); + conn.Close(); + } + catch (SqlException ex) + { + conn.Close(); + logger.Fatal("Exception in DeleteIncorrectLoginAttempts for UserId= " + userId + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace); + throw; + } + finally + { + conn.Dispose(); + } + return result; + } + + protected ArrayList GetLoginFailureCauses() + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug(" Inside GetLoginFailureCauses"); + + ArrayList failureCauseList = new ArrayList(); + + try + { + Hashtable fcHash = null; + + string sp = DBConstants.GET_ALL_LOGIN_FAILURE_CAUSES; + + DataSet ds = DBModel.GetDataFromStoredProcedure(sp); + + if (ds.Tables.Count > 0) + { + DataTable dt = ds.Tables[0]; + + if (dt.Rows.Count > 0) + { + foreach (DataRow drFailureCause in dt.Rows) + { + fcHash = new Hashtable(); + fcHash.Add(AIAConstants.KEY_ID, drFailureCause["Id"]); + fcHash.Add(AIAConstants.KEY_DESCRIPTION, drFailureCause["Description"]); + failureCauseList.Add(fcHash); + } + } + } + } + catch (SqlException ex) + { + logger.Fatal("Exception in GetLoginFailureCauses, Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace); + throw; + } + return failureCauseList; + } + + internal int InsertUserLoginLog(string accountNumber, Int16 failureId, string referalUrl, string edition, string httpReferer) + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug(" inside InsertUserLoginLog for AccountNumber= " + accountNumber); + + int result = 0; + try + { + conn = new SqlConnection(dbConnectionString); + cmd = new SqlCommand(); + cmd.Connection = conn; + conn.Open(); + cmd.CommandText = DBConstants.INSERT_LOGIN_ERROR_LOG; + cmd.CommandType = CommandType.StoredProcedure; + cmd.Parameters.AddWithValue("@nvAccountNumber", accountNumber); + cmd.Parameters.AddWithValue("@dtLogDate", DateTime.Now); + cmd.Parameters.AddWithValue("@tiFailureId", failureId); + cmd.Parameters.AddWithValue("@nvReferalUrl", referalUrl); + cmd.Parameters.AddWithValue("@nvEdition", edition); + cmd.Parameters.AddWithValue("@nvHttpReferer", httpReferer); + result = cmd.ExecuteNonQuery(); + conn.Close(); + } + catch (SqlException ex) + { + conn.Close(); + logger.Fatal("Exception in InsertUserLoginLog for AccountNumber= " + accountNumber + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace); + throw; + } + finally + { + conn.Dispose(); + } + return result; + } + + internal BlockedUser GetBlockedUserByUserId(int userId) + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug(" inside GetBlockedUserByUserId for UserId= " + userId); + + BlockedUser blockedUser = new BlockedUser(); + DataTable dt = null; + try + { + conn = new SqlConnection(dbConnectionString); + cmd = new SqlCommand(); + cmd.Connection = conn; + cmd.CommandText = DBConstants.GET_BLOCKED_USER_BY_USER_ID; + cmd.CommandType = CommandType.StoredProcedure; + cmd.Parameters.AddWithValue("@userId", userId); + SqlDataAdapter da = new SqlDataAdapter(); + da.SelectCommand = cmd; + dt = new DataTable(); + da.Fill(dt); + + if (dt.Rows.Count > 0) + { + foreach (DataRow dr in dt.Rows) + { + blockedUser.Id = Convert.ToInt32(dr["Id"]); + blockedUser.FirstName = dr["FirstName"].ToString(); + blockedUser.LastName = dr["LastName"].ToString(); + blockedUser.EmailId = dr["EmailId"].ToString(); + blockedUser.LoginId = dr["LoginId"].ToString(); + blockedUser.Password = dr["Password"].ToString(); + blockedUser.AccountNumber = dr["AccountNumber"].ToString(); + blockedUser.LoginTime = Convert.ToDateTime(dr["LoginTime"]); + } + } + else + { + blockedUser = new BlockedUser (); + } + } + catch (SqlException ex) + { + logger.Fatal("Exception in GetBlockedUserByUserId for UserId= " + userId + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace); + throw; + } + return blockedUser; + } + + protected ArrayList GetBlockedUsersByUserType(int userTypeId) + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug(" inside GetBlockedUsersByUserType for UserTypeId= " + userTypeId); + + ArrayList blockedUsersList = new ArrayList(); + BlockedUser blockedUser = null; + DataTable dt = null; + try + { + conn = new SqlConnection(dbConnectionString); + cmd = new SqlCommand(); + cmd.Connection = conn; + cmd.CommandText = DBConstants.GET_BLOCKED_USERS_BY_USER_TYPE; + cmd.CommandType = CommandType.StoredProcedure; + cmd.Parameters.AddWithValue("@iUserTypeId", userTypeId); + SqlDataAdapter da = new SqlDataAdapter(); + da.SelectCommand = cmd; + dt = new DataTable(); + da.Fill(dt); + + if (dt.Rows.Count > 0) + { + foreach (DataRow dr in dt.Rows) + { + blockedUser = new BlockedUser(); + + blockedUser.Id = Convert.ToInt32(dr["Id"]); + blockedUser.FirstName = dr["FirstName"].ToString(); + blockedUser.LastName = dr["LastName"].ToString(); + blockedUser.EmailId = dr["EmailId"].ToString(); + blockedUser.LoginId = dr["LoginId"].ToString(); + blockedUser.Password = dr["Password"].ToString(); + blockedUser.AccountNumber = dr["AccountNumber"].ToString(); + blockedUser.LoginTime = Convert.ToDateTime(dr["LoginTime"]); + + blockedUsersList.Add(blockedUser); + } + } + else + { + blockedUser = new BlockedUser(); + } + } + catch (SqlException ex) + { + logger.Fatal("Exception in GetBlockedUsersByUserType for UserTypeId= " + userTypeId + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace); + throw; + } + return blockedUsersList; + } + + internal static int UnblockUser(int userId) + { + int result = 0; + DBModel objModel = new DBModel(); + + result = objModel.DeleteIncorrectLoginAttempts(userId); + + return result; + } + + internal static bool ValidateUserAuthenticity(string username, string password, User user) + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug(" Inside ValidateUserAuthenticity for Username = " + username + ", Password: " + password); + + bool result = false; + + try + { + if ((string.Equals(username.ToUpper(), user.LoginId.ToUpper())) && (string.Equals(password, user.Password))) + { + result = true; + } + else + { + result = false; + } + } + catch (SqlException ex) + { + logger.Fatal("Exception in ValidateUserAuthenticity for Username = " + username + ", Password: " + password + ", Exception= " + ex.Message + ", STACKTRACE= " + ex.StackTrace); + throw; + } + + return result; + } } } \ No newline at end of file diff --git a/400-SOURCECODE/AIAHTML5.API/Models/User.cs b/400-SOURCECODE/AIAHTML5.API/Models/User.cs index 7746e48..4174d6b 100644 --- a/400-SOURCECODE/AIAHTML5.API/Models/User.cs +++ b/400-SOURCECODE/AIAHTML5.API/Models/User.cs @@ -22,14 +22,21 @@ namespace AIAHTML5.API.Models public int? ModifierId { get; set; } public DateTime? ModifiedDate { get; set; } public string UserType { get; set; } + public int UserTypeId { get; set; } public bool IsActive { get; set; } + public bool IsCorrectPassword { get; set; } + public int IncorrectLoginAttemptCount { get; set; } + public bool IsBlocked { get; set; } + public int LicenseId { get; set; } + public int EditionId { get; set; } + public Int16 LoginFailureCauseId { get; set; } 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 SubscriptionExpirationDateString { get; set; } + public string SubscriptionExpirationDate { get; set; } public string TermsOfServiceTitle { get; set; } public string TermsOfServiceText { get; set; } @@ -44,6 +51,11 @@ namespace AIAHTML5.API.Models public const string SITE_USER = "Site User"; } + public enum UserType + { + SUPER_ADMIN = 1, GENERAL_ADMIN, DISTRICT_ADMIN, CLIENT_ADMIN, SINGLE_USER, CONCURRENT_USER, RESELLER, TEST_ACCOUNT, SITE_USER + } + public class License { public int Id { get; set; } @@ -89,4 +101,16 @@ namespace AIAHTML5.API.Models public double AmountPending { get; set; } public int NoOfImages { get; set; } } + + public class BlockedUser + { + public int Id { get; set; } + public string FirstName { get; set; } + public string LastName { get; set; } + public string LoginId { get; set; } + public string Password { get; set; } + public string EmailId { get; set; } + public string AccountNumber { get; set; } + public DateTime LoginTime { get; set; } + } } \ No newline at end of file diff --git a/400-SOURCECODE/AIAHTML5.API/Models/UserUtility.cs b/400-SOURCECODE/AIAHTML5.API/Models/UserUtility.cs index 782fb28..eed8efd 100644 --- a/400-SOURCECODE/AIAHTML5.API/Models/UserUtility.cs +++ b/400-SOURCECODE/AIAHTML5.API/Models/UserUtility.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Web; @@ -13,12 +13,13 @@ using System.Text; using System.IO; using System.Net.Mime; using System.Configuration; +using System.Collections; namespace AIAHTML5.API.Models { public class UserUtility { - public static bool SendEmail(dynamic UserDetails, bool havePassword) + public static bool SendEmail(dynamic UserDetails, bool havePassword, bool unbLockUser = false) { ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); logger.Debug("inside SendEmail in for havePassword =" + havePassword); @@ -71,8 +72,16 @@ namespace AIAHTML5.API.Models if (havePassword) { - templatePath = "~/Templates/forgot-Password.html"; - resetPasswordLink = site_url + "?em:" + HttpUtility.UrlEncode(userMail); + if (unbLockUser) + { + templatePath = "~/Templates/unblock-User.html"; + resetPasswordLink = site_url + "?unb:" + HttpUtility.UrlEncode(userMail); + } + else + { + templatePath = "~/Templates/forgot-Password.html"; + resetPasswordLink = site_url + "?em:" + HttpUtility.UrlEncode(userMail); + } } else templatePath = "~/Templates/forgot-UserId.html"; @@ -105,8 +114,12 @@ namespace AIAHTML5.API.Models if (!havePassword) mailSubject = "UserID recovery mail for: "; else - mailSubject = "Password recovery mail for: "; - + { + if (unbLockUser) + mailSubject = "Unblock user request mail for: "; + else + mailSubject = "Password recovery mail for: "; + } emailUtility.sHostName = Convert.ToString(ConfigurationManager.AppSettings["HostAddress"]); emailUtility.sFromAddress = Convert.ToString(ConfigurationManager.AppSettings["SenderEmailAddress"]); @@ -211,10 +224,93 @@ namespace AIAHTML5.API.Models } catch (Exception ex) { - logger.Fatal("exception in GetMailBodyTextFromTemplate. msg= " + ex.Message + ", stacktrace= " + ex.StackTrace); + logger.Fatal("exception in SendAdminRequestEmail for email =" + userInfo["emailId"] + ". msg= " + ex.Message + ", stacktrace= " + ex.StackTrace); + return false; + } + } + + public static bool SendEmail(Newtonsoft.Json.Linq.JObject userInfo, ArrayList mailToList, string sender, string mailSubject = "", string mailBody = "") + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug("Inside SendEmail with UserInfo =" + userInfo); + + try + { + EmailUtility emailUtility = new EmailUtility(); + List lstToAddress = new List(); + List lstBccAddress = new List(); + + string emailMessage = string.Empty; + string senderEmailId = string.Empty; + + foreach (string email in mailToList) + { + lstToAddress.Add(email); + } + + emailMessage = "Unable to process request for "; + + if (UserUtility.CheckIfPropertyExists(userInfo, "username") && !string.IsNullOrEmpty(userInfo["username"].ToString())) + emailMessage += "username: " + userInfo["username"].ToString() + ""; + if (UserUtility.CheckIfPropertyExists(userInfo, "password") && !string.IsNullOrEmpty(userInfo["password"].ToString())) + emailMessage += "& password: " + userInfo["password"].ToString() + "

"; + if (UserUtility.CheckIfPropertyExists(userInfo, "emailId") && !string.IsNullOrEmpty(userInfo["emailId"].ToString())) + emailMessage += "emailId: " + userInfo["emailId"].ToString() + "

"; + if (UserUtility.CheckIfPropertyExists(userInfo, "accountNumber") && !string.IsNullOrEmpty(userInfo["accountNumber"].ToString())) + emailMessage += "accountNumber: " + userInfo["accountNumber"].ToString() + "

"; + + if (string.IsNullOrEmpty(sender)) + senderEmailId = Convert.ToString(ConfigurationManager.AppSettings["SenderEmailAddress"]); + else + senderEmailId = sender; + + emailMessage += mailBody; + + emailMessage = emailMessage.Replace("\n", "
"); + + emailMessage += "

"; + + emailUtility.sHostName = Convert.ToString(ConfigurationManager.AppSettings["HostAddress"]); + emailUtility.sFromAddress = senderEmailId; + emailUtility.bIsBodyHtml = true; + emailUtility.bEnableSsl = false; + emailUtility.sSubject = mailSubject; + emailUtility.sBodyText = emailMessage; + emailUtility.iPort = 25; + emailUtility.sToAddresses = lstToAddress; + emailUtility.sBccAddresses = lstBccAddress; + + emailUtility.SendSmtpEmail(); + return true; + } + catch (Exception ex) + { + logger.Fatal("exception in SendEmail for username: " + userInfo["username"].ToString() + " & password: " + userInfo["password"].ToString() + " email =" + userInfo["emailId"] + ". msg= " + ex.Message + ", stacktrace= " + ex.StackTrace); return false; } } + public static ArrayList GetSupportMailList() + { + ArrayList supoortMailList = new ArrayList(); + string[] mailToArr = (ConfigurationManager.AppSettings["AdminSupport"]).Split(','); + if (mailToArr.Length > 0) + { + for (int i = 0; i < mailToArr.Length; i++) + { + supoortMailList.Add(mailToArr[i].ToString()); + } + } + return supoortMailList; + } + + protected static bool CheckIfPropertyExists(dynamic dynamicObject, string propertyName) + { + var res = dynamicObject[propertyName]; + if (res != null) + return true; + else + return false; + } } } \ No newline at end of file diff --git a/400-SOURCECODE/AIAHTML5.API/Models/Users.cs b/400-SOURCECODE/AIAHTML5.API/Models/Users.cs index b8d4022..338d625 100644 --- a/400-SOURCECODE/AIAHTML5.API/Models/Users.cs +++ b/400-SOURCECODE/AIAHTML5.API/Models/Users.cs @@ -9,6 +9,7 @@ using AIAHTML5.API.Constants; using log4net; using AIAHTML5.API.Models; using Newtonsoft.Json; +using System.Collections; namespace AIAHTML5.API.Models { @@ -22,27 +23,7 @@ namespace AIAHTML5.API.Models try { - //var client = new MongoClient(); - //var db = client.GetDatabase(Settings.Default.database); - - //var collection = db.GetCollection("Users"); - - //FilterDefinition[] filterCondition = { Builders.Filter.Eq("loginId", credentials["username"].ToString()), - // Builders.Filter.Eq("password", credentials["password"].ToString())}; - - //dynamic userDetails = collection.Find(Builders.Filter.And(filterCondition)).SingleOrDefault(); - - - //if (userDetails != null) - //{ - // logger.Debug("userDetails.loginId= " + userDetails.loginId); - // return userDetails; - //} - //else - //{ - // return AIAConstants.USER_NOT_FOUND; - //} - 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) @@ -60,11 +41,18 @@ namespace AIAHTML5.API.Models catch (Exception e) { - logger.Fatal("Exception in AuthenticateUser for loginId =" + credentials["username"].ToString() + " and password= " + credentials["password"].ToString() + "Exception= " + e.Message); + logger.Fatal("Exception in AuthenticateUser for loginId =" + credentials["username"].ToString() + " and password= " + credentials["password"].ToString() + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace); + + //string errorMessage = AIAConstants.ERROR_IN_FECTHING_DETAILS; + //string error = "Message: " + e.Message + ", STACKTRACE: " + e.StackTrace; + //userDetails = errorMessage; - string errorMessage = AIAConstants.ERROR_IN_FECTHING_DETAILS; - string error = "Message: " + e.Message + ", STACKTRACE: " + e.StackTrace; - userDetails = error; + 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; } return userDetails; } @@ -109,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); @@ -122,16 +110,23 @@ namespace AIAHTML5.API.Models } catch (Exception ex) { - logger.Fatal("Exception in Gettting UserDetailsByEmailId for EmailId =" + userInfo["emailId"].ToString() + " Exception= " + ex.Message); + logger.Fatal("Exception in Gettting UserDetailsByEmailId for EmailId =" + userInfo["emailId"].ToString() + " Exception= " + ex.Message + ", STACKTRACE: " + ex.StackTrace); + + //string errorMessage = AIAConstants.ERROR_IN_FECTHING_DETAILS; + //return errorMessage; - string errorMessage = AIAConstants.ERROR_IN_FECTHING_DETAILS; - return errorMessage; + ArrayList supportMailList = UserUtility.GetSupportMailList(); + string mailSubject = "SQL Exception intimation mail"; + string mailBody = "MESSAGE: " + ex.Message + ", STACKTRACE: " + ex.StackTrace; + UserUtility.SendEmail(userInfo, supportMailList, "", mailSubject, mailBody); + + return AIAConstants.SQL_CONNECTION_ERROR; } } - internal static dynamic UpdatePassword(Newtonsoft.Json.Linq.JObject userInfo) + internal static dynamic UpdatePassword(Newtonsoft.Json.Linq.JObject userInfo, string sLoginId, string sEmailId) { ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); //var client = new MongoClient(); @@ -144,23 +139,444 @@ namespace AIAHTML5.API.Models //var result = collection.UpdateOne(filter, update); - int result = DBModel.UpdateUserPassword(userInfo); + int result = DBModel.UpdateUserPassword(userInfo, sLoginId, sEmailId); - if (result != null) + if (result > 0) return result; else return AIAConstants.USER_NOT_FOUND; } catch (Exception e) { - logger.Fatal("Exception= " + e.Message); - return AIAConstants.ERROR_IN_FECTHING_DETAILS; + logger.Fatal("Exception in UdatePassword with user details = " + userInfo + ", LoginId:" + sLoginId + ", EmailId: "+ sEmailId + "
MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace); + //return AIAConstants.ERROR_IN_FECTHING_DETAILS; + + ArrayList supportMailList = UserUtility.GetSupportMailList(); + string mailSubject = "SQL Exception intimation mail"; + string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace; + UserUtility.SendEmail(userInfo, supportMailList, "", mailSubject, mailBody); + + return AIAConstants.SQL_CONNECTION_ERROR; + } + } + + internal static dynamic UpdateLicenseTerm(Newtonsoft.Json.Linq.JObject userLicenseInfo) + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug(" inside UpdateLicenseTerm for AccountNumber = " + userLicenseInfo["licenseeAccountNumber"].ToString() + ", LicenseId: " + userLicenseInfo["userLicenseId"].ToString()); + Newtonsoft.Json.Linq.JObject userInfo = new Newtonsoft.Json.Linq.JObject(); + + dynamic result; + string accountNumber = userLicenseInfo["licenseeAccountNumber"].ToString(); + + userInfo.Add("accountNumber", accountNumber); + + try + { + result = DBModel.UpdateLicenseTermStatus(accountNumber); + + if (result < 0) + { + logger.Fatal("Unable to update LicenseTermAccepted status for AccountNumber =" + accountNumber); + } + } + catch (Exception ex) + { + logger.Fatal("Exception in UpdateLicenseTerm for AccountNumber =" + accountNumber + " Exception= " + ex.Message + ", STACKTRACE: " + ex.StackTrace); + + ArrayList supportMailList = UserUtility.GetSupportMailList(); + string mailSubject = "SQL Exception intimation mail"; + string mailBody = "MESSAGE: " + ex.Message + ", STACKTRACE: " + ex.StackTrace; + UserUtility.SendEmail(userInfo, supportMailList, "", mailSubject, mailBody); + + result = AIAConstants.SQL_CONNECTION_ERROR; + } + + + return result; + } + + internal static bool IsUserAuthenticated(Newtonsoft.Json.Linq.JObject credentials, User user) + { + bool isAuthenticatedUser = DBModel.ValidateUserAuthenticity(credentials["username"].ToString(), credentials["password"].ToString(), user); + + return isAuthenticatedUser; + } + + 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()); + User userDetails = null; + + try + { + userDetails = DBModel.GetUserDetailsByLoginId(credentials["username"].ToString()); + } + catch (Exception e) + { + + 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); + + //userDetails = AIAConstants.SQL_CONNECTION_ERROR; + } + + return userDetails; + } + + internal static void getLicenseIdForThisUser(int userId, out int licenseId, out int editionId) + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug("inside getLicenseIdForThisUser for UserId =" + userId); + + //assigning below variable to avoid compiler error for unassignd out params + licenseId = 0; + editionId = 0; + + try + { + + DBModel objModel = new DBModel(); + Hashtable licenseEditionHash = objModel.GetLicenseDetailByUserId(userId); + + 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); + //} + } + catch (Exception e) + { + logger.Fatal("Exception in getLicenseIdForThisUser for UserId =" + userId + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace); + throw; + } + } + + internal static int insertLoginDetails(int userId) + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug("inside insertLoginDetails for UserId =" + userId); + + int result = 0; + try + { + DBModel objModel = new DBModel(); + + result = objModel.InsertLoginDetails(userId); + } + catch (Exception e) + { + logger.Fatal("Exception in insertLoginDetails for UserId =" + userId + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace); + throw; + } + + return result; + } + + internal static bool isUSerActive(User user) + { + if (user.IsActive) + return true; + else + return false; + } + + internal static bool checkIfLicenseExpired(LicenseSubscriptionDetails subscriptionDetail, out string expirationDate) + { + expirationDate = string.Empty; + bool isLicenseExpired = false; + + if (subscriptionDetail.Id > 0) + { + DateTime? subscriptionValidThrough = subscriptionDetail.SubscriptionValidThrough; + if (subscriptionValidThrough != null && subscriptionValidThrough.Value.Date >= DateTime.Now.Date) + { + isLicenseExpired = false; + } + else + { + isLicenseExpired = true; + expirationDate = subscriptionDetail.SubscriptionValidThrough.Value.Date.ToString("MM/dd/yyyy").ToString(); + } + } + return isLicenseExpired; + } + + internal static ArrayList getModuleListByLicenseId(int licenseId) + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug("inside getModuleListByLicenseId for LicenseId =" + licenseId); + + ArrayList licensedModulesList = new ArrayList(); + + try + { + + DBModel objModel = new DBModel(); + licensedModulesList = objModel.GetUserModulesByLicenseId(licenseId); + } + catch (Exception e) + { + logger.Fatal("Exception in getModuleListByLicenseId for LicenseId =" + licenseId + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace); + throw; + } + + return licensedModulesList; + } + + internal static int deletePastWrongAttempts(int userId) + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug("inside deletePastWrongAttempts for UserId =" + userId); + + int result = 0; + + try + { + DBModel objModel = new DBModel(); + + result = objModel.DeleteIncorrectLoginAttempts(userId); + } + catch (Exception e) + { + logger.Fatal("Exception in deletePastWrongAttempts for UserId =" + userId + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace); + throw; + } + return result; + } + + internal static int checkNoOfWrongAttempts(int userId) + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug("inside checkNoOfWrongAttempts for UserId =" + userId); + + int result = 0; + + try + { + DBModel objModel = new DBModel(); + + result = objModel.GetIncorrectLoginAttempts(userId); + } + catch (Exception e) + { + logger.Fatal("Exception in checkNoOfWrongAttempts for UserId =" + userId + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace); + throw; + } + return result; + } + + internal static int saveWrongAttemptofUser(int userId) + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug("inside saveWrongAttemptofUser for UserId =" + userId); + int result = 0; + + try + { + int wrongAttemptCount = Users.checkNoOfWrongAttempts(userId); + + DBModel objModel = new DBModel(); + + if (wrongAttemptCount < 1) + { + result = objModel.InsertIncorrectLoginAttempts(userId); + } + else + { + result = objModel.UpdateIncorrectLoginAttempts(userId); + } + } + catch (Exception e) + { + logger.Fatal("Exception in saveWrongAttemptofUser for UserId =" + userId + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace); + throw; + } + + return result; + } + + internal static bool isLicenseActive(int licenseId) + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug("inside isLicenseActive for LicenseId =" + licenseId); + bool result = false; + + try + { + DBModel objModel = new DBModel(); + License userLicense = objModel.GetLicenseDetailsByLicenseId(licenseId); + + + if (userLicense.IsActive) + result = true; + else + result = false; + } + catch (Exception e) + { + logger.Fatal("Exception in isLicenseActive for LicenseId =" + licenseId + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace); + throw; + } + return result; + } + + internal static License getLicenseDetails(int licenseId) + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug("inside getLicenseDetails for LicenseId =" + licenseId); + + License userLicense = null; + + try + { + DBModel objModel = new DBModel(); + userLicense = objModel.GetLicenseDetailsByLicenseId(licenseId); + } + catch (Exception e) + { + logger.Fatal("Exception in getLicenseDetails for LicenseId =" + licenseId + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace); + throw; + } + return userLicense; + } + + internal static LicenseSubscriptionDetails getLicenseSubscriptionDetails(int licenseId) + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug("inside getLicenseSubscriptionDetails for LicenseId =" + licenseId); + LicenseSubscriptionDetails userSubscriptionDetail = null; + + try + { + DBModel objModel = new DBModel(); + userSubscriptionDetail = objModel.GetLicenseSubscriptionDetailsByLicenseId(licenseId); + } + catch (Exception e) + { + logger.Fatal("Exception in getLicenseSubscriptionDetails for LicenseId =" + licenseId + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace); + throw; } + return userSubscriptionDetail; } - internal static dynamic UpdateLicenseTerm(string accNumber) + internal static void isCredentialCorrect(Newtonsoft.Json.Linq.JObject credentials, User userInfo, out bool isCorrectLoginId, out bool isCorrectPassword) { - int result = DBModel.UpdateLicenseTermStatus(accNumber); + isCorrectLoginId = false; + isCorrectPassword = false; + + if (userInfo.Id> 0) + { + if (string.Equals(credentials["username"].ToString().ToUpper(), userInfo.LoginId.ToUpper())) + isCorrectLoginId = true; + + if (string.Equals(credentials["password"].ToString(), userInfo.Password)) + { + isCorrectPassword = true; + } + } + } + + internal static int insertUserLoginLog(string accountNumber, Int16 failureId, string referalUrl, string edition, string httpReferer) + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug("inside insertUserLoginLog for accountNumber =" + accountNumber); + + int result = 0; + + try + { + DBModel objModel = new DBModel(); + result = objModel.InsertUserLoginLog(accountNumber, failureId, null, edition, null); + } + catch (Exception e) + { + logger.Fatal("Exception in insertUserLoginLog for accountNumber =" + accountNumber + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace); + throw; + } + return result; + } + + + internal static ArrayList getTermsOfServiceText() + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug("inside getTermsOfServiceText"); + + ArrayList arrTermsOfService = new ArrayList(); + + try + { + DBModel objModel = new DBModel(); + arrTermsOfService = DBModel.GetTermsOfServiceText(); + } + catch (Exception e) + { + logger.Fatal("Exception in getTermsOfServiceText, Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace); + throw; + } + return arrTermsOfService; + } + + internal static ArrayList getAllModulesList() + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug("inside getAllModulesList"); + ArrayList modulesList = new ArrayList (); + + try + { + DBModel objModel = new DBModel(); + modulesList = objModel.GetAllModules(); + } + catch (Exception e) + { + logger.Fatal("Exception in getAllModulesList, Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace); + throw; + } + return modulesList; + } + + internal static bool isUserBlocked(int userId, out DateTime blockTime) + { + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); + logger.Debug("inside isUserBlocked for UserId =" + userId); + bool result = false; + blockTime = new DateTime(); + + try + { + + + DBModel objModel = new DBModel(); + BlockedUser blockedUser = objModel.GetBlockedUserByUserId(userId); + + if (blockedUser.Id> 0) + { + blockTime = blockedUser.LoginTime; + result = true; + } + else + result = false; + } + + catch (Exception e) + { + logger.Fatal("Exception in isUserBlocked for UserId =" + userId + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace); + throw; + } return result; } diff --git a/400-SOURCECODE/AIAHTML5.API/Templates/unblock-User.html b/400-SOURCECODE/AIAHTML5.API/Templates/unblock-User.html new file mode 100644 index 0000000..a076de8 --- /dev/null +++ b/400-SOURCECODE/AIAHTML5.API/Templates/unblock-User.html @@ -0,0 +1,87 @@ + + + + + + + + + + + + + +
+ AIA +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Unblock Account
 
Hi,
 
You have requested to unblock your account for emailId: {emailId}
 
Click the Unblock button below to unblock your A.D.A.M. Interactive Anatomy™ account
 
+ Unblock +  
 
 
 
 
+
+ + + + + + + + + + + + + + + + + +
A.D.A.M. – the company that pioneered online health content – is dedicated to creating and offering the most effective and innovative educational solutions possible for teaching medical science and improving health literacy.
 
Give us a call toll-free at 1-888-278-9614 or send us an email if you have any questions or if you need help. It will be our pleasure to help you.
 
 
© 2017 Ebix, Inc. All Rights Reserved.
+
\ No newline at end of file diff --git a/400-SOURCECODE/AIAHTML5.API/Web.config b/400-SOURCECODE/AIAHTML5.API/Web.config index de1cf78..f956f67 100644 --- a/400-SOURCECODE/AIAHTML5.API/Web.config +++ b/400-SOURCECODE/AIAHTML5.API/Web.config @@ -39,7 +39,6 @@ - diff --git a/400-SOURCECODE/AIAHTML5.Web/app/controllers/HomeController.js b/400-SOURCECODE/AIAHTML5.Web/app/controllers/HomeController.js index 74dd3e7..47f321e 100644 --- a/400-SOURCECODE/AIAHTML5.Web/app/controllers/HomeController.js +++ b/400-SOURCECODE/AIAHTML5.Web/app/controllers/HomeController.js @@ -43,7 +43,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic // on refersh this variable will also get null that is why we are only checking this variable on initialize that if it is null that means page gets refershed. $rootScope.refreshcheck = null; - + $rootScope.isModestyOn; $rootScope.isModestyOff; @@ -83,7 +83,12 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic havePassword: null, newPassword: null, confirmPassword: null, - userMessage: null + userMessage: null, + unblockUser: null + }; + $rootScope.userLicenseInfo = { + userLicenseId: 0, + licenseeAccountNumber: null }; $rootScope.userData; $rootScope.userModules; @@ -91,21 +96,18 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic $rootScope.isVisibleLogin; $rootScope.haveRoleAdmin; $rootScope.checked = false; - $rootScope.licenseeAccountNumber = null; var isfilloptionChecked = ""; var isOutlineOptionChecked = ""; - $rootScope.forgotPwdModalShow = function () - { - document.getElementById("forgetPwdForm").reset(); + $rootScope.forgotPwdModalShow = function () { + document.getElementById("forgetPwdForm").reset() $("#forgotPwdModal").modal("show"); - $(".modal-backdrop").css("opacity",".5"); + $(".modal-backdrop").css("opacity", ".5"); } - $rootScope.forgotUserModalShow=function() - { + $rootScope.forgotUserModalShow = function () { document.getElementById("forgetUSerIdForm").reset(); $("#forgotUserModal").modal("show"); $(".modal-backdrop").css("opacity", ".5"); - + } $rootScope.initializeAIA = function () { @@ -113,6 +115,8 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic //$rootScope.isVisibleLogin = false; //$rootScope.isVisibleResetPass = true; VerifyUrlForQuerystring(); + if ($location.url().indexOf('?unb:') != -1) + $rootScope.UnblockUser(); getUserDetails(); } @@ -129,39 +133,54 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic .then( function (result) { - if (result == 'true') { - - $rootScope.userModules = UserModules; - $rootScope.isVisibleLogin = false; - $location.path('/'); - + if (result == LoginConstants.USER_NOT_FOUND) { + $rootScope.isVisibleLogin = true; + // alert(LoginMessageConstants.USER_OR_PASSWORD_INCORRECT); + $rootScope.errorMessage = LoginMessageConstants.INVALID_USER; + $("#messageModal").modal('show'); + } + else if (result == LoginConstants.ERROR_IN_FECTHING_DETAILS) { + //alert(LoginMessageConstants.ERROR_IN_FECTHING_DETAILS); + $rootScope.isVisibleLogin = true; + $rootScope.errorMessage = LoginMessageConstants.ERROR_IN_FECTHING_DETAILS; + $("#messageModal").modal('show'); + } + else if (result == LoginConstants.SQL_CONNECTION_ERROR) { + $rootScope.isVisibleLogin = true; + $rootScope.errorMessage = LoginConstants.SQL_CONNECTION_ERROR_MESSAGE; + $("#messageModal").modal('show'); } else { - if (result == LoginConstants.USER_NOT_FOUND) { - $rootScope.isVisibleLogin = true; - // alert(LoginMessageConstants.USER_OR_PASSWORD_INCORRECT); - $rootScope.errorMessage = LoginMessageConstants.USER_OR_PASSWORD_INCORRECT; - $("#messageModal").modal('show'); - } - else if (result == LoginConstants.ERROR_IN_FECTHING_DETAILS) { - //alert(LoginMessageConstants.ERROR_IN_FECTHING_DETAILS); - $rootScope.isVisibleLogin = true; - $rootScope.errorMessage = LoginMessageConstants.ERROR_IN_FECTHING_DETAILS; - $("#messageModal").modal('show'); - } - else { - if (typeof result.LoginId != undefined || result.LoginId != "" || result.LoginId != null) { + if (typeof result.LoginId != undefined || result.LoginId != "" || result.LoginId != null) { - if ($("#messageModal").length > 0){ - $("#messageModal").modal('hide'); - } - if (result == LoginMessageConstants.INVALID_USER) { - $rootScope.isVisibleLogin = true; - $rootScope.errorMessage = LoginMessageConstants.INVALID_USER; - $("#messageModal").modal('show'); + if ($("#messageModal").length > 0) { + $("#messageModal").modal('hide'); + } + if (result == LoginMessageConstants.INVALID_USER) { + $rootScope.isVisibleLogin = true; + $rootScope.errorMessage = LoginMessageConstants.INVALID_USER; + $("#messageModal").modal('show'); + } + else if (result.IsBlocked) { + $rootScope.isVisibleLogin = true; + $rootScope.errorMessage = LoginMessageConstants.USER_BLOCKED; + $("#messageModal").modal('show'); + } + else { + if (!result.IsCorrectPassword) { + if (result.IncorrectLoginAttemptCount < 5) { + $rootScope.isVisibleLogin = true; + $rootScope.errorMessage = LoginMessageConstants.INVALID_PASSWORD; + $("#messageModal").modal('show'); + } + else { + $rootScope.isVisibleLogin = true; + $rootScope.errorMessage = LoginMessageConstants.USER_BLOCKED; + $("#messageModal").modal('show'); + } } else { - if ((!result.IsSubscriptionExpired) && (result.UserType == UserTypeConstants.SUPER_ADMIN) || result.UserType == UserTypeConstants.GENERAL_ADMIN && result.IsActive) { + if (result.UserType == UserTypeConstants.SUPER_ADMIN || result.UserType == UserTypeConstants.GENERAL_ADMIN && result.IsActive) { //(!result.IsSubscriptionExpired) && $rootScope.userData = result; $rootScope.userModules = result.Modules; $rootScope.isVisibleLogin = false; @@ -169,22 +188,19 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic localStorage.setItem('loggedInUserDetails', JSON.stringify(result)); $('#dvUserModulesInfo').modal('show'); $location.path('/'); - - } - //else if ((!result.IsSubscriptionExpired) && (result.UserType== UserTypeConstants.CLIENT_ADMIN || result.UserType== UserTypeConstants.DISTRICT_ADMIN || result.UserType== UserTypeConstants.SINGLE_USER ||result.UserType== UserTypeConstants.RESELLER) && result.License.IsTermAccepted) {} - else if ((!result.IsSubscriptionExpired) && (result.License != null) && (result.License.IsActive) && result.IsActive) { + } + else if ((!result.IsSubscriptionExpired) && (result.LicenseInfo != null) && (result.LicenseInfo.IsActive) && result.IsActive) { if (result.UserType == UserTypeConstants.CLIENT_ADMIN || result.UserType == UserTypeConstants.DISTRICT_ADMIN || result.UserType == UserTypeConstants.SINGLE_USER || result.UserType == UserTypeConstants.RESELLER) { - if (result.License.IsTermAccepted) { + if (result.LicenseInfo.IsTermAccepted) { $rootScope.userData = result; $rootScope.userModules = result.Modules; $rootScope.isVisibleLogin = false; - $rootScope.haveRoleAdmin = true; - $rootScope.licenseeAccountNumber = result.License.AccountNumber; + $rootScope.haveRoleAdmin = true; localStorage.setItem('loggedInUserDetails', JSON.stringify(result)); $('#dvUserModulesInfo').modal('show'); $location.path('/'); - + } else { if ($('#dvTerms').length > 0) { @@ -193,9 +209,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic $rootScope.isVisibleLogin = true; $('#dvTermCondition').fadeIn(); $rootScope.userData = result; - $rootScope.userModules = result.Modules; $rootScope.haveRoleAdmin = true; - $rootScope.licenseeAccountNumber = result.License.AccountNumber; localStorage.setItem('loggedInUserDetails', JSON.stringify(result)); $location.path('/'); } @@ -210,41 +224,41 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic $location.path('/'); } } - else if ((!result.IsSubscriptionExpired) && (result.License != null) && (result.License.IsActive) && !result.IsActive) { + else if ((!result.IsSubscriptionExpired) && (result.LicenseInfo != null) && (result.LicenseInfo.IsActive) && !result.IsActive) { $rootScope.isVisibleLogin = true; $rootScope.errorMessage = LoginMessageConstants.USER_INACTIVE_MESSAGE; $("#messageModal").modal('show'); } - else if ((result.IsSubscriptionExpired) && (result.License != null) && (result.License.IsActive) && result.IsActive) { + else if ((result.IsSubscriptionExpired) && (result.LicenseInfo != null) && (result.LicenseInfo.IsActive) && result.IsActive) { $rootScope.isVisibleLogin = true; - $rootScope.errorMessage = LoginMessageConstants.SUBSCRIPTION_EXPIRATION_MESSAGE + result.SubscriptionExpirationDateString + '.'; + $rootScope.errorMessage = LoginMessageConstants.SUBSCRIPTION_EXPIRATION_MESSAGE + result.SubscriptionExpirationDate + '.'; $("#messageModal").modal('show'); } - else if ((result.IsSubscriptionExpired) && (result.License != null) && (result.License.IsActive) && !result.IsActive) { + else if ((result.IsSubscriptionExpired) && (result.LicenseInfo != null) && (result.LicenseInfo.IsActive) && !result.IsActive) { $rootScope.isVisibleLogin = true; - $rootScope.errorMessage = LoginMessageConstants.SUBSCRIPTION_EXPIRATION_MESSAGE + result.SubscriptionExpirationDateString + '.'; + $rootScope.errorMessage = LoginMessageConstants.SUBSCRIPTION_EXPIRATION_MESSAGE + result.SubscriptionExpirationDate + '.'; $rootScope.errorMessage = $rootScope.errorMessage + ' ' + LoginMessageConstants.USER_INACTIVE_MESSAGE; $("#messageModal").modal('show'); } - else if ((result.IsSubscriptionExpired) && (result.License != null) && !(result.License.IsActive) && result.IsActive) { + else if ((result.IsSubscriptionExpired) && (result.LicenseInfo != null) && !(result.LicenseInfo.IsActive) && result.IsActive) { $rootScope.isVisibleLogin = true; - $rootScope.errorMessage = LoginMessageConstants.SUBSCRIPTION_EXPIRATION_MESSAGE + result.SubscriptionExpirationDateString + '.'; + $rootScope.errorMessage = LoginMessageConstants.SUBSCRIPTION_EXPIRATION_MESSAGE + result.SubscriptionExpirationDate + '.'; $rootScope.errorMessage = $rootScope.errorMessage + ' ' + LoginMessageConstants.LICENSE_INACTIVE_MESSAGE; $("#messageModal").modal('show'); } - else if ((result.IsSubscriptionExpired) && (result.License != null) && !(result.License.IsActive) && !result.IsActive) { + else if ((result.IsSubscriptionExpired) && (result.LicenseInfo != null) && !(result.LicenseInfo.IsActive) && !result.IsActive) { $rootScope.isVisibleLogin = true; - $rootScope.errorMessage = LoginMessageConstants.SUBSCRIPTION_EXPIRATION_MESSAGE + result.SubscriptionExpirationDateString + '.'; + $rootScope.errorMessage = LoginMessageConstants.SUBSCRIPTION_EXPIRATION_MESSAGE + result.SubscriptionExpirationDate + '.'; $rootScope.errorMessage = $rootScope.errorMessage + ' ' + LoginMessageConstants.LICENSE_INACTIVE_MESSAGE + ' ' + LoginMessageConstants.USER_INACTIVE_MESSAGE; $("#messageModal").modal('show'); } - else if (result.License == null && !result.IsActive) { + else if (typeof (result.LicenseInfo) != "undefined" && !result.IsActive) { $rootScope.isVisibleLogin = true; $rootScope.errorMessage = LoginMessageConstants.USER_INACTIVE_MESSAGE; $("#messageModal").modal('show'); } } - } + } } } }, @@ -260,28 +274,46 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic } $rootScope.UpdateLicenseTermStatus = function () { $('#dvTermCondition').fadeOut(); - if($rootScope.licenseeAccountNumber !=null) { - - AuthenticationService.UpdateLicenseTerm($rootScope.licenseeAccountNumber) - .then(function (result) { - console.log(' Term and Condition acceptance status updated successfully.'); - - }, - function (error) { - console.log(' Error in Term and Condition acceptance status update = ' + error);//.statusText - }); - } - var currentUserDetails = $rootScope.getLocalStorageValue('loggedInUserDetails'); - if (currentUserDetails) { - var userInfo = JSON.parse(currentUserDetails); - - if (userInfo.loginId != undefined || userInfo.loginId != "" || userInfo.loginId != null) { - $rootScope.isVisibleLogin = false; - $rootScope.userData = userInfo; - $rootScope.userModules = userInfo.Modules; - $('#dvUserModulesInfo').modal('show'); - } - } + var currentUserDetails = $rootScope.getLocalStorageValue('loggedInUserDetails'); + if (currentUserDetails) { + var userInfo = JSON.parse(currentUserDetails); + } + if (userInfo.LicenseInfo.AccountNumber != null && userInfo.LicenseInfo.Id != 0) { + $rootScope.userLicenseInfo.userLicenseId = userInfo.LicenseInfo.Id; + $rootScope.userLicenseInfo.licenseeAccountNumber = userInfo.LicenseInfo.AccountNumber; + + AuthenticationService.UpdateLicenseTerm($rootScope.userLicenseInfo) + .then(function (result) { + if (result.Modules !=="" && result.Modules !== null) { // LoginMessageConstants.LICENSE_TERM_CONDITION_UPDATE_SUCCESS) { + console.log(' Term and Condition acceptance status updated successfully.'); + if (currentUserDetails) { + var userInfo = JSON.parse(currentUserDetails); + userInfo.Modules = result.Modules; + + if (userInfo.LoginId != undefined || userInfo.LoginId != "" || userInfo.LoginId != null) { + $rootScope.isVisibleLogin = false; + $rootScope.userData = userInfo; + $rootScope.userModules = userInfo.Modules; + $('#dvUserModulesInfo').modal('show'); + } + } + } + else if (result == LoginConstants.SQL_CONNECTION_ERROR) { + console.log(result); + $rootScope.isVisibleLogin = true; + $('#dvTermCondition').fadeIn(); + $rootScope.errorMessage = LoginConstants.SQL_CONNECTION_ERROR_MESSAGE; + $("#messageModal").modal('show'); + $("#messageModal").css("z-index", 111112); + localStorage.removeItem("loggedInUserDetails"); + } + }, + function (error) { + console.log(' Error in Term and Condition acceptance status update = ' + error);//.statusText + $rootScope.isVisibleLogin = true; + $('#dvTermCondition').fadeIn(); + }); + } }; function VerifyUrlForQuerystring() { var url = $location.url(); @@ -312,11 +344,29 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic try { var userInfo = JSON.parse(currentUserDetails); - if (userInfo.loginId != undefined || userInfo.loginId != "" || userInfo.loginId != null) { - $rootScope.isVisibleLogin = false; - $rootScope.userData = userInfo; - $rootScope.userModules = userInfo.Modules; - if ($rootScope.refreshcheck == null) { + if (userInfo.LoginId != undefined || userInfo.LoginId != "" || userInfo.LoginId != null) { + if (userInfo.LicenseInfo.IsTermAccepted) { + $rootScope.userData = userInfo; + $rootScope.userModules = userInfo.Modules; + $rootScope.isVisibleLogin = false; + //$rootScope.haveRoleAdmin = true; + $rootScope.licenseeAccountNumber = userInfo.LicenseInfo.AccountNumber; + + if ($rootScope.refreshcheck == null) { + $location.path('/'); + } + + } + else { + if ($('#dvTerms').length > 0) { + $('#dvTerms').html(userInfo.TermsOfServiceText); + } + $rootScope.isVisibleLogin = true; + $('#dvTermCondition').fadeIn(); + $rootScope.userData = userInfo; + $rootScope.userModules = userInfo.Modules; + //$rootScope.haveRoleAdmin = true; + $rootScope.licenseeAccountNumber = userInfo.LicenseInfo.AccountNumber; $location.path('/'); } } @@ -328,10 +378,17 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic } $rootScope.SendMailToUser = function (userInfo, isMailForPassword) { + var selectedOption = $("input[name='inlineRadioOptions']:checked").val(); if ((userInfo.emailId != null) && (userInfo.emailId != '')) { if (validateEmail(userInfo.emailId)) { - if (isMailForPassword == true) + if (isMailForPassword == true && selectedOption == LoginMessageConstants.UNBLOCK_SELECTED) { + userInfo.unblockUser = true; + userInfo.havePassword = true; + } + else if (isMailForPassword == true && selectedOption == LoginMessageConstants.FORGOT_PASSWORD_SELECTED) { + userInfo.unblockUser = false; userInfo.havePassword = true; + } else userInfo.havePassword = false; @@ -347,6 +404,10 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic $rootScope.errorMessage = LoginMessageConstants.ERROR_IN_FECTHING_DETAILS; $("#messageModal").modal('show'); } + else if (result == LoginConstants.SQL_CONNECTION_ERROR) { + $rootScope.errorMessage = LoginConstants.SQL_CONNECTION_ERROR_MESSAGE; + $("#messageModal").modal('show'); + } else if (result == LoginConstants.MAIL_NOT_SENT) { // alert(LoginMessageConstants.MAIL_NOT_SENT); $rootScope.errorMessage = LoginMessageConstants.MAIL_NOT_SENT; @@ -363,8 +424,12 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic $('.forgot-sm1').fadeOut(); $('.forgot-sm1').modal('hide'); } - if (isMailForPassword) - message = LoginMessageConstants.RESET_PASSWORD; + if (isMailForPassword) { + if (userInfo.unblockUser) + message = LoginMessageConstants.USER_UNBLOCK_LINK_IN_EMAIL; + else + message = LoginMessageConstants.RESET_PASSWORD; + } else message = LoginMessageConstants.USERID_SENT_IN_EMAIL //alert(message); @@ -397,7 +462,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic } }; - + function validateEmail(email) { @@ -411,6 +476,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic var split = url.split('?em:'); userInfo.emailId = split[1]; } + if (userInfo.newPassword != null) { if (userInfo.newPassword === userInfo.confirmPassword) { @@ -431,6 +497,10 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic $("#messageModal").modal('show'); } + else if (result == LoginConstants.SQL_CONNECTION_ERROR) { + $rootScope.errorMessage = LoginConstants.SQL_CONNECTION_ERROR_MESSAGE; + $("#messageModal").modal('show'); + } else { //if ((result.IsAcknowledged == true) && (result.IsModifiedCountAvailable == true)) { if (result == LoginMessageConstants.PASSWORD_UPDATE_SUCCESS) { @@ -460,7 +530,39 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic $rootScope.errorMessage = LoginMessageConstants.NEW_PASSWORD_FIELD_IS_EMPTY; $("#messageModal").modal('show'); } - + + } + + $rootScope.UnblockUser = function () { + var userEmailId = ''; + var url = $location.url(); + if (url.indexOf('?unb:') != -1) { + var split = url.split('?unb:'); + userEmailId = split[1]; + } + + AuthenticationService.UnblockUser(userEmailId) + .then( + function (result) { + if (result == LoginMessageConstants.USER_UNBLOCK_SUCCESS) { + $rootScope.errorMessage = LoginMessageConstants.USER_UNBLOCK_SUCCESS_MESSAGE; + $("#messageModal").modal('show'); + $rootScope.isVisibleLogin = true; + $location.url("/"); + } + else { + $rootScope.errorMessage = LoginMessageConstants.USER_ALREADY_UNBLOCKED; + $("#messageModal").modal('show'); + $rootScope.isVisibleLogin = true; + $location.url("/"); + } + }, + function (error) { + console.log(' Error in authentication = ' + error.statusText); + $rootScope.errorMessage = LoginMessageConstants.ERROR_IN_FECTHING_DETAILS; + $("#messageModal").modal('show'); + } + ); } $rootScope.lexiconLanguageArray = []; @@ -475,9 +577,9 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic dataType: "json", success: function (result) { $(result.root.uc.al.lx).each(function (key, value) { - + $('#lexiconLangDropdown').append(''); - + }); } @@ -540,7 +642,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic if ($.browser.msie) { $("#resetBtn").css("display", "inline-block"); - // $rootScope.refreshCanvas(); + // $rootScope.refreshCanvas(); } $(function () { @@ -625,7 +727,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic } $("#annotationToolBarOptions").removeClass("disableMenuoption"); $("#optionsListManagerTab").removeClass("disableMenuoption"); - + if (($location.url() == "/da-body-view")) { $rootScope.disableMenuannotation = " "; @@ -648,7 +750,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic $("#annotationToolBarOptions").removeClass("disableSubMenu"); $rootScope.disableFileMenu = " "; } - + else if ($location.url() == "/clinical-animations-detail") { $rootScope.disableMenuannotation = "disableMenuannotation"; $rootScope.disableMenuoption = " "; @@ -683,14 +785,14 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic $rootScope.getModuleScrollPosition = function () { $rootScope.refreshcheck = "check"; $('.mCSB_container ul li').click(function () { - + $rootScope.scrollTopPosition = $(this).position().top; - + }); setTimeout(function () { $(".sidebar").mCustomScrollbar("scrollTo", $rootScope.scrollTopPosition + "px"); - + }, 300); @@ -708,7 +810,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic if (openViews.length > 0) { var lastOpenMoudle = $rootScope.openViews[openViews.length - 1]; } - // $('#daImagePanel').remove(); + // $('#daImagePanel').remove(); if ($('#jsPanel-1').length > 0) $('#jsPanel-1').remove(); @@ -3532,7 +3634,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic $rootScope.disableAnnotationtoolOnListManager = false; $rootScope.ShowListManager = function () { - + $rootScope.switchCanvas(); $("#annotationpaintbrushsize").attr("href", "#"); $("#annotationpainteraser").attr("href", "#"); @@ -3552,9 +3654,9 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic $('#listManager').draggable(); $rootScope.islistManagerEventAlredayDispachted = true; - + $rootScope.$broadcast('listManagerEvent', true); - + if ($rootScope.selectedBodySystemName == undefined && $rootScope.slectedActualTermNumber == undefined) { if ($location.path() == "/module-item-view") { $timeout(function () { @@ -3570,7 +3672,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic $("#termList").find("option").css({ "background-color": "#ffffff", "color": "#000000" }); $('#termList option[value="' + $rootScope.searchSelectedText + '"]').css({ "background-color": "#3399FF", "color": "#ffffff" }); } - } + } else { if ($rootScope.selectedBodySystemId == undefined) { @@ -3585,7 +3687,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic else { $rootScope.refreshTermListOnSystemSelection($rootScope.selectedBodySystemId); } - + } } else { @@ -3595,14 +3697,14 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic else { $rootScope.refreshTermListOnSystemSelection($rootScope.selectedBodySystemId); } - + } - + $timeout(function () { - $('#bodySystems option[selected="selected"]').prop("selected", false); - $('#bodySystems option[value="' + $rootScope.selectedBodySystemName + '"]').prop("selected", true); - $("#termList").find("option").css({ "background-color": "#ffffff", "color": "#000000" }); - $('#termList option[value="' + $rootScope.searchSelectedText + '"]').css({ "background-color": "#3399FF", "color": "#ffffff" }); + $('#bodySystems option[selected="selected"]').prop("selected", false); + $('#bodySystems option[value="' + $rootScope.selectedBodySystemName + '"]').prop("selected", true); + $("#termList").find("option").css({ "background-color": "#ffffff", "color": "#000000" }); + $('#termList option[value="' + $rootScope.searchSelectedText + '"]').css({ "background-color": "#3399FF", "color": "#ffffff" }); }, 1000); } $("#optionsListManagerTab").addClass("active"); @@ -3613,7 +3715,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic } $rootScope.CloseListManager = function () { - + $("#btnTranparency").removeAttr('disabled', 'disabled'); $("#optionsListManagerTab").removeClass("active"); $rootScope.isListManagerMenuSelected = false; @@ -3785,8 +3887,8 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic } $rootScope.isApplyBtnClicked = false; //$timeout(function () { - $('#modal-settings').css("display", "none"); - $("#modelsettingsbackground").css("display", "none"); + $('#modal-settings').css("display", "none"); + $("#modelsettingsbackground").css("display", "none"); // $("#setting-spinner").css("display", "none"); if ($rootScope.MenuModuleName == "DA" || $rootScope.MenuModuleName == "AA") { $("#setting-spinner").css("display", "block"); @@ -3794,7 +3896,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic $rootScope.lexiconLanguageArrayLength = $rootScope.lexiconLanguageArray.length; - // }, 6000); + // }, 6000); }; @@ -3975,7 +4077,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic $(".modal-backdrop").css("z-index", "1200001"); }; - + $rootScope.ShowPrintWindow = function () { // Print Active Viewer html2canvas($("#canvasDiv"), { @@ -4018,8 +4120,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic var curPosture = $rootScope.getLocalStorageValue('currentViewTitle'); if (document.getElementById('jsPanel-1')) { //document.getElementsByClassName('ppImagePanel')) { - if (dataURL == "" || dataURL == undefined) - { + if (dataURL == "" || dataURL == undefined) { setTimeout(function () { document.getElementById('imgPortrait').setAttribute('src', dataURL); @@ -4034,8 +4135,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic } }, 520); } - else - { + else { setTimeout(function () { document.getElementById('imgPortrait').setAttribute('src', dataURL); document.getElementById('imgLandscape').setAttribute('src', dataURL); @@ -4049,14 +4149,14 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic } }, 320); } - + } $('#fileMenuAnchor').parent().addClass('disableFileMenu'); if ($('#daImagePanel').length > 0) { console.log('close') //$('#daImagePanel').css('display', 'none'); - // $('#daImagePanel').remove(); + // $('#daImagePanel').remove(); } } }); @@ -4079,17 +4179,18 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic top: 70, left: 1, }, - controls: { buttons: 'closeonly'}, + controls: { buttons: 'closeonly' }, size: { width: $(window).outerWidth(), height: $(window).outerHeight() + 60 }, //size: { width: $(window).outerWidth() - 10, height: $(window).outerHeight() - 110 }, }); } $rootScope.getLocalStorageValue = function (localStorageParam) { - - if ((localStorage.getItem('loggedInUserDetails') == null) && ($rootScope.isVisibleLogin == false)) - { - $rootScope.LogoutUser(); + + + if ((localStorage.getItem('loggedInUserDetails') == null) && ($rootScope.isVisibleLogin == false)) { + if ($location.url().indexOf('?em') == -1 && $location.url().indexOf('?unb') == -1) + $rootScope.LogoutUser(); } @@ -4189,7 +4290,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic } $(document).on('click', '#jsPanel-1 .jsglyph-remove', function () { - $("#daImagePanel").css({ "pointer-events": "auto", "opacity": "1" }); + $("#daImagePanel").css({ "pointer-events": "auto", "opacity": "1" }); $("#ciImagePanel").css({ "pointer-events": "auto", "opacity": "1" }); $("#annotationButton").parent().removeClass("disableMenuannotation"); $("#annotationToolBarOptions").removeClass("disableMenuoption"); @@ -4276,9 +4377,9 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic }; $rootScope.resetDrawing = function (e) { - - $('#canvas').removeLayers(); - + + $('#canvas').removeLayers(); + }; }] diff --git a/400-SOURCECODE/AIAHTML5.Web/app/main/AIA.js b/400-SOURCECODE/AIAHTML5.Web/app/main/AIA.js index b62f59b..9c7975e 100644 --- a/400-SOURCECODE/AIAHTML5.Web/app/main/AIA.js +++ b/400-SOURCECODE/AIAHTML5.Web/app/main/AIA.js @@ -14,11 +14,11 @@ AIA.constant('pages', [ pageController: 'HomeController' }, { // id:1, - name: 'Dissectible Anatomy Views List', - pageSlug: 'da-view-list', - pageUrl: 'app/views/da/da-body-view-list.html', - pageController: 'DAController' - }, + name: 'Dissectible Anatomy Views List', + pageSlug: 'da-view-list', + pageUrl: 'app/views/da/da-body-view-list.html', + pageController: 'DAController' + }, { //id:2, name: 'Dissectible Anatomy Body View', pageSlug: 'da-body-view', @@ -40,11 +40,11 @@ AIA.constant('pages', [ }, { - // id:4, - name: 'Clinical Animations', - pageSlug: 'clinical-animations', - pageUrl: 'app/views/ca/ca-view.html', - pageController: 'CAController' + // id:4, + name: 'Clinical Animations', + pageSlug: 'clinical-animations', + pageUrl: 'app/views/ca/ca-view.html', + pageController: 'CAController' }, { // id:5, @@ -139,7 +139,7 @@ AIA.constant('pages', [ pageController: 'LinkController' }, - { + { name: 'A.D.A.M OnDemand', pageSlug: 'Link/aod', pageUrl: 'app/views/Link/Link-view.html', @@ -239,8 +239,8 @@ AIA.constant('Modules', [ Name: 'Lab Exercises', }, { - Id: 9, - Name: 'ADAM Images', + Id: 9, + Name: 'ADAM Images', }, { Id: 10, @@ -249,32 +249,32 @@ AIA.constant('Modules', [ { Id: 11, Name: 'Encyclopedia', - + }, { Id: 12, Name: 'IP 10', }, - + { - Id: 13, - Name: 'In-Depth Reports', + Id: 13, + Name: 'In-Depth Reports', }, { - Id: 14, - Name: 'Complementary and Alternative Medicine', + Id: 14, + Name: 'Complementary and Alternative Medicine', }, { - Id: 15, - Name: 'Body Guide', + Id: 15, + Name: 'Body Guide', }, { - Id: 16, - Name: 'Health Navigator', + Id: 16, + Name: 'Health Navigator', }, { - Id: 17, - Name: 'The Wellness Tools', + Id: 17, + Name: 'The Wellness Tools', }, ]); @@ -291,7 +291,7 @@ AIA.constant('BodyRegions', ['Abdomen', 'Body Wall and Back', 'Head and Neck', ' AIA.constant('BodySystems', ['Cardiovascular', 'Digestive', 'Endocrine', 'Immune', 'Integumentary', 'Lymphatic', 'Muscular', 'Nervous', 'Reproductive', 'Respiratory', 'Skeletal', 'Urinary']); -AIA.constant('ViewOrientations', ['Anterior', 'Posterior', 'Lateral','Medial', 'Superior', 'Inferior', 'Non-standard']); +AIA.constant('ViewOrientations', ['Anterior', 'Posterior', 'Lateral', 'Medial', 'Superior', 'Inferior', 'Non-standard']); AIA.constant('MedicalSpecialties', ['Allergy & Immunology', 'Anesthesiology', 'Cardiology', 'Chiropractic', 'Dentistry', 'Dermatology', 'Embryology', 'Emergency Medicine', 'Endocrinology', 'First Aid', 'Gastroenterology', 'General Surgery', 'Geriatrics', 'Hematology', 'Infectious Diseases', 'Microbiology', 'Nuclear Medicine', 'Nephrology', 'Neurology', 'Nutrition', 'Obstetrics and Gynecology (OB/GYN)', 'Oncology (Cancer)', 'Opthalmology', 'Optometry', 'Orthopedics', 'Osteopathy', 'Otolaryngology (ENT)', 'Pathology', 'Pediatrics', 'Physiology', 'Plastic Surgery', 'Podiatry', 'Pulmonary Medicine', 'Radiology', 'Respiratory Therapy', 'Rheumatology', 'Sports Medicine', 'Urology', 'Vascular Medicine', 'Thoracic Surgery']); @@ -304,8 +304,10 @@ AIA.constant('ImageTypes', ['Illustration', 'Cadaver Photograph', 'Radiograph']) AIA.constant("LoginConstants", { "USER_NOT_FOUND": "User not found.", "ERROR_IN_FECTHING_DETAILS": "Error in fecthing details.", - "MAIL_NOT_SENT": "Mail not sent." - + "MAIL_NOT_SENT": "Mail not sent.", + "SQL_CONNECTION_ERROR": "SQL Connection Error", + "SQL_CONNECTION_ERROR_MESSAGE": "Due to some issue we are unable to connect with database. Kindly, contact customer support" + }) AIA.constant("LoginMessageConstants", { @@ -323,10 +325,22 @@ AIA.constant("LoginMessageConstants", { "NEW_PASSWORD_FIELD_IS_EMPTY": "Please enter new password to reset your password.", "PASSWORD_UPDATE_SUCCESS": "Password updated successfully", "PASSWORD_UPDATE_FAILED": "Password update failed", - "SUBSCRIPTION_EXPIRATION_MESSAGE": "Your license has been expired since ", + "SUBSCRIPTION_EXPIRATION_MESSAGE": "Your license is expired since ", "LICENSE_INACTIVE_MESSAGE": "Your license is inactive.", "INVALID_USER": "Invalid UserID", - "USER_INACTIVE_MESSAGE": "User ID is inactive." + "USER_INACTIVE_MESSAGE": "User ID is inactive.", + "INVALID_PASSWORD": "Invalid Password. UserID and password will be disabled if your password is entered incorrectly for five consecutive attempts. If you have forgotten your password, please click on the forgot password link.", + "USER_BLOCKED": 'Your User ID has been disabled for 24 hours. To unblock please click on "Reset Password" link and select "unblock" radio button.', + "UNBLOCK_SELECTED": "unblock", + "FORGOT_PASSWORD_SELECTED": "forgotpwd", + "USER_UNBLOCK_LINK_IN_EMAIL": "Please check you email and unblock your account.", + "USER_UNBLOCK_SUCCESS": "User unblocked", + "USER_UNBLOCK_SUCCESS_MESSAGE": "Your account has been unblocked sucessfully.", + "USER_UNBLOCK_FAILED": "Unblock operation failed", + "USER_ALREADY_UNBLOCKED": "User already unblocked.", + "LICENSE_TERM_CONDITION_UPDATE_SUCCESS": "License Term Accepted field updated successfully.", + "LICENSE_TERM_CONDITION_UPDATE_FAILED": "License Term Accepted field update failed." + //"ERROR_IN_FECTHING_DETAILS": "Error in fecthing details.", //"MAIL_NOT_SENT": "Mail not sent." @@ -335,8 +349,7 @@ AIA.constant("AdminConstants", { "ERROR_IN_SENDING_MAIL": "Some internal error occured.", "MAIL_SENT": "Mail sent.", "MAIL_NOT_SENT": "Mail not sent.", - "MAIL_SENT_SUCCESS_MESSAGE": "We have received your request. We will get back to you soon.", - + "MAIL_SENT_SUCCESS_MESSAGE": "We have received your request. We will get back to you soon." }) AIA.constant("UserTypeConstants", { "SUPER_ADMIN": "Super Admin", @@ -351,9 +364,9 @@ AIA.constant("UserTypeConstants", { }) AIA.constant("AIAConstants", { - - "NO_BODY_SYSTEM_AVAILABLE" : "This body system is not available on this layer.", - + + "NO_BODY_SYSTEM_AVAILABLE": "No body system available in this layer.", + }) AIA.constant("UserModules", [ @@ -428,7 +441,7 @@ AIA.constant("UserModules", [ ]); AIA.constant("AIAConstants", { - "NO_BODY_SYSTEM_AVAILABLE" : "No body system available in this layer.", + "NO_BODY_SYSTEM_AVAILABLE": "No body system available in this layer.", }) AIA.config(function ($routeProvider, pages, $locationProvider) { diff --git a/400-SOURCECODE/AIAHTML5.Web/app/services/AuthenticationService.js b/400-SOURCECODE/AIAHTML5.Web/app/services/AuthenticationService.js index 5b8918f..9ba8f23 100644 --- a/400-SOURCECODE/AIAHTML5.Web/app/services/AuthenticationService.js +++ b/400-SOURCECODE/AIAHTML5.Web/app/services/AuthenticationService.js @@ -70,6 +70,24 @@ deferred.reject(status); }); return deferred.promise; + }, + + UnblockUser: function (userEmailId) { + var deferred = $q.defer(); + + $http.post('/API/api/UnblockUser', JSON.stringify(userEmailId), { + headers: { + 'Content-Type': 'application/json' + } + }) + .success(function (data, status, headers, config) { + console.log('success') + deferred.resolve(data); + }).error(function (data, status, headers, config) { + console.log('error') + deferred.reject(status); + }); + return deferred.promise; } } diff --git a/400-SOURCECODE/AIAHTML5.Web/index.html b/400-SOURCECODE/AIAHTML5.Web/index.html index 8e2ffc8..efe5b47 100644 --- a/400-SOURCECODE/AIAHTML5.Web/index.html +++ b/400-SOURCECODE/AIAHTML5.Web/index.html @@ -159,7 +159,6 @@ #refreshBtn { color: #ffffff; } - @@ -231,7 +230,7 @@