Exemplo n.º 1
0
        public APIResponse RecoverPasswordAction()
        {
            string Email = UserProfileObj.GetEmail();

            try
            {
                string      FPToken        = SHA256.Instance().GetUniqueKey(100);
                APIResponse ApiResponseObj = new UserActions(UserProfileObj).RecoverPasswordAction();
                if (ApiResponseObj == APIResponse.OK)
                {
                    // send the mail
                }
                return(APIResponse.OK);
            }
            catch (MySqlException mse)
            {
                Logger.Instance().Log(Warn.Instance(), mse);
                throw mse;
            }
            catch (Exception ex)
            {
                Logger.Instance().Log(Warn.Instance(), ex);
                throw ex;
            }
        }
Exemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        ProductResponse ProductResponseObj = null;

        try
        {
            if (Request.QueryString["k"] != null)
            {
                ProductResponseObj = new ProductsList().FetchProducts(HttpUtility.UrlDecode(Request.QueryString["k"].ToString()));
                Logger.Instance().Log(Info.Instance(), new LogInfo("Product Searched : " + HttpUtility.UrlDecode(Request.QueryString["k"].ToString())));
            }
            else
            {
                ProductResponseObj = new ProductsList().FetchProducts();
            }
        }
        catch (Exception ex)
        {
            ProductResponseObj = new ProductResponse
            {
                HasProducts    = false,
                responseString = "Unable to view products this time, please try again later"
            };
            Logger.Instance().Log(Warn.Instance(), ex);
        }
        finally
        {
            Response.Write(new JavaScriptSerializer().Serialize(ProductResponseObj));
        }
    }
 public override List <ICategory> Select()
 {
     try
     {
         bool Response = new Security(UserProfileObj).AuthenticateAdmin();
         if (Response == true)
         {
             return(CategoryTemplateObj.Select());
         }
         else
         {
             return(null);
         }
     }
     catch (NullReferenceException nex)
     {
         Logger.Instance().Log(Warn.Instance(), new LogInfo("Received null reference while fetching category (Routine : AuthenticateAdmin), might be token manipulation. Check token : " + UserProfileObj.GetToken()));
         throw nex;
     }
     catch (Exception ex)
     {
         Logger.Instance().Log(Fatal.Instance(), ex);
         throw ex;
     }
 }
Exemplo n.º 4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        List <IUserProfile> UserList = null;

        try
        {
            UserProfile UserProfileObj = new UserProfile();
            UserProfileObj.SetToken(CookieProxy.Instance().GetValue("t").ToString());
            UserTemplate <IUserProfile> Profile = new NormalUserTemplate(UserProfileObj, Request.Form["s"]);
            UserList = Profile.FetchList();
            if (UserList == null)
            {
                CookieProxy.Instance().SetValue("LoginMessage", "Unable to authenticate the token, please relogin or check logs", DateTime.Now.AddDays(2));
            }
            Logger.Instance().Log(Info.Instance(), new LogInfo(new AdminUserTemplate().FetchParticularProfile(UserProfileObj).GetEmail() + " searched for user " + Request.Form["s"]));
        }
        catch (Exception ex)
        {
            CookieProxy.Instance().SetValue("LoginMessage", "An Error occured while processing the request, please check logs", DateTime.Now.AddDays(2));
            Logger.Instance().Log(Warn.Instance(), ex);
        }
        finally
        {
            Response.Write(new JavaScriptSerializer().Serialize(UserList));
        }
    }
Exemplo n.º 5
0
 protected void Page_Load(object sender, EventArgs e)
 {
     // check whether user is logged in or not
     try
     {
         if (CookieProxy.Instance().HasKey("t") == false)
         {
             CookieProxy.Instance().SetValue("LoginMessage", "You need to login to view this page", DateTime.Now.AddSeconds(10));
             Response.Redirect("/Signout", false);
         }
         else
         {
             IUserProfile UserProfileObj = new UserProfile(CookieProxy.Instance().GetValue("t").ToString());
             if (new Security(UserProfileObj).AuthenticateUser() == false)
             {
                 CookieProxy.Instance().SetValue("LoginMessage", "Relogin required to proceed", DateTime.Now.AddSeconds(10));
                 Response.Redirect("/Signout", false);
             }
         }
     }
     catch (Exception ex)
     {
         Logger.Instance().Log(Warn.Instance(), ex);
         CookieProxy.Instance().SetValue("LoginMessage", "An error occured, this event has been logged", DateTime.Now.AddSeconds(10));
         Response.Redirect("/Signout");
     }
 }
Exemplo n.º 6
0
 public bool AuthenticateAdmin()
 {
     try
     {
         if (UserProfileObj.GetIsAdmin() == false)
         {
             Logger.Instance().Log(Warn.Instance(), new LogInfo(UserProfileObj.GetEmail().ToString() + " tried to access the admin panel but failed. "));
         }
         return(UserProfileObj.GetIsAdmin());
     }
     catch (ArgumentException AEX)
     {
         Logger.Instance().Log(Warn.Instance(), new WarnDebug("Anonymous user tried to access the Admin panel, but failed"));
         throw AEX;
     }
     catch (NullReferenceException nex)
     {
         Logger.Instance().Log(Fatal.Instance(), new LogInfo("Unable to authenticate Admin, got exception : " + nex.Message.ToString()));
         throw nex;
     }
     catch (Exception ex)
     {
         Logger.Instance().Log(Fatal.Instance(), ex);
         throw ex;
     }
 }
 public override APIResponse Insert(ICategory CategoryObj)
 {
     try
     {
         bool Response = new Security(UserProfileObj).AuthenticateAdmin();
         if (Response == true)
         {
             if (0 == CategoryTemplateObj.Insert(CategoryObj))
             {
                 return(APIResponse.NOT_OK);
             }
             else
             {
                 return(APIResponse.OK);
             }
         }
         else
         {
             return(APIResponse.NOT_AUTHENTICATED);
         }
     }
     catch (NullReferenceException nex)
     {
         Logger.Instance().Log(Warn.Instance(), new LogInfo("Received null reference while adding category (Routine : AuthenticateAdmin), might be token manipulation. Check token : " + UserProfileObj.GetToken()));
         throw nex;
     }
     catch (Exception ex)
     {
         Logger.Instance().Log(Fatal.Instance(), ex);
         throw ex;
     }
 }
