protected void btn_generatekey_Click(object sender, EventArgs e)
 {
     try
     {
         string email = txt_email.Text.ToString();
         Guid   userid;
         string username = "";
         Guid   key;
         key = Guid.NewGuid();
         //fetching userid from database
         System.Web.Security.MembershipUser user;
         username = System.Web.Security.Membership.GetUserNameByEmail(email);
         user     = System.Web.Security.Membership.GetUser(username);
         userid   = (Guid)user.ProviderUserKey;
         Account act = new Account();
         if (System.Web.Security.Membership.ValidateUser(username, txt_password.Text))
         {
             if (act.SaveActivationKey(userid, key))
             {
                 var    siteRoot       = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/");
                 string activate_url   = siteRoot + "ActivateAccount.aspx?key=" + key;
                 string site_url       = siteRoot;
                 string web_design_url = siteRoot + "web-design/create.aspx";
                 string hosting_url    = siteRoot + "hosting/main.aspx";
                 string help           = siteRoot + "contact-us.html";
                 string address        = "Balaganj, Lucknow Up 226003</br> Web Creation Inc.";
                 WMail  mail           = new WMail();
                 if (mail.Send(email, "", "", username, txt_password.Text, activate_url, site_url, web_design_url, hosting_url, help, address))
                 {
                     lbl_msg.ForeColor = System.Drawing.Color.Green;
                     lbl_msg.Text      = "Activation key has been sent again. Please check your email!";
                 }
             }
         }
         else
         {
             lbl_msg.ForeColor = System.Drawing.Color.Red;
             lbl_msg.Text      = "Please enter correct password!";
         }
     }
     catch
     {
         lbl_msg.ForeColor = System.Drawing.Color.Red;
         lbl_msg.Text      = "Error.";
     }
 }
예제 #2
0
    public void Save_Update_Data()
    {
        Guid key;

        key = Guid.NewGuid();   // generating key for the users

        string username  = txt_username.Text.Trim();
        string firstname = txt_firstname.Text.Trim();
        string lastname  = txt_lastname.Text.Trim();
        string address   = txt_address.Text.Trim();
        string city      = txt_city.Text.Trim();
        string state     = txt_state.Text.Trim();
        string country   = txt_country.Text.Trim();
        //  string password = txt_password.Text;
        string password = Guid.NewGuid().ToString("d").Substring(1, 6);
        string email    = txt_email.Text;
        Guid   creatorid;

        System.Web.Security.MembershipUser mu;
        mu        = System.Web.Security.Membership.GetUser();
        creatorid = (Guid)mu.ProviderUserKey;
        // initialise data class
        MembershipCreateStatus createStatus;
        MembershipUser         user = System.Web.Security.Membership.CreateUser(username, password, email, "question", "answer", true, out createStatus);

        if (MembershipCreateStatus.Success == createStatus)
        {
            if (admin.SaveSiteUsers(username, firstname, lastname, email, address, city, state, country, Session[Constants.Session.USERNAME].ToString(), creatorid, ""))
            {
                Guid userid;
                System.Web.Security.MembershipUser mu1;
                mu1    = System.Web.Security.Membership.GetUser(username);
                userid = (Guid)mu1.ProviderUserKey;
                Account act = new Account();
                if (act.SaveActivationKey(userid, key))
                {
                    //  Hash_Pass hash = new Hash_Pass();
                    // string hash_pass = Hash_Pass.DESCryptoHelper.DESEncrypt(Tpassword.Text.Trim());
                    var    siteRoot        = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/");
                    string activate_url    = siteRoot + "ActivateAccount.aspx?key=" + key;
                    string site_url        = siteRoot;
                    string web_design_url  = siteRoot + "web-design/create.aspx";
                    string hosting_url     = siteRoot + "hosting/main.aspx";
                    string help            = siteRoot + "contact-us.html";
                    string company_address = "Balaganj, Lucknow Up 226003</br> Web Creation Inc.";
                    WMail  mail            = new WMail();
                    if (mail.Send(email, "", "", username, password, activate_url, site_url, web_design_url, hosting_url, help, company_address))
                    {
                        ClearText();        // clear the text.........
                        pnl_message.Visible = true;
                        div_msg.InnerHtml   = "Records inserted successfully! And password sent to the mail. Please check your mail.";
                    }
                    else
                    {
                        pnl_message.Visible       = true;
                        error.Attributes["class"] = "box box-danger";
                        div_msg.InnerHtml         = "Problem while sending mail.";
                    }
                }
            }
            else
            {
                pnl_message.Visible       = true;
                error.Attributes["class"] = "box box-danger";
                div_msg.InnerHtml         = "Could not created due to some errors...";
                System.Web.Security.Membership.DeleteUser(username);
            }
        }
        else
        {
            pnl_message.Visible       = true;
            error.Attributes["class"] = "box box-danger";
            div_msg.InnerHtml         = "Could not created due to " + createStatus;
        }
    }
