Exemplo n.º 1
0
        public static void SendInvite(SessionCustomer Customer, string Url, string mailTo, string mailSubject, string message)
        {
            MailMessage mail = new MailMessage();
            mail.To.Add(new MailAddress(mailTo));
            mail.Subject = mailSubject;
            mail.IsBodyHtml = true;
            mail.Body = Transfomer.GenerateInviteMail(Customer, Url, message);
            mail.From = new MailAddress("*****@*****.**", "FZone");

            SmtpClient client = new SmtpClient();
            //client.EnableSsl = true;
            client.Timeout = 5000;
            client.Send(mail);
        }
Exemplo n.º 2
0
        protected void lnkRegister_Click(object sender, EventArgs e)
        {
            if (RouteData.Values["uid"] != null && RouteData.Values["pid"] != null)
            {
                string user = RouteData.Values["uid"].ToString();
                string pass = RouteData.Values["pid"].ToString();
                if (!String.IsNullOrWhiteSpace(user) && !String.IsNullOrWhiteSpace(pass))
                {
                    try
                    {
                        string clearUser = Encryption.Decrypt(user);
                        string clearPass = Encryption.Decrypt(pass);

                        if (ApplicationContext.Current.Customers.Validate(clearUser, clearPass))
                        {
                            string newPass =  FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, Configuration.PasswordHashMethod).ToLower();
                            ApplicationContext.Current.Customers.ChangePassword(clearUser, clearPass, newPass);

                            CurrentCustomer = new SessionCustomer(ApplicationContext.Current.Customers.GetByEmail(clearUser));

                            Response.Cookies.Remove(FormsAuthentication.FormsCookieName);
                            FormsAuthentication.SetAuthCookie(clearUser, false);

                            Response.Redirect("/home");
                        }
                    }
                    catch (System.Threading.ThreadAbortException ex)
                    {
                    }
                    catch (Exception ex)
                    {
                        Log(ex, ex.Message, ex.StackTrace, "Password");
                        lblResult.Text = Resources.Lang.ErrorVerifiedLabel;
                    }
                }
            }
        }