Exemplo n.º 8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string ResponseValue  = "";
        string ResponseString = "";

        try
        {
            if (CookieProxy.Instance().HasKey("t"))
            {
                UserProfile UserProfileObj = new UserProfile();
                Category    CategoryObj    = new Category();
                UserProfileObj.SetToken(CookieProxy.Instance().GetValue("t").ToString());
                CategoryObj.SetCategoryId(int.Parse(Request.Form["c"]));
                APIResponse Response = new CategoryBusinessLayerTemplate(UserProfileObj).Delete(CategoryObj);
                ResponseValue = Response.ToString();

                if (Response == APIResponse.NOT_OK)
                {
                    ResponseString = "Unable to delete the category, please check logs";
                }
                else
                {
                    Logger.Instance().Log(Info.Instance(), new LogInfo(new AdminUserTemplate().FetchParticularProfile(UserProfileObj).GetEmail() + " deleted the category ID " + Request.Form["c"].ToString()));
                }
            }
            else
            {
                ResponseValue  = APIResponse.NOT_OK.ToString();
                ResponseString = "NOT_AUTHENTICATED";
            }
        }
        catch (NullReferenceException nex)
        {
            CookieProxy.Instance().SetValue("LoginMessage", "Not Authorized, please login with correct credentials. If you believe this is an error, please check logs".ToString(), DateTime.Now.AddDays(2));
            Logger.Instance().Log(Warn.Instance(), nex);
            ResponseValue  = APIResponse.NOT_OK.ToString();
            ResponseString = "NOT_AUTHENTICATED";
        }
        catch (MySqlException mse)
        {
            Logger.Instance().Log(Warn.Instance(), mse);
            ResponseValue  = APIResponse.NOT_OK.ToString();
            ResponseString = "Unable to delete category, please delete the products first linked to category before deleting category";
        }
        catch (Exception ex)
        {
            Logger.Instance().Log(Warn.Instance(), ex);
            ResponseValue  = APIResponse.NOT_OK.ToString();
            ResponseString = "Unable to delete the category, please check logs";
        }
        finally
        {
            var output = new
            {
                Code     = ResponseValue,
                Response = ResponseString,
            };
            Response.Write(new JavaScriptSerializer().Serialize(output));
        }
    }
Exemplo n.º 9
0
    private void PopulateAndSetMaintenanceMode()
    {
        try
        {
            // populate the dropdown values
            dropdown_maintenance_mode.Items.Insert(0, new ListItem("Disabled", "0"));
            dropdown_maintenance_mode.Items.Insert(1, new ListItem("Enabled", "1"));

            string MaintenanceValue = "0";
            // set the dropdown values
            foreach (Settings SettingObj in ListOfSettings.GetSettingsList())
            {
                if (SettingObj.GetSettingsKey() == "MAINTENANCE")
                {
                    MaintenanceValue = SettingObj.GetSettingsValue();
                    break;
                }
            }
            dropdown_maintenance_mode.SelectedValue = MaintenanceValue;
            TextStatus.Visible = false;
            dropdown_maintenance_mode.Visible = true;
        }
        catch (Exception ex)
        {
            Logger.Instance().Log(Warn.Instance(), ex);
            dropdown_maintenance_mode.Visible = false;
            TextStatus.Visible   = true;
            TextStatus.BackColor = System.Drawing.Color.FromArgb(Int32.Parse("FF6E6E", NumberStyles.HexNumber));
            TextStatus.ForeColor = System.Drawing.Color.White;
        }
    }
Exemplo n.º 10
0
    protected void Page_Load(object sender, EventArgs e)
    {
        APIResponse ResponseENUM   = APIResponse.NOT_OK;
        string      ResponseString = "";

        try
        {
            CookieProxy.Instance().RemoveKey("Cart");
            ResponseENUM   = APIResponse.OK;
            ResponseString = "SUCCESS";
        }
        catch (Exception ex)
        {
            Logger.Instance().Log(Warn.Instance(), ex);
            ResponseENUM   = APIResponse.NOT_OK;
            ResponseString = "ERROR";
        }
        finally
        {
            var ReturnObj = new
            {
                Response = ResponseENUM.ToString(),
                ResponseString
            };
            Response.Write(new JavaScriptSerializer().Serialize(ReturnObj));
        }
    }
Exemplo n.º 11
0
        public IOrderDetailsResponse FetchOrderDetailsByOrderID(IOrder OrderObj, IUserProfile UserProfileObj)
        {
            try
            {
                IOrderDetailsResponse            Response = null;
                List <ITaxOrderDetailsByProduct> ProductList;
                DataSet OrderDetailsResponse = new OrderDetailsDataLayer(UserProfileObj, OrderObj).FetchOrderDetailsByID();
                if (OrderDetailsResponse.Tables[0].Rows.Count > 0)
                {
                    ProductList = new List <ITaxOrderDetailsByProduct>();
                    IOrderDetailsDateAndStatus OrderDetailsDateAndStatusObj = new OrderDetailsDateAndStatus(DateTime.Parse(OrderDetailsResponse.Tables[0].Rows[0]["date"].ToString()), OrderDetailsResponse.Tables[0].Rows[0]["statusName"].ToString());
                    foreach (DataRow dr in OrderDetailsResponse.Tables[2].Rows)
                    {
                        IStores StoreObj = new Stores();
                        StoreObj.SetStoreLogo(dr["storeLogo"].ToString());
                        IProduct ProductObj = new ProductsOnly();
                        ProductObj.SetProductName(dr["productName"].ToString());
                        ProductObj.SetProductImage(dr["productImage"].ToString());
                        ProductObj.SetProductQuantity(int.Parse(dr["quantity"].ToString()));
                        ITaxOrderDetailsByProduct ProductListObj = new TaxOrderDetailsByProduct(StoreObj, ProductObj, double.Parse(dr["PreTaxProductPrice"].ToString()), double.Parse(dr["PostTaxProductPrice"].ToString()), double.Parse(dr["taxAmount"].ToString()));
                        ProductList.Add(ProductListObj);
                    }
                    DataRow  AddressRow = OrderDetailsResponse.Tables[1].Rows[0];
                    IAddress AddressObj = new Address(
                        AddressRow["addressName"].ToString(),
                        AddressRow["appt"].ToString(),
                        AddressRow["postalCode"].ToString(),
                        AddressRow["phone"].ToString(),
                        AddressRow["city"].ToString(),
                        AddressRow["city"].ToString(),
                        AddressRow["Province"].ToString()
                        );
                    DataRow           TaxComputedRow = OrderDetailsResponse.Tables[3].Rows[0];
                    IComputedTaxPrice ComputedObj    = new ComputedTaxPrice(
                        int.Parse(TaxComputedRow["TotalUniqueQuantity"].ToString()),
                        int.Parse(TaxComputedRow["TotalQuantity"].ToString()),
                        double.Parse(TaxComputedRow["TotalPreTaxProductPrice"].ToString()),
                        double.Parse(TaxComputedRow["TotalPostTaxProductPrice"].ToString()),
                        double.Parse(TaxComputedRow["TotalTaxAmount"].ToString())
                        );
                    ICardDetails CardObj             = new CardDetails(int.Parse(OrderDetailsResponse.Tables[0].Rows[0]["caID"].ToString()));
                    ICardDetails OutputCardDecrypted = new CardDetailsBusinessLayerTemplate(UserProfileObj).Select(CardObj);
                    Response = new OrderDetailResponse(true, ProductList, OrderDetailsDateAndStatusObj, AddressObj, ComputedObj, OutputCardDecrypted);
                }
                else
                {
                    Response = new OrderDetailResponse(false);
                }

                return(Response);
            }
            catch (Exception ex)
            {
                Logger.Instance().Log(Warn.Instance(), ex);
                throw ex;
            }
        }
Exemplo n.º 12
0
        public LoginUserReponse LoginUserAction(IUserProfile UserProfileObj)
        {
            bool   IsLoggedIn     = false;
            string Email          = UserProfileObj.GetEmail();
            string Password       = UserProfileObj.GetPassword();
            string Token          = "";
            string ErrorText      = "";
            string DbSalt         = "";
            string DbHashPassword = "";
            string HashPassword   = "";

            try
            {
                DataSet output = new UserActionsDataLayer(UserProfileObj).GetHashedPassword();
                if (output.Tables[0].Rows.Count > 0)
                {
                    DbSalt         = output.Tables[0].Rows[0]["salt"].ToString();
                    DbHashPassword = output.Tables[0].Rows[0]["password"].ToString();
                    HashPassword   = SHA256.Instance().hash(Password + DbSalt);
                    if (DbHashPassword == HashPassword)
                    {
                        Token = SHA256.Instance().hash(Email + Password + DateTime.Now.ToString());
                        // create a long token
                        Token += SHA256.Instance().hash(Email + Password + DateTime.Now.AddSeconds(200).ToString());
                        UserProfileObj.SetToken(Token);
                        // update the token value to database so as to authenticate the user for all events
                        new Security(UserProfileObj).AddTokenToDB();
                        IsLoggedIn = true;
                    }
                    else
                    {
                        IsLoggedIn = false;
                        Logger.Instance().Log(Warn.Instance(), new WarnDebug("Authentication failed for email : " + Email.ToString()));
                        ErrorText = "Invalid Email ID and password combination";
                    }
                }
                else
                {
                    IsLoggedIn = false;
                    ErrorText  = "Invalid Email ID and password combination";
                }
            }
            catch (Exception ex)
            {
                Logger.Instance().Log(Fatal.Instance(), ex);
                IsLoggedIn = false;
                ErrorText  = "Unable to login to the system, please try again later. This event has been logged";
                throw ex;
            }
            LoginUserReponse LoginResponse = new LoginUserReponse();

            LoginResponse.SetIsLoggedIn(IsLoggedIn);
            LoginResponse.SetErrorText(ErrorText);
            LoginResponse.SetToken(Token);
            return(LoginResponse);
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        bool   HasOrders       = false;
        bool   IsAuthenticated = false;
        string ResponseString  = "";
        List <IOrderBuilderResponse> ListOfOrders = null;

        try
        {
            if (CookieProxy.Instance().HasKey("t"))
            {
                IUserProfile UserProfileObj = new UserProfile();
                UserProfileObj.SetToken(CookieProxy.Instance().GetValue("t").ToString());
                // authenticate incoming token
                new Security(UserProfileObj).AuthenticateUser();
                IOrder            OrderObj = new Order();
                OrderTypeTemplate Order    = new IndividualOrderTemplate(UserProfileObj, OrderObj);
                ListOfOrders   = Order.FetchCancelledOrderID();
                ResponseString = "SUCCESS";

                IsAuthenticated = true;
                if (ListOfOrders.Count == 0)
                {
                    HasOrders = false;
                }
                else
                {
                    HasOrders = true;
                }
            }
            else
            {
                ResponseString = "INVALID";
            }
        }
        catch (Exception ex)
        {
            Logger.Instance().Log(Warn.Instance(), ex);
            ResponseString = "Unable to fetch the orders this time, please try again later";
        }
        finally
        {
            var JSONResponse = new
            {
                HasOrders,
                IsAuthenticated,
                Response = ResponseString,
                ListOfOrders
            };

            Response.Write(new JavaScriptSerializer().Serialize(JSONResponse));
        }
    }
Exemplo n.º 14
0
 public List <string> GetTokenList()
 {
     try
     {
         List <string> Result = SecurityObjDataLayer.GetTokenList();
         return(Result);
     }
     catch (Exception ex)
     {
         Logger.Instance().Log(Warn.Instance(), ex);
         throw ex;
     }
 }
Exemplo n.º 15
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string           ResponseValue  = "";
        string           ResponseString = "";
        List <ICategory> Categories     = null;

        try
        {
            UserProfile UserProfileObj = new UserProfile();
            UserProfileObj.SetToken(CookieProxy.Instance().GetValue("t").ToString());
            Categories = new CategoryBusinessLayerTemplate(UserProfileObj).Select();
            if (null == Categories)
            {
                ResponseValue  = APIResponse.NOT_OK.ToString();
                ResponseString = "NOT_AUTHENTICATED";
                CookieProxy.Instance().SetValue("LoginMessage", "Not Authorized, please login with correct credentials".ToString(), DateTime.Now.AddDays(2));
                Logger.Instance().Log(Info.Instance(), new LogInfo(new AdminUserTemplate().FetchParticularProfile(UserProfileObj).GetEmail() + " fetched category list"));
            }
            else
            {
                Logger.Instance().Log(Info.Instance(), new LogInfo(new AdminUserTemplate().FetchParticularProfile(UserProfileObj).GetEmail() + " fetched category list "));
                ResponseValue  = APIResponse.OK.ToString();
                ResponseString = "SUCCESS";
            }
        }
        catch (NullReferenceException nex)
        {
            CookieProxy.Instance().SetValue("LoginMessage", "Not Authorized, please login with correct credentials. If you believe this is an error, please check logs".ToString(), DateTime.Now.AddDays(2));
            Logger.Instance().Log(Warn.Instance(), nex);
            ResponseValue  = APIResponse.NOT_OK.ToString();
            ResponseString = "NOT_AUTHENTICATED";
        }
        catch (Exception ex)
        {
            Logger.Instance().Log(Warn.Instance(), ex);
            ResponseValue  = APIResponse.NOT_OK.ToString();
            ResponseString = "Unable to fetch the list of categories, please check logs";
        }
        finally
        {
            var output = new
            {
                Code           = ResponseValue,
                Response       = ResponseString,
                CategoriesList = Categories
            };
            Response.Write(new JavaScriptSerializer().Serialize(output));
        }
    }
Exemplo n.º 16
0
    protected void Page_Load(object sender, EventArgs e)
    {
        APIResponse ResponseENUM   = APIResponse.NOT_OK;
        string      ResponseString = "";

        try
        {
            Cart CartObj = null;
            if (CookieProxy.Instance().HasKey("Cart"))
            {
                int PBSId = int.Parse(Request.Form["pbsid"].ToString());
                CartObj = new JavaScriptSerializer().Deserialize <Cart>(CookieProxy.Instance().GetValue("Cart").ToString());
                int Iterator = 0;
                foreach (CartItems Cart in CartObj.CartItems)
                {
                    if (Cart.ProductObj.pbsID == PBSId)
                    {
                        CartObj.CartItems.RemoveAt(Iterator);
                        ResponseENUM   = APIResponse.OK;
                        ResponseString = "SUCCESS";
                        break;
                    }
                    Iterator += 1;
                }
                CookieProxy.Instance().SetValue("Cart", new JavaScriptSerializer().Serialize(CartObj), DateTime.Now.AddDays(5));
            }
            else
            {
                ResponseENUM   = APIResponse.NOT_OK;
                ResponseString = "AN ERROR OCCURED WHILE READING THE CART, PLEASE CLEAR YOUR COOKIES";
            }
        }
        catch (Exception ex)
        {
            Logger.Instance().Log(Warn.Instance(), ex);
            ResponseENUM   = APIResponse.NOT_OK;
            ResponseString = "AN ERROR OCCURED WHILE READING THE CART, PLEASE CLEAR YOUR COOKIES";
        }
        finally
        {
            var ReturnObj = new
            {
                Response = ResponseENUM.ToString(),
                ResponseString
            };
            Response.Write(new JavaScriptSerializer().Serialize(ReturnObj));
        }
    }
