Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //进行激活判断
            //修改密码
            //显示激活成功
            //用户登录

            if (!Page.IsPostBack)
            {
                lbl_info.Text = "至少包含一个大写字母,至少包含一个小写字母,至少包含一个数字,密码只能以字母开头,并且包含这些字母(!#@$%^&*)中的一个, 并且密码长度至少是8个";
                string id_tmp = System.Web.HttpUtility.UrlEncode(Request.QueryString["id"], System.Text.UnicodeEncoding.UTF8);
                string id     = id_tmp.Replace("%3d", "=");

                //string token = Request.QueryString["id"];
                string de_id = EnDecrypt.Decrypt(id);
                hf_id.Value = id;
                if (de_id != "")
                {
                    user_Pub = QueryPwd(de_id);

                    string commonname = user_Pub.firstName;
                    string oldpwd     = user_Pub.password;

                    lbl_username.Text = commonname;
                    lbl_oldpwd.Text   = oldpwd;
                }
                else
                {
                    Response.Write("Invalid Link");
                    return;
                }
            }
        }
Exemplo n.º 2
0
        public static UserInfo_Normal QueryInfoByID(string id)
        {
            UserInfo_Normal user = new UserInfo_Normal();

            // DataTable dt = DBHelp.GetDataSet("select userId,firstName,emailAddress,registrationToken,expTime,activited,password from local_users where registrationToken='" + token + "'");
            DataTable dt = DBHelp.GetDataSet("select * from local_users where userId='" + id + "'");

            if (dt.Rows.Count > 0)
            {
                user.userId               = int.Parse(dt.Rows[0]["userId"].ToString());
                user.firstName            = dt.Rows[0]["firstName"].ToString();
                user.emailAddress         = dt.Rows[0]["emailAddress"].ToString();
                user.registrationToken    = dt.Rows[0]["registrationToken"].ToString();
                user.tokenExpiredDatetime = Convert.ToDateTime(dt.Rows[0]["tokenExpiredDatetime"].ToString());
                string act = dt.Rows[0]["activited"].ToString();
                if (act == "true")
                {
                    user.activited = 1;
                }
                else
                {
                    user.activited = 0;
                }
                user.password = dt.Rows[0]["password"].ToString();
            }
            return(user);
        }
Exemplo n.º 3
0
        private UserInfo_Normal QueryPwd(string id)
        {
            UserInfo_Normal user   = new UserInfo_Normal();
            SqlDataReader   reader = DBHelper.DBHelp.GetReader("select userId,firstName,emailAddress,registrationToken,tokenExpiredDatetime,activited,password from local_users where userId=@id",

                                                               new SqlParameter("@id", id));

            while (reader.Read())
            {
                user.userId               = reader.GetInt32(0);
                user.firstName            = reader.GetString(1);
                user.emailAddress         = reader.GetString(2);
                user.registrationToken    = reader.GetString(3);
                user.tokenExpiredDatetime = reader.GetDateTime(4);
                string act = reader[5].ToString();
                if (act == "true")
                {
                    user.activited = 1;
                }
                else
                {
                    user.activited = 0;
                }
                user.password = reader.GetString(6);
            }
            reader.Close();
            return(user);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 向新用户发送邮件
        /// </summary>
        private void SendSMTPEMail()
        {
            try
            {
                string addresser = "*****@*****.**"; //发送者的邮箱
                string recipient = this.txt_usermail.Text.Trim();    //接收者的邮箱
                string userName  = this.txt_firstName.Text.Trim();   //接收者的用户名
                //string emailPwd = "FBW08uos$";//发送者的邮箱密码

                user_norm = QueryId(userName, recipient);
                string id   = EnDecrypt.Encrypt(user_norm.userId.ToString());
                string code = user_norm.registrationToken;


                string title = "Thanks for registering, please verify your email registration";
                //   string str = string.Format("http://localhost:24569/RegistSuccess.aspx?userName={0}&id={1}&token={2}", userName, id, code); //激活码链接
                // string str = string.Format("http://localhost:24569/confirm.aspx?token={0}", code); //激活码链接
                string      str     = "http://localhost:44567/confirm.aspx?id=" + id + "&token=" + code + "";
                string      content = "Please click the link to complete the email verification  " + str;// +",也可以访问http://localhost:24569/confirm.aspx,输入激活码:" + code + "进行激活";
                MailMessage message = new MailMessage(addresser, recipient);
                message.Subject  = title;
                message.Body     = content;
                message.Priority = MailPriority.High;
                SmtpClient client = new SmtpClient("KLAUVM19.kerrylogistics.com", 25);//更改,例如smtp.163.com,smtp.gmail.com
                client.EnableSsl             = false;
                client.UseDefaultCredentials = false;
                //client.Credentials = new System.Net.NetworkCredential(addresser, emailPwd);
                client.Send(message);
            }
            catch (Exception ex)
            {
                // Response.Write("email send fail..."+ex.ToString());
                lbl_msg.Text = "Sending error" + ex.ToString();
            }
        }
Exemplo n.º 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string token  = Request.QueryString["token"];
                string id_tmp = System.Web.HttpUtility.UrlEncode(Request.QueryString["id"], System.Text.UnicodeEncoding.UTF8);
                string id     = id_tmp.Replace("%3d", "=");
                if (token != "" && id != "")
                {
                    string de_id = EnDecrypt.Decrypt(id);
                    //user_nom = OperData.QueryIdByToken(token);
                    user_nom = OperData.QueryInfoByID(de_id);
                    if (user_nom != null)
                    {
                        string   first = user_nom.firstName;
                        DateTime tokenExpiredDatetime = user_nom.tokenExpiredDatetime; //有效期

                        string code = user_nom.registrationToken;                      //激活码
                        int    flag = user_nom.activited;                              //激活状态

                        DateTime curtime = DateTime.Now;



                        if (flag == 0 && curtime < tokenExpiredDatetime)
                        {
                            if (OperData.UpdateActiveByID(de_id))
                            {
                                //这就是打断点的方法
                                Response.Write("<script language=javascript>alert('Your account has been activated successfully!');window.location.href='active.aspx?id=" + id + "';</script>");
                            }
                            else
                            {
                                Response.Write("<script language=javascript>alert('Failed to activate!');window.location.href='login.aspx';</script>");
                            }
                        }
                        else
                        {
                            if (flag == 1)
                            {
                                Response.Write("<script language=javascript>alert('Account has been activated!');window.location.href='active.aspx?id=" + id + "';</script>");
                                return;
                            }

                            if (flag == 0 && curtime > tokenExpiredDatetime)
                            {
                                Response.Write("<script language=javascript>alert('Code expired, activate fail!');window.location.href='delaccount.aspx?id=" + id + "';</script>");
                                return;
                            }
                            else
                            {
                                Response.Write("<script language=javascript>alert('Error Link!');window.location.href='login.aspx';</script>");
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        protected void btn_active_Click(object sender, EventArgs e)
        {
            if (txt_regcode.Text != "" || txt_regcode.Text != null)
            {
                Response.Write("");
            }
            else
            {
                string token = txt_regcode.Text.Trim();
                if (token != "")
                {
                    user_nom = OperData.QueryIdByToken(token);
                    string   first = user_nom.firstName;
                    DateTime tokenExpiredDatetime = user_nom.tokenExpiredDatetime; //有效期
                    string   code = user_nom.registrationToken;                    //激活码
                    int      flag = user_nom.activited;                            //激活状态

                    DateTime curtime = DateTime.Now;
                    if (code == token && flag == 0 && curtime < tokenExpiredDatetime)
                    {
                        if (OperData.UpdateActive(token))
                        {
                            Response.Write("<script language=javascript>alert('Your account has been activated successfully!');window.location.href='active.aspx?token=" + token + "';</script>");
                        }
                        else
                        {
                            Response.Write("<script language=javascript>alert('Failed to activate!');window.location.href='login.aspx';</script>");
                        }
                    }
                    else
                    {
                        if (code == token && flag == 1)
                        {
                            Response.Write("<script language=javascript>alert('Your account has been activated successfully!');window.location.href='active.aspx?token=" + token + "';</script>");
                            return;
                        }

                        if (code == token && flag == 0 && curtime > tokenExpiredDatetime)
                        {
                            Response.Write("<script language=javascript>alert('Code expired, failed to activate!');window.location.href='login.aspx" + token + "';</script>");
                            return;
                        }
                        else
                        {
                            Response.Write("<script language=javascript>alert('Error Link!');window.location.href='login.aspx';</script>");
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
        private UserInfo_Normal QueryId(string firstname, string email)
        {
            UserInfo_Normal user   = new UserInfo_Normal();
            SqlDataReader   reader = DBHelper.DBHelp.GetReader("select userId,firstName,emailAddress,registrationToken,tokenExpiredDatetime,activited from local_users where firstName=@firstName and emailAddress=@mail",
                                                               new SqlParameter("@firstName", firstname),
                                                               new SqlParameter("@mail", email));

            while (reader.Read())
            {
                user.userId            = reader.GetInt32(0);
                user.registrationToken = reader.GetString(3);
            }
            reader.Close();
            return(user);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 是否用户已存在
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="Email"></param>
        /// <returns></returns>
        public UserInfo_Normal HaveUser(string userName, string Email)
        {
            UserInfo_Normal user = new UserInfo_Normal();

            string sql = "select firstName,surName,emailAddress from local_users where firstName='" + userName + "' or emailAddress='" + Email + "'";

            SqlDataReader reader = DBHelper.DBHelp.GetReader(sql);

            while (reader.Read())
            {
                user.firstName    = reader.GetString(0);
                user.emailAddress = reader.GetString(1);
            }


            reader.Close();
            return(user);
        }
Exemplo n.º 9
0
        private static UserInfo_Normal QueryPwd(string token)
        {
            UserInfo_Normal user   = new UserInfo_Normal();
            SqlDataReader   reader = DBHelper.DBHelp.GetReader("select userId,firstName,emailAddress,registrationToken,tokenExpiredDatetime,activited,password from local_users where registrationToken=@token",

                                                               new SqlParameter("@token", token));

            while (reader.Read())
            {
                user.userId               = reader.GetInt32(0);
                user.firstName            = reader.GetString(1);
                user.emailAddress         = reader.GetString(2);
                user.registrationToken    = reader.GetString(3);
                user.tokenExpiredDatetime = reader.GetDateTime(4);
                user.activited            = reader.GetInt32(5);
                user.password             = reader.GetString(6);
            }
            reader.Close();
            return(user);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 插入用户信息到数据库表
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        private bool Insert(UserInfo_Normal user)
        {
            string sql = @"insert into local_users 
(firstName,surName,password,companyCode,position,workPhoneNumber,mobileNumber,emailAddress,userCreatedBy,userCreatedDatetime,userLatestEditedBy,userLatestEditedDatetime,activited,registrationToken,registrationDatetime,tokenExpiredDatetime)
VALUES (@firstName,@surName,@password,@companyCode,@position,@workPhoneNumber,@mobileNumber,@emailAddress,@userCreatedBy,@userCreatedDatetime,@userLatestEditedBy,@userLatestEditedDatetime,@activited,@registrationToken,@registrationDatetime,@tokenExpiredDatetime)";

            SqlParameter[] para = new SqlParameter[]
            {
                new SqlParameter("@firstName", user.firstName),
                new SqlParameter("@surName", user.surName),
                new SqlParameter("@password", user.password),
                new SqlParameter("@companyCode", user.companyCode),
                new SqlParameter("@position", user.position),
                new SqlParameter("@workPhoneNumber", user.workPhoneNumber),
                new SqlParameter("@mobileNumber", user.mobileNumber),
                new SqlParameter("@emailAddress", user.emailAddress),
                new SqlParameter("@userCreatedBy", user.userCreatedBy),
                new SqlParameter("@userCreatedDatetime", user.userCreatedDatetime),
                new SqlParameter("@userLatestEditedBy", user.userLatestEditedBy),
                new SqlParameter("@userLatestEditedDatetime", user.userLatestEditedDatetime),
                new SqlParameter("@activited", user.activited = 0),
                new SqlParameter("@registrationToken", user.registrationToken),
                new SqlParameter("@registrationDatetime", user.registrationDatetime),
                new SqlParameter("@tokenExpiredDatetime", user.tokenExpiredDatetime)
            };

            int i = DBHelp.ExecuteCommand(sql, para);

            if (i > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 11
0
        private bool isUser()
        {
            string userName     = txt_firstName.Text.Trim();
            string surname      = txt_surName.Text.Trim();
            string companycode  = txt_companyCode.Text.Trim();
            string mail         = txt_usermail.Text.Trim();
            string password     = "******";// txt_password.Text.Trim();
            string workphonenum = txt_workPhoneNumber.Text.Trim();

            user_norm = HaveUser(userName, mail);

            if (userName == "")
            {
                // Response.Write("用户名不能为空");
                lbl_msg.Text = "Username cannot be empty";
                return(false);
            }
            if (surname == "")
            {
                lbl_msg.Text = "Surname cannot be empty";
                return(false);
            }
            if (password == "")
            {
                //Response.Write("密码不能为空");
                lbl_msg.Text = "Password cannot be empty";
                return(false);
            }
            if (companycode == "")
            {
                lbl_msg.Text = "Company code cannot be empty";
                return(false);
            }
            if (workphonenum == "")
            {
                // Response.Write("邮箱不能为空");
                lbl_msg.Text = "Work phnoe number cannot be empty";
                return(false);
            }
            if (mail == "")
            {
                // Response.Write("邮箱不能为空");
                lbl_msg.Text = "Email address cannot be empty";
                return(false);
            }
            if (userName == user_norm.firstName)
            {
                // Response.Write("用户名已存在");
                lbl_msg.Text = "Username already exists";
                return(false);
            }

            //检查邮箱是否已注册
            if (OperData.ChkReEmail(mail))
            //if (mail == user_norm.emailAddress)
            {
                //Response.Write("邮箱已存在");

                return(true);
            }
            else
            {
                userName     = "";
                surname      = "";
                companycode  = "";
                mail         = "";
                password     = "";
                workphonenum = "";
                lbl_msg.Text = "The mailbox already exists";
                return(false);
            }
        }