Ejemplo n.º 1
0
        protected void btnCreateAcc_OnClick(object sender, EventArgs e)
        {
            string orgname        = txtOrgName.Text.Trim();
            string orgmail        = txtOrgEmail.Text.Trim();
            string userNm         = txtOrgUsername.Text.Trim();
            string passMe1        = txtPasswordOne.Text.Trim();
            string passMe         = txtPassConfir.Text.Trim();
            string activationCode = Guid.NewGuid().ToString();

            if (passMe1 != passMe)
            {
                lblError.Text         = "Password Mismatch, try again!";
                txtPassword1.Text     = "";
                txtPassConfirmed.Text = "";
            }
            else
            {
                try
                {
                    var     credentials = new NetworkCredential(ConfigurationManager.AppSettings["W_USER"], ConfigurationManager.AppSettings["W_PWD"], ConfigurationManager.AppSettings["DOMAIN"]);
                    Portals sup         = new Portals();
                    sup.Credentials     = credentials;
                    sup.PreAuthenticate = true;
                    sup.FnAddGrantee(orgname, orgmail, userNm, EncryptP(passMe), activationCode);

                    KCDFAlert.ShowAlert("Your account succcessfully created, proceed to activation from your email");

                    InsertToActivationDB(userNm, activationCode);

                    using (MailMessage mm = new MailMessage("*****@*****.**", orgmail))
                    {
                        string ActivationUrl = string.Empty;
                        ActivationUrl =
                            System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority)
                            + "/Account/Activated_Grantees.aspx?ActivationCode=" + activationCode + "&username="******"";

                        //Click here to activate your account
                        //var contactUsUrl = Page.ResolveClientUrl("~/Account/Register.aspx");

                        mm.Subject = "KCDF Account Activation";
                        string body = "Hello " + userNm + ",";
                        body += "<br /><br />Please click the following link to activate your account";

                        // body += "<br /><a href = '" + Request.Url.AbsoluteUri.Replace("/Account/Register.aspx", "/Account/Activated.aspx?ActivationCode=" + activationCode) + "'>Click here to activate your account.</a>";

                        body         += "<br />" + ActivationUrl + "";
                        body         += "<br /><br />Thanks";
                        mm.Body       = body;
                        mm.IsBodyHtml = true;
                        SmtpClient smtp = new SmtpClient();
                        smtp.Host      = "smtp.gmail.com";
                        smtp.EnableSsl = true;
                        NetworkCredential NetworkCred = new NetworkCredential("*****@*****.**", "Kcdfportal@4321*~");
                        smtp.UseDefaultCredentials = true;
                        smtp.Credentials           = NetworkCred;
                        smtp.Port = 587;
                        smtp.Send(mm);

                        KCDFAlert.ShowAlert("Activation link has been send to your email");
                    }
                }
                catch (Exception ex)
                {
                    lblError.Text = ex.Message;
                    return;
                }
            }
        }