Exemplo n.º 17
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string LoginMessage = "";

        try
        {
            if (CookieProxy.Instance().HasKey("LoginMessage"))
            {
                LoginMessage = CookieProxy.Instance().GetValue("LoginMessage").ToString();
            }
            // remove the session
            SessionProxy.Instance().RemoveKey("USER.AUTHENTICATED");

            // remove the cookies
            CookieProxy.Instance().RemoveKey("t");
            CookieProxy.Instance().RemoveKey("um");

            // redirect to login
            if (Request.QueryString["r"] != null)
            {
                // set the redirect cookie
                CookieProxy.Instance().SetValue("InternalRedirect", Request.QueryString["r"], DateTime.Now.AddSeconds(10));
                Response.Redirect("/InternalRedirect");
            }
            UserProfile UserProfileObj = new UserProfile();
            if (CookieProxy.Instance().HasKey("t"))
            {
                UserProfileObj.SetToken(CookieProxy.Instance().GetValue("t").ToString());
                new Security(UserProfileObj).RemoveTokenFromDB();
            }
        }
        catch (Exception ex)
        {
            Logger.Instance().Log(Warn.Instance(), ex);
        }
        finally
        {
            if (LoginMessage != "")
            {
                CookieProxy.Instance().SetValue("LoginMessage", LoginMessage, DateTime.Now.AddDays(2));
            }
        }
        Response.Redirect("/login");
    }
Exemplo n.º 18
0
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         UserProfile UserProfileObj = new UserProfile();
         if (CookieProxy.Instance().HasKey("t"))
         {
             UserProfileObj.SetToken(CookieProxy.Instance().GetValue("t").ToString());
             // check if the current user is admin or not
             bool AuthAdminResponseObj = new Security(UserProfileObj).AuthenticateAdmin();
             if (AuthAdminResponseObj == false)
             {
                 CookieProxy.Instance().SetValue("LoginMessage", "Not Authorized, please login with correct credentials".ToString(), DateTime.Now.AddDays(2));
                 Response.Redirect("/signout.aspx", false);
             }
             else
             {
                 UserTemplate <IUserProfile> Template = new AdminUserTemplate();
                 userName.Text = Template.FetchParticularProfile(UserProfileObj).GetFirstName();
             }
         }
         else
         {
             Logger.Instance().Log(Warn.Instance(), new LogDebug("An attempt was made to access the admin panel but failed."));
             CookieProxy.Instance().SetValue("LoginMessage", "Not Authorized, please login with correct credentials".ToString(), DateTime.Now.AddDays(2));
             Response.Redirect("/signout.aspx", false);
         }
     }
     catch (NullReferenceException)
     {
         Logger.Instance().Log(Warn.Instance(), new LogDebug("Unable to authenticate the token, token invalid or not found"));
         CookieProxy.Instance().SetValue("LoginMessage", "Unable to authenticate, please login with correct credentails.".ToString(), DateTime.Now.AddDays(2));
         Response.Redirect("/signout.aspx", false);
     }
     catch (Exception ex)
     {
         Logger.Instance().Log(Warn.Instance(), ex);
         if (CookieProxy.Instance().HasKey("LoginMessage") == false)
         {
             CookieProxy.Instance().SetValue("LoginMessage", "An error occured while authenticating, this event has been logged".ToString(), DateTime.Now.AddDays(2));
         }
         Response.Redirect("/signout.aspx");
     }
 }
Exemplo n.º 19
0
        public DataSet GetUserToken()
        {
            Source = "sp_authToken";
            string Token = UserProfileObj.GetToken();

            try
            {
                object[] parameters =
                {
                    new MySqlParameter("@paramToken", Token)
                };
                DataSet output = Commands.ExecuteQuery(Source, CommandType.StoredProcedure, parameters);
                return(output);
            }
            catch (Exception ex)
            {
                Logger.Instance().Log(Warn.Instance(), ex);
                throw ex;
            }
        }
Exemplo n.º 20
0
        public DataSet GetHashedPassword()
        {
            Source = "sp_getSaltPass";
            String Email = UserProfileObj.GetEmail();

            try
            {
                object[] parameters =
                {
                    new MySqlParameter("@paramEmail", Email)
                };
                DataSet output = Commands.ExecuteQuery(Source, CommandType.StoredProcedure, parameters);
                return(output);
            }
            catch (Exception ex)
            {
                Logger.Instance().Log(Warn.Instance(), ex);
                throw ex;
            }
        }
Exemplo n.º 21
0
 protected void Btn_Update_maintenance_text_Click_Click(object sender, EventArgs e)
 {
     try
     {
         new SettingsFromDB().UpdateSettingsFromDB(new Settings("LOGIN_MAINTENANCE_MESSAGE", txt_Maintenance_text.Text.ToString()));
         TextStatus.Text      = "UPDATED";
         TextStatus.BackColor = System.Drawing.Color.FromArgb(Int32.Parse("26A69A", NumberStyles.HexNumber));
         TextStatus.ForeColor = System.Drawing.Color.White;
         TextStatus.Visible   = true;
         Logger.Instance().Log(Info.Instance(), new WarnDebug(new NormalUserTemplate().FetchParticularProfile(new UserProfile(CookieProxy.Instance().GetValue("t").ToString())).GetEmail() + " changed maintance login text to : " + txt_Maintenance_text.Text.ToString()));
     }
     catch (Exception ex)
     {
         Logger.Instance().Log(Warn.Instance(), ex);
         TextStatus.Visible   = true;
         TextStatus.Text      = ex.Message.ToString();
         TextStatus.BackColor = System.Drawing.Color.FromArgb(Int32.Parse("FF6E6E", NumberStyles.HexNumber));
         TextStatus.ForeColor = System.Drawing.Color.White;
     }
 }
Exemplo n.º 22
0
 public override APIResponse Insert(ICardDetails CardDetailsObj)
 {
     try
     {
         AESObj.GenerateKey();
         CardDetailsObj.SetIV(AESObj.GetIV());
         CardDetailsObj.SetDecryptionKey(AESObj.GetKey());
         CardDetailsObj.SetName(AESObj.Encrypt(CardDetailsObj.GetName()));
         CardDetailsObj.SetCardNumber(AESObj.Encrypt(CardDetailsObj.GetCardNumber()));
         CardDetailsObj.SetExpiryMonth(AESObj.Encrypt(CardDetailsObj.GetExpiryMonth()));
         CardDetailsObj.SetExpiryYear(AESObj.Encrypt(CardDetailsObj.GetExpiryYear()));
         CardDetailsObj.SetCvv(AESObj.Encrypt(CardDetailsObj.GetCvv()));
         bool Response = new Security(UserProfileObj).AuthenticateUser();
         if (Response == true)
         {
             if (0 == CardDetailsDataLayerObj.Insert(CardDetailsObj))
             {
                 return(APIResponse.NOT_OK);
             }
             else
             {
                 return(APIResponse.OK);
             }
         }
         else
         {
             return(APIResponse.NOT_AUTHENTICATED);
         }
     }
     catch (NullReferenceException nex)
     {
         Logger.Instance().Log(Warn.Instance(), new LogInfo("Received null reference while adding card (Routine : AuthenticateUser), might be token manipulation. Check token : " + UserProfileObj.GetToken()));
         throw nex;
     }
     catch (Exception ex)
     {
         Logger.Instance().Log(Fatal.Instance(), ex);
         throw ex;
     }
 }
Exemplo n.º 23
0
 public override List <ICardDetails> Select()
 {
     try
     {
         bool Response = new Security(UserProfileObj).AuthenticateUser();
         if (Response == true)
         {
             List <ICardDetails> DecryptedCardDetailsList = new List <ICardDetails>();
             foreach (ICardDetails EncryptedCardObj in CardDetailsDataLayerObj.Select())
             {
                 ICardDetails DecryptedCardDetails = new CardDetails();
                 AESObj.SetIV(EncryptedCardObj.GetIV());
                 AESObj.SetKey(EncryptedCardObj.GetDecryptionKey());
                 DecryptedCardDetails.SetCardID(EncryptedCardObj.GetCardID());
                 DecryptedCardDetails.SetName(AESObj.Decrypt(EncryptedCardObj.GetName()));
                 DecryptedCardDetails.SetCardNumber(AESObj.Decrypt(EncryptedCardObj.GetCardNumber()).ToString());
                 DecryptedCardDetails.SetExpiryMonth(AESObj.Decrypt(EncryptedCardObj.GetExpiryMonth()));
                 DecryptedCardDetails.SetExpiryYear(AESObj.Decrypt(EncryptedCardObj.GetExpiryYear()));
                 DecryptedCardDetails.SetCvv(AESObj.Decrypt(EncryptedCardObj.GetCvv()));
                 DecryptedCardDetailsList.Add(DecryptedCardDetails);
             }
             return(DecryptedCardDetailsList);
         }
         else
         {
             return(null);
         }
     }
     catch (NullReferenceException nex)
     {
         Logger.Instance().Log(Warn.Instance(), new LogInfo("Received null reference while fetching card details (Routine : AuthenticateUser), might be token manipulation. Check token : " + UserProfileObj.GetToken()));
         throw nex;
     }
     catch (Exception ex)
     {
         Logger.Instance().Log(Fatal.Instance(), ex);
         throw ex;
     }
 }
Exemplo n.º 24
0
        public override APIResponse Add()
        {
            Source = "sp_registerUser";
            try
            {
                string FirstName      = UserProfileObj.GetFirstName();
                string LastName       = UserProfileObj.GetLastName();
                string Password       = UserProfileObj.GetPassword();
                string HashedPassword = UserProfileObj.GetHashedPassword();
                string Token          = UserProfileObj.GetToken();
                string RoleType       = UserProfileObj.GetRoleType();
                string Email          = UserProfileObj.GetEmail();
                string Salt           = UserProfileObj.GetSalt();

                object[] parameters =
                {
                    new MySqlParameter("@paramFirstName", FirstName),
                    new MySqlParameter("@paramLastName",  LastName),
                    new MySqlParameter("@paramEmail",     Email),
                    new MySqlParameter("@paramPwd",       HashedPassword),
                    new MySqlParameter("@paramSalt",      Salt),
                    new MySqlParameter("@paramToken",     Token),
                    new MySqlParameter("@paramRoleType",  RoleType)
                };
                DataSet sqlOutput = Commands.ExecuteQuery(Source, CommandType.StoredProcedure, parameters);
                // now check the status
                return(APIResponse.OK);
            }
            catch (MySqlException mse)
            {
                Logger.Instance().Log(Info.Instance(), mse);
                throw mse;
            }
            catch (Exception ex)
            {
                Logger.Instance().Log(Warn.Instance(), ex);
                throw ex;
            }
        }
