Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.Security;
- using System.Data;
- using System.Configuration;
- using System.Security.Principal;
- using BinOp.BusinessLogic.Web;
- using BinOp.BusinessLogic.Operations;
- using BinOp.Web.Security;
- using BinOp.Web;
- using BinOp.Core;
- using BinOp.Site.Code.Payments.Parameters;
- using System.Web.SessionState;
- namespace BinOp.Site.Code
- {
- public class BasePage : Page
- {
- private const string USER_INFO_KEY = "USER_INFO";
- private const string DEFAULT_AUTHENTIFICATION_KEY = "DefaultAuthentificationPassed";
- private const string USER_AGENT = "http_user_agent";
- private const string SAFARI = "safari";
- private const string UPLEVEL = "uplevel";
- private const string TRUE = "true";
- private const string COLUMN_USER_ID = "UserID";
- private const string COLUMN_FIRST_NAME = "FirstName";
- private const string COLUMN_LAST_NAME = "LastName";
- private const string COLUMN_EMAIL = "Email";
- private const string COLUMN_PHONENUMBER = "PhoneNumber";
- private const string COLUMN_CHAT_BLOCKED = "ChatBlocked";
- private const string DEFAULT_PAGE_KEY = "DefaultPage";
- private const string LANGUAGE_DROPDOWN_ID = "ddlLanguage";
- private const string EVENT_TARGET = "__EVENTTARGET";
- private const string DEFAULT_VOUCHER = "DefaultVoucher";
- private const string SSL_PORT_KEY = "SslPort";
- private const string HTTP_PORT_KEY = "HttpPort";
- private const string COLUMN_BIRTH_DATE = "BirthDate";
- public string MainDepositPageURl { get; set; }
- public string PaymentProviderName { get; set; }
- protected class CustomErrorMessage : IValidator
- {
- private string Message;
- public CustomErrorMessage(string message)
- {
- this.Message = message;
- }
- public string ErrorMessage { get { return Message; } set { Message = value; } }
- public bool IsValid { get { return false; } set { } }
- public void Validate() { }
- }
- public BasePage()
- {
- const string SSL_ON_PAGES_KEY = "SslOnPages";
- //Verify ssl
- var attribute = this.GetType().GetCustomAttributes(typeof(RequireSSLAttribute), true).FirstOrDefault() as RequireSSLAttribute;
- //Get SslOnPages from configuration to override attributes
- var sslOnPages = ConfigUtilities.GetAppSettingsBoolean(SSL_ON_PAGES_KEY);
- if (HttpContext.Current.Request.Url.Scheme == Uri.UriSchemeHttps && (attribute == null || !attribute.RequireSSL) && sslOnPages)
- {
- //Redirect to http
- var httpPort = ConfigUtilities.GetAppSettingsInt(HTTP_PORT_KEY);
- WebUtils.RedirectToHttp(this.Context, httpPort);
- return;
- }
- else if (HttpContext.Current.Request.Url.Scheme == Uri.UriSchemeHttp && (attribute != null && attribute.RequireSSL) && sslOnPages)
- {
- //Redirect to https
- var sslPort = ConfigUtilities.GetAppSettingsInt(SSL_PORT_KEY);
- WebUtils.RedirectToSsl(this.Context, sslPort);
- return;
- }
- //Verify role
- object[] attributes = this.GetType().GetCustomAttributes(typeof(RequiredRoleAttribute), true);
- if (attributes.Length > 0)
- {
- IPrincipal user = HttpContext.Current.User;
- if (user != null)
- {
- RequiredRoleAttribute roleAttribute = null;
- for (int i = 0; i < attributes.Length; i++)
- {
- roleAttribute = attributes[i] as RequiredRoleAttribute;
- if (!user.IsInRole(roleAttribute.Role))
- {
- FormsAuthentication.RedirectToLoginPage();
- }
- }
- }
- else
- FormsAuthentication.RedirectToLoginPage();
- }
- string affid = HttpContext.Current.Request.Params.Get("AFFID");
- if (affid != null)
- {
- HttpCookie aCookie = new HttpCookie("userInfo");
- aCookie.Values["AFFID"] = affid;
- aCookie.Values["lastVisit"] = DateTime.Now.ToString();
- HttpContext.Current.Response.Cookies.Add(aCookie);
- }
- //logic for refer a friend functionality to store the referal id in a cookie
- string referalId = HttpContext.Current.Request.Params.Get("REF");
- if (referalId != null)
- {
- Session["REF"] = referalId; //???
- HttpCookie refCookie = new HttpCookie("refInfo");
- refCookie.Values["REF"] = referalId;
- refCookie.Values["lastVisit"] = DateTime.Now.ToString();
- HttpContext.Current.Response.Cookies.Add(refCookie);
- }
- this.SetProviderName();
- }
- public UserDescriptor UserInfo
- {
- get
- {
- object info = Session[USER_INFO_KEY];
- if (info != null)
- return info as UserDescriptor;
- return null;
- }
- set
- {
- Session[USER_INFO_KEY] = value;
- }
- }
- protected void ShowCustomValidationMessage(string message)
- {
- Validators.Add(new CustomErrorMessage(message));
- }
- protected override void OnPreInit(EventArgs e)
- {
- if (HttpContext.Current.User.Identity.IsAuthenticated)
- {
- if (UserInfo == null || HttpContext.Current.User.Identity.Name != UserInfo.EMail)
- {
- Helper.LoginUserByEmail(HttpContext.Current.User.Identity.Name, null);
- }
- }
- else
- {
- UserInfo = null;
- Session["HideTradeBoxExcept"] = null;
- }
- if (!String.IsNullOrEmpty(Page.Request.ServerVariables[USER_AGENT]))
- {
- string servVar = Page.Request.ServerVariables[USER_AGENT];
- if (servVar.ToLower().Contains(SAFARI))
- Page.ClientTarget = UPLEVEL;
- }
- base.OnPreInit(e);
- }
- protected override void OnLoad(EventArgs e)
- {
- if (User.Identity.IsAuthenticated && UserInfo != null)
- {
- UsersOperations.SetLastActivity(UserInfo.UserID);
- }
- base.OnLoad(e);
- }
- public string CurrencySign
- {
- get
- {
- if (UserInfo != null && !string.IsNullOrEmpty(UserInfo.CurrencySign))
- {
- return UserInfo.CurrencySign;
- }
- return ConfigurationManager.AppSettings["DefaultCurrencySymbol"] ?? "$";
- }
- }
- /*
- public UserDescriptor FillUserData(object ResultValue)
- {
- DataTable userData = ResultValue as DataTable;
- if (userData != null && userData.Rows.Count == 0) return null;
- int userID = Convert.ToInt32(userData.Rows[0][COLUMN_USER_ID]);
- string firstName = Convert.ToString(userData.Rows[0][COLUMN_FIRST_NAME]);
- string lastName = Convert.ToString(userData.Rows[0][COLUMN_LAST_NAME]);
- string email = Convert.ToString(userData.Rows[0][COLUMN_EMAIL]);
- string phoneNumber = Convert.ToString(userData.Rows[0][COLUMN_PHONENUMBER]);
- int chatBlocked = Convert.ToInt32(userData.Rows[0][COLUMN_CHAT_BLOCKED]);
- DateTime BirthDate = Convert.ToDateTime(userData.Rows[0][COLUMN_BIRTH_DATE]);
- return new UserDescriptor(userID, firstName, lastName, email, phoneNumber, chatBlocked, BirthDate);
- }
- */
- private bool DefaultAuthentificationPassed
- {
- get
- {
- if (Session[DEFAULT_AUTHENTIFICATION_KEY] != null)
- return Convert.ToBoolean(Session[DEFAULT_AUTHENTIFICATION_KEY]);
- return false;
- }
- set
- {
- Session[DEFAULT_AUTHENTIFICATION_KEY] = value;
- }
- }
- public string DefaultPage
- {
- get
- {
- return ConfigurationManager.AppSettings[DEFAULT_PAGE_KEY];
- }
- }
- protected bool IsLanguageChangeRequest
- {
- get
- {
- string targetId = Context.Request.Form[EVENT_TARGET];
- if (!String.IsNullOrEmpty(targetId))
- return targetId.EndsWith(LANGUAGE_DROPDOWN_ID);
- return false;
- }
- }
- protected int DefaultVoucherValue
- {
- get
- {
- int val = 0;
- if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings[DEFAULT_VOUCHER]))
- int.TryParse(ConfigurationManager.AppSettings[DEFAULT_VOUCHER], out val);
- return val;
- }
- }
- protected override void OnPreRender(EventArgs e)
- {
- MasterPage master = Master;
- while (master != null && !(master is Site.masterpages.root))
- master = master.Master;
- if (master != null) (master as Site.masterpages.root).HideVoucher(DefaultVoucherValue);
- master = Master;
- while (master != null && !(master is Site.masterpages.navigation))
- master = master.Master;
- if (master != null) (master as Site.masterpages.navigation).HideVoucher(DefaultVoucherValue);
- HideVouchers(DefaultVoucherValue);
- base.OnPreRender(e);
- }
- /// <summary>
- /// Get user's temo demo exiration date by ID
- /// </summary>
- /// <param name="userID">The current logged user ID</param>
- /// <returns>The current user temp demo expiration date or null</returns>
- protected DateTime? GetUserTempDemoExpiration(int userID)
- {
- OperationResult result = UsersOperations.GetUserTempDemoExpiration(userID);
- if (result.ProcessedSuccessful)
- {
- DateTime tempDemoExpirationDate = new DateTime();
- if (DateTime.TryParse(result.ResultValue.ToString(), out tempDemoExpirationDate))
- {
- return tempDemoExpirationDate;
- }
- }
- return null;
- }
- /// <summary>
- /// Redirects the user to the default login page if the session parameter UserInfo is empty or the user is not authenticated
- /// </summary>
- protected void HandleNotLoggedInUsers()
- {
- if (UserInfo == null || !User.Identity.IsAuthenticated)
- {
- Response.Redirect("~/trading");
- }
- }
- protected virtual void HideVouchers(int voucher)
- {
- }
- protected void SetProviderName()
- {
- this.PaymentProviderName = ConfigurationManager.AppSettings["ChargeProvider"];
- if (!string.IsNullOrEmpty(this.PaymentProviderName))
- {
- switch (this.PaymentProviderName)
- {
- case PaymentTypeConstants.SOLID_3D:
- case PaymentTypeConstants.CASHU:
- this.MainDepositPageURl = "SimpleDepositForm";
- break;
- default:
- this.MainDepositPageURl = "Deposit";
- break;
- }
- }
- }
- protected void RedirectToProperPaymentProviderPage(string commingFrom)
- {
- if (this.MainDepositPageURl != commingFrom && this.MainDepositPageURl != "SimpleDepositForm")
- {
- Response.Redirect(this.MainDepositPageURl);
- }
- }
- protected string GetUserCurrencyNameForUser()
- {
- return CurrencyHelper.GetUserCurrencyNameForUser(UserInfo.UserID);
- }
- /// <summary>
- /// Create additional parameters associated with a user
- /// </summary>
- protected void CreateAdditionalParameters(int userID)
- {
- string name = string.Empty;
- string value = string.Empty;
- string externParametersString = ConfigurationManager.AppSettings["ExternalParameters"];
- if (!string.IsNullOrEmpty(externParametersString))
- {
- string[] externalParameterNames = externParametersString.Split(',');
- string externalContainerName = ConfigurationManager.AppSettings["ExternalContainerName"];
- string currentExternalParameterName = string.Empty;
- string currentExternalParameterValue = string.Empty;
- foreach (string externalParameterName in externalParameterNames)
- {
- currentExternalParameterName = externalParameterName.Trim();
- if (!string.IsNullOrEmpty(externalContainerName))
- {
- HttpCookie currentCookie = Request.Cookies[externalContainerName];
- // get the value from a cookie
- if (currentCookie != null && currentCookie[currentExternalParameterName] != null)
- {
- value = currentCookie[currentExternalParameterName];
- name = currentExternalParameterName;
- }
- else // check the session for a parameter value
- {
- if (Session[currentExternalParameterName] != null)
- {
- value = Session[currentExternalParameterName].ToString();
- name = currentExternalParameterName;
- }
- else
- {
- Session.Add(currentExternalParameterName, currentExternalParameterValue);
- }
- }
- // save into the database
- if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(value))
- {
- ExternalParametersOperations.Save(userID, name, value);
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement