예제 #1
0
        protected void CreateAConsultant()
        {
            string fullname       = txtConsName.Text.Trim();
            string email          = txtConsEmail.Text.Trim();
            string username       = txtConsUsername.Text.Trim();
            string passW1         = txtConsPass1.Text.Trim();
            string confirPwd      = txtConsPass2.Text.Trim();
            string activationCode = Guid.NewGuid().ToString();
            string regNo          = txtConsIDReg.Text.Trim();


            if (string.IsNullOrWhiteSpace(fullname) ||
                string.IsNullOrWhiteSpace(regNo) ||
                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.FnCreateConsultant(fullname, email, regNo, 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/Activate_Consultant.aspx?ActivationCode=" + activationCode + "&username="******"";

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

                            mm.Subject = "KCDF Consultant 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;
                    return;
                }
            }
        }