Exemplo n.º 25
0
 public override APIResponse Delete(ICardDetails CardDetailsObj)
 {
     try
     {
         bool AuthUserResponseObj = new Security(UserProfileObj).AuthenticateUser();
         if (AuthUserResponseObj == true)
         {
             if (0 == CardDetailsDataLayerObj.Delete(CardDetailsObj))
             {
                 return(APIResponse.NOT_OK);
             }
             else
             {
                 return(APIResponse.OK);
             }
         }
         else
         {
             return(APIResponse.NOT_AUTHENTICATED);
         }
     }
     catch (NullReferenceException nex)
     {
         Logger.Instance().Log(Warn.Instance(), new LogInfo("Received null reference while removing card (Routine : AuthenticateUser), might be token manipulation. Check token : " + UserProfileObj.GetToken()));
         throw nex;
     }
     catch (MySqlException mse)
     {
         Logger.Instance().Log(Warn.Instance(), mse);
         throw mse;
     }
     catch (Exception ex)
     {
         Logger.Instance().Log(Fatal.Instance(), ex);
         throw ex;
     }
 }
 public override APIResponse Delete(IStores StoreObj)
 {
     try
     {
         bool Response = new Security(UserProfileObj).AuthenticateAdmin();
         if (Response == true)
         {
             if (0 == StoresTemplateObj.Delete(StoreObj))
             {
                 return(APIResponse.NOT_OK);
             }
             else
             {
                 return(APIResponse.OK);
             }
         }
         else
         {
             return(APIResponse.NOT_AUTHENTICATED);
         }
     }
     catch (NullReferenceException nex)
     {
         Logger.Instance().Log(Warn.Instance(), new LogInfo("Received null reference while removing store (Routine : AuthenticateAdmin), might be token manipulation. Check token : " + UserProfileObj.GetToken()));
         throw nex;
     }
     catch (MySqlException mse)
     {
         Logger.Instance().Log(Warn.Instance(), mse);
         throw mse;
     }
     catch (Exception ex)
     {
         Logger.Instance().Log(Fatal.Instance(), ex);
         throw ex;
     }
 }
Exemplo n.º 27
0
    protected void Page_Load(object sender, EventArgs e)
    {
        bool IsAuthenticated = false;

        try
        {
            if (CookieProxy.Instance().HasKey("t"))
            {
                IUserProfile UserProfileObj = new UserProfile(CookieProxy.Instance().GetValue("t").ToString());
                if (new Security(UserProfileObj).AuthenticateUser() == false)
                {
                    IsAuthenticated = false;
                }
                else
                {
                    IsAuthenticated = true;
                }
            }
            else
            {
                IsAuthenticated = false;
            }
        }
        catch (Exception ex)
        {
            Logger.Instance().Log(Warn.Instance(), ex);
            IsAuthenticated = false;
        }
        finally
        {
            var Output = new
            {
                IsAuthenticated
            };
            Response.Write(new JavaScriptSerializer().Serialize(Output));
        }
    }
Exemplo n.º 28
0
    protected void Page_Load(object sender, EventArgs e)
    {
        APIResponse ResponseENUM   = APIResponse.NOT_OK;
        string      ResponseString = "";

        try
        {
            Cart CartObj = null;
            if (CookieProxy.Instance().HasKey("Cart"))
            {
                int PBSId = int.Parse(Request.Form["pbsid"].ToString());
                CartObj = new JavaScriptSerializer().Deserialize <Cart>(CookieProxy.Instance().GetValue("Cart").ToString());
                bool AlreadyHasProductInCart = false;
                foreach (CartItems Cart in CartObj.CartItems)
                {
                    if (Cart.ProductObj.pbsID == PBSId)
                    {
                        ResponseENUM            = APIResponse.NOT_OK;
                        ResponseString          = "PRODUCT ALREADY ADDED TO CART, PLEASE MODIFY THE QUANTITY";
                        AlreadyHasProductInCart = true;
                        break;
                    }
                }
                if (AlreadyHasProductInCart == false)
                {
                    ProductByStore PBSPbj = new ProductByStore();
                    PBSPbj.SetProductByStoreID(PBSId);
                    CartItems CartItemsObj = new CartItems
                    {
                        HasQuantity = true,
                        ProductObj  = new ProductByStoreBusinessLayerTemplate().Select(PBSPbj)
                    };
                    // reset the quantity to 1, we want the user quantity not the product quantity
                    CartItemsObj.ProductObj.Quantity = 1;
                    CartObj.CartItems.Add(CartItemsObj);
                    CookieProxy.Instance().SetValue("Cart", new JavaScriptSerializer().Serialize(CartObj), DateTime.Now.AddDays(5));
                    ResponseENUM   = APIResponse.OK;
                    ResponseString = "SUCCESS";
                }
            }
            else
            {
                CartObj = new Cart
                {
                    CartItems = new List <CartItems>()
                };
                int       PBSId        = int.Parse(Request.Form["pbsid"].ToString());
                CartItems CartItemsObj = new CartItems
                {
                    HasQuantity = true,
                    ProductObj  = new ProductByStoreBusinessLayerTemplate().Select(new ProductByStore()
                    {
                        ProductByStoreID = PBSId
                    })
                };
                // reset the quantity to 1, we want the user quantity (user has initially selected the quantity) not the product quantity
                CartItemsObj.ProductObj.Quantity = 1;
                CartObj.CartItems.Add(CartItemsObj);
                CookieProxy.Instance().SetValue("Cart", new JavaScriptSerializer().Serialize(CartObj), DateTime.Now.AddDays(5));
                ResponseENUM   = APIResponse.OK;
                ResponseString = "SUCCESS";
            }
        }
        catch (Exception ex)
        {
            Logger.Instance().Log(Warn.Instance(), ex);
            ResponseENUM   = APIResponse.NOT_OK;
            ResponseString = "ERROR";
        }
        finally
        {
            var ReturnObj = new
            {
                Response = ResponseENUM.ToString(),
                ResponseString
            };
            Response.Write(new JavaScriptSerializer().Serialize(ReturnObj));
        }
    }
