示例#1
0
        protected void GetGranteeAccount()
        {
            string email          = txtExEmail.Text.Trim();
            string username       = txtExUsername.Text.Trim();
            string passW1         = txtXPass1.Text.Trim();
            string confirPwd      = txtXPass2.Text.Trim();
            string activationCode = Guid.NewGuid().ToString();
            string regNo          = txtConsIDReg.Text.Trim();


            if (string.IsNullOrWhiteSpace(email) ||
                string.IsNullOrWhiteSpace(username) ||
                string.IsNullOrWhiteSpace(passW1) ||
                string.IsNullOrWhiteSpace(confirPwd))
            {
                lblError.Text = "Please fill all the empty required fields!";
                return;
            }
            if (passW1 != confirPwd)
            {
                lblError.Text = "Password Mismatch, try again!";
                KCDFAlert.ShowAlert("Password Mismatch, try again!");
                txtPassword1.Text     = "";
                txtPassConfirmed.Text = "";
                return;
            }
            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;
                    if (sup.FnAddXstingGrantee(email, username, EncryptP(confirPwd), activationCode))
                    {
                        this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "getmeTohomeConfirm()", true);

                        //call goback to login to load Default page for user
                        InsertToActivationDB(username, activationCode);

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

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

                            mm.Subject = "KCDF Grantee Account Activation";
                            string body = "Hello " + username + ",";
                            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;
                    KCDFAlert.ShowAlert(ex.Message);
                    return;
                }
            }
        }