Exemplo n.º 3
0
        public static string GenerateInviteMail(SessionCustomer Customer, string Url, string message)
        {
            // Input data will be defined in this XML document.
            XmlDocument xmlDoc = new XmlDocument();

            XmlElement xmlRoot;
            XmlNode xmlNode, xmlNode2, xmlChild2, xmlChild, xmlNode3;

            xmlDoc.LoadXml(
            "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
            "<Root>" +
            "<Customer/>" +
            "<Message/>" +
            "<Url/>" +
            "<Campaigns/>" +
            "</Root>");

            // Set the values of the XML nodes that will be used by XSLT.
            xmlRoot = xmlDoc.DocumentElement;

            xmlNode = xmlRoot.SelectSingleNode("/Root/Customer");


            xmlChild2 = xmlDoc.CreateNode(XmlNodeType.Element, "Name", null);
            xmlChild2.InnerText = Customer.FullName;
            xmlNode.AppendChild(xmlChild2);


            xmlNode = xmlRoot.SelectSingleNode("/Root/Url");
            xmlNode.InnerText = Url;

            xmlNode2 = xmlRoot.SelectSingleNode("/Root/Message");
            xmlNode2.InnerText = message;

            xmlNode3 = xmlRoot.SelectSingleNode("/Root/Campaigns");

            CAMPAIGN searchCampaign = new CAMPAIGN() { Active = true, Approved = true };
            int TotalCampaignsForToday;
            List<CAMPAIGN> campaigns = ApplicationContext.Current.Campaigns.Search(searchCampaign, 100, 0, out TotalCampaignsForToday, "StartDate", BL.Util.SortDirection.Descending);


            foreach (CAMPAIGN campaign in campaigns)
            {
                xmlChild = xmlDoc.CreateNode(XmlNodeType.Element, "Campaign", null);

                // title
                xmlChild2 = xmlDoc.CreateNode(XmlNodeType.Element, "Title", null);
                xmlChild2.InnerText = campaign.BrandName;
                xmlChild.AppendChild(xmlChild2);

                // from
                //xmlChild2 = xmlDoc.CreateNode(XmlNodeType.Element, "From", null);
                //xmlChild2.InnerText = campaign.StartDate.ToString("dd/MM/yyyy");
                //xmlChild.AppendChild(xmlChild2);

                // to
                xmlChild2 = xmlDoc.CreateNode(XmlNodeType.Element, "To", null);
                xmlChild2.InnerText = campaign.EndDate.ToString("dd/MM/yyyy");
                xmlChild.AppendChild(xmlChild2);

                // image
                xmlChild2 = xmlDoc.CreateNode(XmlNodeType.Element, "Image", null);
                xmlChild2.InnerText = Configuration.DeploymentURL + Configuration.ImagesUploadPath + campaign.ImageHome;
                xmlChild.AppendChild(xmlChild2);

                // Url
                //xmlChild2 = xmlDoc.CreateNode(XmlNodeType.Element, "Url", null);
                //xmlChild2.InnerText = Configuration.DeploymentURL + "/campaign/" + Encryption.Encrypt(campaign.ID.ToString());
                //xmlChild.AppendChild(xmlChild2);

                xmlNode3.AppendChild(xmlChild);
            }

            // This is our XSL template.
            XslCompiledTransform xslDoc = new XslCompiledTransform();
            xslDoc.Load(@Configuration.InviteTemplate);

            XsltArgumentList xslArgs = new XsltArgumentList();
            StringWriter writer = new StringWriter();

            // Merge XSLT document with data XML document 
            // (writer will hold resulted transformation).
            xslDoc.Transform(xmlDoc, xslArgs, writer);

            return writer.ToString();
        }
        public override bool ValidateUser(string username, string password)
        {
            if (String.IsNullOrWhiteSpace(password))
            {
                return false;
            }
            password = FormsAuthentication.HashPasswordForStoringInConfigFile(password, Configuration.PasswordHashMethod).ToLower();
            var ctx = ApplicationContext.Current.Customers;
            bool valid = ctx.Validate(username, password);

            if (valid)
            {
                var customer = ApplicationContext.Current.Customers.GetByEmail(username);
                SessionCustomer sC = new SessionCustomer(customer);
                System.Web.HttpContext.Current.Session["CurrentCustomer"] = sC;
            }

            return valid;
        }
        private void SendInvite(SessionCustomer customer, int idInvi, string mailTo, string fullName)
        {
            string custEncId = Encryption.Encrypt(customer.Id.ToString());
            string invEncId = Encryption.Encrypt(idInvi.ToString());
            string sub = string.Format("{0} {1}", fullName, Lang.InviteSubjectMailLabel);
            string url = string.Format("{0}/register/{1}/{2}", Configuration.DeploymentURL, custEncId, invEncId);

            BL.Util.Mailer.SendInvite(customer, url, mailTo, sub, Lang.InviteBody2MailLabel);
        }
Exemplo n.º 6
0
        protected bool facebookAuthenticate()
        {
            try
            {
                if (!String.IsNullOrWhiteSpace(Request["accessToken"]))
                {
                    FacebookClient client = new FacebookClient(Request["accessToken"]);
                    dynamic person = client.Get("me");

                    // data returned from facebook
                    if (person != null)
                    {
                        CUSTOMER customer = new CUSTOMER(person);
                        CUSTOMER fbCustomer = ApplicationContext.Current.Customers.GetByFBId(person.id);
                        // user not found in db with this fb id
                        if (fbCustomer == null)
                        {
                            CUSTOMER myCustomer = ApplicationContext.Current.Customers.GetByEmail(customer.Email);
                            // user not present with this fb id nor with this email
                            if (myCustomer == null)
                            {
                                customer.RegistrationDate = DateTime.Today;
                                ApplicationContext.Current.Customers.Insert(customer);
                            }
                            else
                            {
                                myCustomer.Email = customer.Email;
                                myCustomer.Name = customer.Name;
                                myCustomer.Surname = customer.Surname;
                                myCustomer.Gender = customer.Gender;
                                myCustomer.FBId = customer.FBId;
                                myCustomer.BirthDate = customer.BirthDate;
                                ApplicationContext.Current.Customers.Update(myCustomer, false);
                                customer.ID = myCustomer.ID;
                            }
                        }
                        else
                        {
                            // user already saved as fb user, updating email if necessary
                            if (fbCustomer.Email != customer.Email)
                            {
                                fbCustomer.Email = customer.Email;
                                ApplicationContext.Current.Customers.Update(fbCustomer, false);
                            }
                            customer.ID = fbCustomer.ID;
                        }

                        CurrentCustomer = new SessionCustomer(customer);
                        Session["accessToken"] = Request["accessToken"];
                        Response.Cookies.Remove(FormsAuthentication.FormsCookieName);
                        FormsAuthentication.SetAuthCookie(customer.Email, false);
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                Log(ex, ex.Message, ex.StackTrace, "BasePage - FacebookAuth");
                return false;
            }
        }
Exemplo n.º 7
0
        protected void lnkRegister_Click(object sender, EventArgs e)
        {
            Page.Validate();
            if (Page.IsValid)
            {
                CUSTOMER customer = new CUSTOMER();
                if (String.IsNullOrWhiteSpace(txtEmail.Text) || !valEmail.IsValid)
                {
                    litError.Text = "Email " + Resources.Lang.NotValidLabel + ".";
                    return;
                }

                if (!chkGeneralTerms.Checked)
                {
                    litError.Text = Resources.Lang.PleaseAcceptLabel;
                    return;
                }
                int invCust = 0;
                //Check if have cookie. Yes ? Add id of customer whu invited : nothing
                if (Request.Cookies["InvBy"] != null)
                {
                    if (Request.Cookies["InvBy"]["IdCust"] != null)
                    {
                        if (int.TryParse(Request.Cookies["InvBy"]["IdCust"], out invCust))
                        {
                            customer.InvitedFrom = invCust;
                        }
                    }
                }

                customer.Email = txtEmail.Text;

                try
                {
                    if (ApplicationContext.Current.Customers.GetByEmail(txtEmail.Text) != null)
                    {
                        litError.Text = Resources.Lang.AlreadyRegisteredMailLabel;
                        return;
                    }

                    customer.Name = txtName.Text;
                    customer.Surname = txtSurname.Text;
                    DateTime date = new DateTime();
                    IFormatProvider formatProvider = new CultureInfo("it-IT");

                    if (!String.IsNullOrWhiteSpace(txtBirthday.Text))
                    {
                        DateTime.TryParse(txtBirthday.Text, formatProvider, DateTimeStyles.AdjustToUniversal, out date);

                    }
                    customer.BirthDate = date;
                    customer.Password = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, Configuration.PasswordHashMethod).ToLower();
                    customer.Active = true;
                    customer.RegistrationDate = DateTime.Now;
                    customer.Newsletter = true;
                    customer.Gender = ddlGender.SelectedValue;
                    customer.Telephone = txtPhone.Text;
                    customer.Mobile = txtMobile.Text;

                    //If cookie exist ? delte && set InviteTabele a True : nothing
                    if (Request.Cookies["InvBy"] != null)
                    {
                        if (Request.Cookies["InvBy"]["InvId"] != null)
                        {
                            int idInv;
                            if (int.TryParse(Request.Cookies["InvBy"]["InvId"], out idInv))
                            {
                                var invitation = ApplicationContext.Current.Invitations.GetById(idInv);
                                if (invitation.InvitedMail == txtEmail.Text)
                                {
                                    invitation.Registered = true;
                                    invitation.RegistrationDate = DateTime.Now;
                                    //ApplicationContext.Current.Invitations.Update(invitation);
                                    //No need to do an update (i.e. attach and save context), object already attached
                                }
                                // TODO Check logic
                                // case when invitation id is specified, but user is registering another email
                                else if (invCust != 0)
                                {
                                    INVITATION invt = new INVITATION() { CustomerID = invCust, InvitedMail = txtEmail.Text, Registered = true, RegistrationDate = DateTime.Now, IP = Request.UserHostAddress };
                                    ApplicationContext.Current.Invitations.Insert(invt);
                                }
                            }
                            else
                            {
                                //case when invitation id is not specified, user may be referred in another way
                                INVITATION invt = new INVITATION() { CustomerID = invCust, InvitedMail = txtEmail.Text, Registered = true, RegistrationDate = DateTime.Now, IP = Request.UserHostAddress };
                                ApplicationContext.Current.Invitations.Insert(invt);
                            }
                        }
                        HttpCookie myCookie = new HttpCookie("InvBy");
                        myCookie.Expires = DateTime.Now.AddDays(-1d);
                        Response.Cookies.Add(myCookie);
                    }

                    ApplicationContext.Current.Customers.Insert(customer);

                    CurrentCustomer = new SessionCustomer(customer);

                    Response.Cookies.Remove(FormsAuthentication.FormsCookieName);
                    FormsAuthentication.SetAuthCookie(customer.Email, false);

                    Response.Redirect("/home");

                }
                catch (System.Threading.ThreadAbortException ex)
                {
                }
                catch (Exception ex)
                {
                    //TODO log ex
                    Log(ex, ex.Message, ex.StackTrace, "Register");
                    litError.Text = Resources.Lang.ErrorVerifiedLabel;
                }
            }
        }