Exemplo n.º 29
0
    protected void Page_Load(object sender, EventArgs e)
    {
        APIResponse ApiResponse = APIResponse.NOT_OK;
        int         Quantity    = 0;
        Cart        CartObj     = new Cart();

        try
        {
            if (CookieProxy.Instance().HasKey("Cart"))
            {
                CartObj = new JavaScriptSerializer().Deserialize <Cart>(CookieProxy.Instance().GetValue("Cart").ToString());
                foreach (CartItems Items in CartObj.CartItems)
                {
                    IProductByStore PBSObj = new ProductByStore();
                    PBSObj.SetProductByStoreID(Items.ProductObj.pbsID);
                    Products DBProductQty = new ProductByStoreBusinessLayerTemplate().Select(PBSObj);
                    if (GetMaxQty < DBProductQty.Quantity)
                    {
                        Items.DBQuantity = GetMaxQty;
                    }
                    else
                    {
                        Items.DBQuantity = DBProductQty.Quantity;
                    }
                    if (Items.ProductObj.Quantity < 0)
                    {
                        CartObj.HasValidationErrors = true;
                        Items.ProductObj.Quantity   = -1;
                        Items.HasQuantity           = false;
                    }
                    else
                    if (DBProductQty.Quantity < Items.ProductObj.Quantity && Items.ProductObj.Quantity <= 0)
                    {
                        CartObj.HasValidationErrors = true;
                        Items.ProductObj.Quantity   = -1;
                        Items.HasQuantity           = false;
                    }
                    else if (DBProductQty.Quantity < Items.ProductObj.Quantity)
                    {
                        CartObj.HasValidationErrors = true;
                        Items.HasQuantity           = false;
                    }
                    Quantity = CartObj.CartItems.Count;
                }
            }
            ApiResponse = APIResponse.OK;
        }
        catch (Exception ex)
        {
            Logger.Instance().Log(Warn.Instance(), ex);
            ApiResponse = APIResponse.NOT_OK;
        }
        finally
        {
            var Cart = new
            {
                Response = ApiResponse.ToString(),
                Quantity,
                Cart = new JavaScriptSerializer().Serialize(CartObj)
            };
            Response.Write(new JavaScriptSerializer().Serialize(Cart));
        }
    }
Exemplo n.º 30
0
    protected void Page_Load(object sender, EventArgs e)
    {
        APIResponse ResponseENUM   = APIResponse.NOT_OK;
        string      ResponseString = "";

        try
        {
            Cart CartObj = null;
            if (CookieProxy.Instance().HasKey("Cart"))
            {
                int PBSId = int.Parse(Request.Form["pbsid"].ToString());
                CartObj = new JavaScriptSerializer().Deserialize <Cart>(CookieProxy.Instance().GetValue("Cart").ToString());
                int Iterator = 0;
                foreach (CartItems Cart in CartObj.CartItems)
                {
                    if (Cart.ProductObj.pbsID == PBSId)
                    {
                        int             Quantity = int.Parse(Request.Form["qty"].ToString());
                        IProductByStore PBSObj   = new ProductByStore();
                        PBSObj.SetProductByStoreID(PBSId);
                        Products DBProductQty = new ProductByStoreBusinessLayerTemplate().Select(PBSObj);
                        if (Quantity <= DBProductQty.Quantity)
                        {
                            Cart.ProductObj.Quantity = Quantity;
                            ResponseENUM             = APIResponse.OK;
                            ResponseString           = "SUCCESS";
                        }
                        else
                        {
                            Cart.ProductObj.Quantity = Quantity;
                            ResponseENUM             = APIResponse.NOT_OK;
                            ResponseString           = "CURRENT QUANTITY NOT AVAILABLE, PLEASE REFRESH THE PAGE TO SEE UPDATED QUANTITY";
                        }
                        break;
                    }
                    Iterator += 1;
                }
                CookieProxy.Instance().SetValue("Cart", new JavaScriptSerializer().Serialize(CartObj), DateTime.Now.AddDays(5));
            }
            else
            {
                ResponseENUM   = APIResponse.NOT_OK;
                ResponseString = "AN ERROR OCCURED WHILE READING THE CART, PLEASE CLEAR YOUR COOKIES";
            }
        }
        catch (Exception ex)
        {
            Logger.Instance().Log(Warn.Instance(), ex);
            ResponseENUM   = APIResponse.NOT_OK;
            ResponseString = "AN ERROR OCCURED WHILE READING THE CART, PLEASE CLEAR YOUR COOKIES";
        }
        finally
        {
            var ReturnObj = new
            {
                Response = ResponseENUM.ToString(),
                ResponseString
            };
            Response.Write(new JavaScriptSerializer().Serialize(ReturnObj));
        }
    }