예제 #3
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (CheckBox1.Checked == true)
        {
            Guid key;
            key = Guid.NewGuid();
            Message m = new Message();
            if (Session["captcha"].ToString() != txtCaptcha.Text)
            {
                pnl_msg.Controls.Add(m.Error("Invalid captcha!"));
            }
            else
            {
                string username  = Tname.Text.Trim();
                string user_name = ConfigurationManager.AppSettings["Administrator"];
                if (user_name == username)
                {
                    string[] roles = Roles.GetRolesForUser(username);
                    foreach (string role in roles)
                    {
                        if (role.Equals("Administrator"))
                        {
                            // Response.Redirect("admin/Home.aspx");
                            pnl_msg.Controls.Add(m.Error("This user already exists!"));
                        }
                    }
                    string[] admin_roles = Roles.GetAllRoles();
                    foreach (string role in admin_roles)
                    {
                        if (role.Equals("Administrator"))
                        {
                            Roles.AddUserToRole(username, "Administrator");
                            if (Register())
                            {
                                Guid userid;
                                System.Web.Security.MembershipUser mu;
                                mu     = System.Web.Security.Membership.GetUser(username);
                                userid = (Guid)mu.ProviderUserKey;
                                admin_management admin = new admin_management();

                                if (admin.AddAdmin(userid, username))
                                {
                                    string name  = Tname.Text.Trim();
                                    string email = Temail.Text.Trim();
                                    //string password = Tpassword.Text.Trim();
                                    string    gender   = Rblgender.Text.Trim();
                                    string    s_ques   = ddlsecurityQ.Text.Trim();
                                    string    s_ans    = TAnswer.Text.Trim();
                                    string    dob      = Tdob.Text.Trim();
                                    string    mobileno = Tmobile.Text.Trim();
                                    string    country  = ddlcountry.Text.Trim();
                                    string    city     = Tcity.Text.Trim();
                                    string    address  = Taddress.Text.Trim();
                                    datalayer c        = new datalayer();
                                    c.Registration(name, email, gender, s_ques, s_ans, dob, mobileno, country, city, address);
                                    Response.Redirect("admin/Home.aspx");
                                }
                                else
                                {
                                    pnl_msg.Controls.Add(m.Error("User can not created!"));
                                }
                            }
                        }
                        else
                        {
                            Roles.CreateRole("Administrator");
                            Roles.AddUserToRole(username, "Administrator");
                            if (Register())
                            {
                                Guid userid;
                                System.Web.Security.MembershipUser mu;
                                mu     = System.Web.Security.Membership.GetUser(username);
                                userid = (Guid)mu.ProviderUserKey;
                                admin_management admin = new admin_management();
                                if (admin.AddAdmin(userid, username))
                                {
                                    string name  = Tname.Text.Trim();
                                    string email = Temail.Text.Trim();
                                    //string password = Tpassword.Text.Trim();
                                    string    gender   = Rblgender.Text.Trim();
                                    string    s_ques   = ddlsecurityQ.Text.Trim();
                                    string    s_ans    = TAnswer.Text.Trim();
                                    string    dob      = Tdob.Text.Trim();
                                    string    mobileno = Tmobile.Text.Trim();
                                    string    country  = ddlcountry.Text.Trim();
                                    string    city     = Tcity.Text.Trim();
                                    string    address  = Taddress.Text.Trim();
                                    datalayer c        = new datalayer();
                                    c.Registration(name, email, gender, s_ques, s_ans, dob, mobileno, country, city, address);
                                    Response.Redirect("admin/Home.aspx");
                                }
                                else
                                {
                                    pnl_msg.Controls.Add(m.Error("User can not created!"));
                                }
                            }
                        }
                    }
                    Roles.CreateRole("Administrator");
                    Roles.AddUserToRole(username, "Administrator");
                    if (Register())
                    {
                        Guid userid;
                        System.Web.Security.MembershipUser mu;
                        mu     = System.Web.Security.Membership.GetUser(username);
                        userid = (Guid)mu.ProviderUserKey;
                        admin_management admin = new admin_management();
                        if (admin.AddAdmin(userid, username))
                        {
                            string name  = Tname.Text.Trim();
                            string email = Temail.Text.Trim();
                            //string password = Tpassword.Text.Trim();
                            string    gender   = Rblgender.Text.Trim();
                            string    s_ques   = ddlsecurityQ.Text.Trim();
                            string    s_ans    = TAnswer.Text.Trim();
                            string    dob      = Tdob.Text.Trim();
                            string    mobileno = Tmobile.Text.Trim();
                            string    country  = ddlcountry.Text.Trim();
                            string    city     = Tcity.Text.Trim();
                            string    address  = Taddress.Text.Trim();
                            datalayer c        = new datalayer();
                            c.Registration(name, email, gender, s_ques, s_ans, dob, mobileno, country, city, address);
                            Response.Redirect("admin/Home.aspx");
                        }
                        else
                        {
                            pnl_msg.Controls.Add(m.Error("User can not created!"));
                            System.Web.Security.Membership.DeleteUser(username);
                        }
                    }
                }
                else
                {
                    Account act = new Account();
                    if (Register())
                    {
                        Guid userid;
                        System.Web.Security.MembershipUser mu;
                        mu     = System.Web.Security.Membership.GetUser(username);
                        userid = (Guid)mu.ProviderUserKey;
                        if (act.SaveActivationKey(userid, key))
                        {
                            //  Hash_Pass hash = new Hash_Pass();
                            // string hash_pass = Hash_Pass.DESCryptoHelper.DESEncrypt(Tpassword.Text.Trim());
                            var    siteRoot       = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/");
                            string activate_url   = siteRoot + "ActivateAccount.aspx?key=" + key;
                            string site_url       = siteRoot;
                            string web_design_url = siteRoot + "web-design/create.aspx";
                            string hosting_url    = siteRoot + "hosting/main.aspx";
                            string help           = siteRoot + "contact-us.html";
                            string address        = "Balaganj, Lucknow Up 226003</br> Web Creation Inc.";
                            string password       = Hash_Pass.DESCryptoHelper.DESDecrypt(Session[Constants.Session.PASSWORD].ToString());
                            WMail  mail           = new WMail();
                            if (mail.Send(Temail.Text.Trim(), "", "", Tname.Text.Trim(), password, activate_url, site_url, web_design_url, hosting_url, help, address))
                            {
                                string name  = Tname.Text.Trim();
                                string email = Temail.Text.Trim();
                                //string password = Tpassword.Text.Trim();
                                string    gender       = Rblgender.Text.Trim();
                                string    s_ques       = ddlsecurityQ.Text.Trim();
                                string    s_ans        = TAnswer.Text.Trim();
                                string    dob          = Tdob.Text.Trim();
                                string    mobileno     = Tmobile.Text.Trim();
                                string    country      = ddlcountry.Text.Trim();
                                string    city         = Tcity.Text.Trim();
                                string    user_address = Taddress.Text.Trim();
                                datalayer c            = new datalayer();
                                c.Registration(name, email, gender, s_ques, s_ans, dob, mobileno, country, city, user_address);
                                pnl_msg.Controls.Add(m.Error("An activation link has been sent to your email."));
                                clear();
                            }
                        }
                        else
                        {
                            pnl_msg.Controls.Add(m.Error("An error occurred while sending mail."));
                            System.Web.Security.Membership.DeleteUser(username);
                        }
                        // Response.Redirect("home.aspx");
                    }
                    else
                    {
                        pnl_msg.Controls.Add(m.Error("An error occurred while processing your request."));
                    }
                }
            }
        }
        else
        {
            lbl_message.ForeColor = System.Drawing.Color.Red;
            lbl_message.Text      = "Accept our terms and conditions.";
        }
    }