Beispiel #1
0
    public CManageError Validate(string title, string mailfrom, string mailto, string code)
    {
        CManageError errors    = new CManageError();
        CValidate    TestValue = new CValidate();
        int          numErr    = 0;

        if ((title.Length == 0) || (mailfrom.Length == 0) || (mailto.Length == 0) || (code.Length == 0))
        {
            errors.AddError(terror);
            numErr++;
            return(errors);
        }
        if (!TestValue.TestAddressEmail(mailfrom) || !TestValue.TestAddressEmail(mailto))
        {
            errors.AddError(terrEmail);
            numErr++;
            return(errors);
        }
        if (Session["RamDomCodeRegister"] != null)
        {
            if (!code.Equals(Session["RamDomCodeRegister"].ToString()))
            {
                errors.AddError(terrcode);
                numErr++;
                Session["RamDomCodeRegister"] = DataCommon.CreateCodeRanDom(5);
                return(errors);
            }
        }
        return(errors);
    }
    public CManageError Validate(string name, string address, string email, string mobile, int idPos)
    {
        CValidate    testValue = new CValidate();
        CManageError errors    = new CManageError();
        int          numErr    = 0;

        if (name.Length == 0 || address.Length == 0 || email.Length == 0 || mobile.Length == 0)
        {
            numErr++;
            errors.AddError(terrcommon);
            return(errors);
        }
        if (idPos == 0)
        {
            numErr++;
            errors.AddError(tPleaseChoiceWhere);
            return(errors);
        }
        if (!testValue.TestAddressEmail(email))
        {
            numErr++;
            errors.AddError(terrmail);
            return(errors);
        }
        return(errors);
    }
 protected void changeinfo_Click(object sender, EventArgs e)
 {
     try
     {
         string name    = txtname.Value.Trim();
         string company = txtcompany.Value.Trim();
         string job     = txtjob.Value.Trim();
         string mobile  = txtmobile.Value.Trim();
         string office  = txtoffice.Value.Trim();
         string home    = txthome.Value.Trim();
         //string email1 = txtemail1.Value.Trim();
         string email2  = txtemail2.Value.Trim();
         string fax     = txtfax.Value.Trim();
         string tax     = txttax.Value.Trim();
         string website = txtwebsite.Value.Trim();
         if (name.Length == 0)
         {
             diverror2.Visible   = true;
             diverror2.InnerHtml = "<div class='diverror'>" + terrcommon + "</div>";
             return;
         }
         else if (!Validate.TestAddressEmail(email2))
         {
             diverror2.Visible   = true;
             diverror2.InnerHtml = "<div class='diverror'>" + terremail + "</div>";
             return;
         }
         string[] arrstr = (string[])Session["infoUser"];
         Boolean  update = Users.UserUpdateInfoId(int.Parse(arrstr[0].ToString()), name, company, job, mobile, office, home, email2, fax, tax, website);
         if (update)
         {
             diverror2.Visible   = true;
             diverror2.InnerHtml = "<div class='diverror'>" + tyestochange + "</div>";
             return;
         }
         else
         {
             diverror2.Visible   = true;
             diverror2.InnerHtml = "<div class='diverror'>" + terrUpdate + "</div>";
             return;
         }
     }
     catch
     {
         diverror2.Visible   = true;
         diverror2.InnerHtml = "<div class='diverror'>" + terrUpdate + "</div>";
         return;
     }
 }
Beispiel #4
0
    protected void getpass_Click(object sender, EventArgs e)
    {
        try
        {
            string            addressto   = txtemail.Value.Trim();
            CValidate         validate    = new CValidate();
            UserManagerSystem usermanager = new UserManagerSystem();
            if (!validate.TestAddressEmail(addressto))
            {
                divErrors.InnerHtml = "<div class='diverror'>" + merrmail + "</div>";
                divErrors.Visible   = true;
                return;
            }
            else
            {
                string code = txtcode.Value.Trim();
                if (!Session["RamDomCodeRegister"].ToString().Equals(code))
                {
                    divErrors.InnerHtml           = "<div class='diverror'>" + mcodeerr + "</div>";
                    divErrors.Visible             = true;
                    Session["RamDomCodeRegister"] = datacommon.CreateCodeRanDom(5);
                    return;
                }
            }
            DataSet ds       = usermanager.UserSelecWithEmail(addressto);
            string  username = "";
            string  name     = "";
            if (ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    username = ds.Tables[0].Rows[0]["userName"].ToString();
                    name     = ds.Tables[0].Rows[0]["contactName"].ToString();
                }
                else
                {
                    divErrors.InnerHtml = "<div class='diverror'>" + mnothave + "</div>";
                    divErrors.Visible   = true;
                    return;
                }
            }
            else
            {
                divErrors.InnerHtml = "<div class='diverror'>" + mnothave + "</div>";
                divErrors.Visible   = true;
                return;
            }
            try
            {
                XmlDocument   docservermail = new XmlDocument();
                string        xpathfile     = Server.MapPath("data/xml/configmailserver.xml");
                XmlTextReader readfile      = new XmlTextReader(xpathfile);
                docservermail.Load(readfile);
                readfile.Close();
                XmlNode     node       = docservermail.SelectSingleNode("/server");
                XmlNodeList listnode   = node.ChildNodes;
                int         numnodes   = listnode.Count;
                Hashtable   hastServer = new Hashtable();
                for (int i = 0; i < numnodes; i++)
                {
                    hastServer.Add(listnode[i].Name, listnode[i].InnerText);
                }
                SmtpClient  client      = new SmtpClient();
                MailAddress addressfrom = new MailAddress(hastServer["from"].ToString(), hastServer["displayname"].ToString(), System.Text.Encoding.UTF8);
                MailAddress MailTo      = new MailAddress(addressto);
                MailMessage message     = new MailMessage();
                message.From = addressfrom;
                message.To.Add(MailTo);
                message.CC.Add(MailTo);
                message.BodyEncoding    = System.Text.Encoding.UTF8;
                message.SubjectEncoding = System.Text.Encoding.UTF8;
                message.Subject         = "YÊU CẦU LẤY LẠI MẬT KHẨU";
                message.IsBodyHtml      = true;
                string   codeGet = datacommon.CreateCodeRanDom(32);
                DateTime time    = new DateTime();
                time = DateTime.Now;

                message.Body = BuildTable(username, name, hastServer["domain"].ToString(), hastServer["website"].ToString(), addressto, codeGet, time);
                client.Host  = hastServer["host"].ToString();
                client.Port  = int.Parse(hastServer["port"].ToString());
                Boolean testInsert = usermanager.UserInsertRequestPass(codeGet, name, addressto, time);
                if (testInsert)
                {
                    client.Credentials = new NetworkCredential(hastServer["username"].ToString(), hastServer["password"].ToString(), hastServer["domain"].ToString());
                    client.Send(message);
                    message.Dispose();
                    divErrors.Visible             = true;
                    divErrors.InnerHtml           = "<div class='diverror'>" + tyestosend + "</div>";
                    txtcode.Value                 = "";
                    txtemail.Value                = "";
                    Session["RamDomCodeRegister"] = datacommon.CreateCodeRanDom(5);
                }
                else
                {
                    divErrors.Visible   = true;
                    divErrors.InnerHtml = "<div class='diverror'>" + terrInsert + "</div>";
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.ToString());
                divErrors.Visible   = true;
                divErrors.InnerHtml = "<div class='diverror'>" + tnotsend + "</div>";
            }
        }
        catch (Exception ex)
        {
            divErrors.InnerHtml = "<div class='diverror'>" + ex.ToString() + "</div>";
        }
    }
    public CManageError ValidateForm(string username, string pass1, string pass2, string fullname, string jobtitle, string address, string email, string mobile, string homephone, string code)
    {
        CManageError errors   = new CManageError();
        int          numErr   = 0;
        CValidate    validate = new CValidate();

        if (username.Length > 0)
        {
            if (validate.TestUserName(username) > 0)
            {
                numErr++;
                errors.AddError(merruser);
                return(errors);
            }
        }
        else
        {
            numErr++;
            errors.AddError(merr);
            return(errors);
        }
        if (pass1.Length > 0)
        {
            if (pass1.Length < 4)
            {
                numErr++;
                errors.AddError(mpass);
                return(errors);
            }
        }
        else
        {
            numErr++;
            errors.AddError(merr);
            return(errors);
        }
        if (pass2.Length > 0)
        {
        }
        else
        {
            numErr++;
            errors.AddError(merr);
            return(errors);
        }
        if (fullname.Length == 0)
        {
            numErr++;
            errors.AddError(merr);
            return(errors);
        }
        if (address.Length == 0)
        {
            numErr++;
            errors.AddError(merr);
            return(errors);
        }
        if (email.Length > 0)
        {
        }
        else
        {
            numErr++;
            errors.AddError(merr);
            return(errors);
        }
        if (!pass1.Equals(pass2))
        {
            numErr++;
            errors.AddError(mpasserr);
            return(errors);
        }
        if (code.Length > 0)
        {
            string subcode = Session["RamDomCodeRegister"].ToString();
            if (!subcode.Equals(code))
            {
                numErr++;
                errors.AddError(mcode);
                subcode = GetCodeRandom.CreateCodeRanDom(5);
                Session["RamDomCodeRegister"] = subcode;
                return(errors);
            }
        }
        else
        {
            numErr++;
            errors.AddError(merr);
            return(errors);
        }
        if (!validate.TestAddressEmail(email))
        {
            numErr++;
            errors.AddError(merremail);
            return(errors);
        }
        //TestExsit Username, or Email:
        DataSet Ds = new UserManagerSystem().UserSelectUsernameandEmail(username, email);

        if (Ds.Tables.Count > 0)
        {
            if (Ds.Tables[0].Rows.Count > 0)
            {
                if (!Ds.Tables[0].Rows[0]["count"].ToString().Equals("0"))
                {
                    numErr++;
                    errors.AddError(muser);
                }
                if (!Ds.Tables[1].Rows[0]["count"].ToString().Equals("0"))
                {
                    numErr++;
                    errors.AddError(memail);
                }
            }
        }
        return(errors);
    }