Beispiel #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //第一次打开该页面
                //View处理部分:
                RegResult.Visible = false; //注册结果不可见。
                RegUser.Visible   = true;  //显示注册表单
            }
            else
            {
                //用户填写好了表单,回传到了本页。
                #region Control处理部分
                //获取提交表单的信息,去掉所有前导和滞后空格
                String userAccount  = Request.Form["UserAccount"].Trim();
                String userPassword = Request.Form["UserPassword"];     //密码不用去空格
                if (userPassword.Length < 6 || userPassword.Length > 16)
                {
                    RegResult.Text    = "密码长度应该在6-16位之间,请重新输入";
                    RegResult.Visible = true;
                    return;
                }
                String strUserSex       = Request.Form["UserSex"].Trim();
                String userIntroduction = Request.Form["UserIntroduction"].Trim();
                String userNickname     = Request.Form["UserNickname"].Trim();
                //用户验证码
                String regVerifyCode = Request.Form["RegVerifyCode"].Trim().ToUpper();
                //最后一次登录IP即为注册IP.
                String userLastLoginIp = HttpContext.Current.Request.UserHostAddress;

                //转换为布尔型,注意用户性别1为男0为女
                Boolean userSex = strUserSex.ToUpper().Trim().Equals("MALE");

                //密码MD5加密
                userPassword = UserOpr.MD5(userPassword);
                //测试用语句

                /* RegResult.Text =
                 *  "注册信息为:" + "账号" + userAccount + "密码" + userPassword + "性别" + strUserSex +
                 *  "密码" + userPassword + "昵称" + userNickname + "最后登录ip" + userLastLoginIp + "个人说明" + userIntroduction;
                 */
                if (     //验证码判定
                    Session[RegVerifyCodeGenerator.strIdentify] != null &&
                    regVerifyCode.ToUpper().Equals
                        (Session[RegVerifyCodeGenerator.strIdentify].ToString().ToUpper()) &&
                    !regVerifyCode.Equals("") &&
                    regVerifyCode != null
                    )
                {
                    //验证码正确,这里记得刷新验证码以防后退提交!
                    Session.Remove(RegVerifyCodeGenerator.strIdentify);     //防止后退提交
                    #region 用户注册,与UserOpr打交道
                    //开始注册用户,数据完整性检查在BLL.UserOpr类中
                    String user_head = "img/01.jpg"; //男生默认头像
                    if (userSex == false)            //是女生
                    {
                        user_head = "img/00.jpg";    //女生默认头像
                    }
                    User newUser = new User(userAccount, userPassword, userNickname, userSex, userLastLoginIp, user_head.Trim());
                    newUser.User_introduction = userIntroduction;

                    if (UserOpr.CreateUser(newUser) > 0)
                    {
                        RegResult.Text  = "注册成功!请到您的邮箱" + userAccount + "中打开确认信完成激活,3秒钟之后自动跳转回主页";
                        RegUser.Visible = false;                                                        //注册表单不可见
                        HtmlMeta RedirectMeta = new HtmlMeta();                                         //重定向用Meta标签
                        RedirectMeta.HttpEquiv = "refresh";                                             //指定行为为跳转
                        RedirectMeta.Content   = "3;url=" + ReadWebConfig.GetAppSettingValue("Domain"); //时间为三秒,跳转到首页
                        this.Page.Header.Controls.Add(RedirectMeta);
                    }
                    else
                    {
                        RegResult.Text = "注册失败!请检查输入项!";

                        RegUser.Visible = true;     //注册表单可见
                    }
                    #endregion
                }
                else                             //验证码输入不正确
                {
                    RegResult.Text  = "验证码验证出错"; //提示状态
                    RegUser.Visible = true;      //注册表单可见
                }

                #endregion
                #region 通用View处理部分
                RegResult.Visible = true;   //提示状态
                UserPassword.Text = "";     //清空密码框
                #endregion
            }
        }
Beispiel #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Admin loggedAdmin = AdminOpr.isLogged(Request); //获取信息

            if (!Page.IsPostBack)
            {
                //第一次显示
                if (loggedAdmin != null) //已经登录
                {
                    //如果已经登录
                    AdminLoginForm.Visible   = false; //不显示登录页面
                    AdminLoginStatus.Text    = "欢迎回来!尊敬的管理员" + loggedAdmin.User_nickname + ",3秒后自动为您转入管理员首页";
                    AdminLoginStatus.Visible = true;
                    //重定向
                    HtmlMeta RedirectMeta = new HtmlMeta();            //重定向用Meta标签
                    RedirectMeta.HttpEquiv = "refresh";                //指定行为为跳转
                    RedirectMeta.Content   = "3;url=admin_index.aspx"; //时间为三秒,跳转到首页
                    this.Page.Header.Controls.Add(RedirectMeta);
                }
                else //没登录
                {
                    AdminLoginForm.Visible   = true;
                    AdminLoginStatus.Visible = false; //隐藏指示信息
                }
            }
            else
            {
                //提交回来了登录信息
                String AdminLoginVerifyCode = Request.Form["txtAdminVerifyCode"];
                String adminAccount         = Request.Form["txtAdminAccount"];
                String adminPassword        = Request.Form["txtAdminPassword"];
                if (Session[AdminLoginVerifyCodeGenerator.strIdentify] != null &&
                    !Session[AdminLoginVerifyCodeGenerator.strIdentify].ToString().Equals("") &&  //notNullAndEmpty
                    AdminLoginVerifyCode != null &&
                    !AdminLoginVerifyCode.Equals(""))
                {
                    //清空Session防止后退提交
                    Session.Remove(AdminLoginVerifyCodeGenerator.strIdentify);

                    //验证码校验通过
                    Admin loginAdmin = new Admin();
                    loginAdmin.User_account  = adminAccount;
                    loginAdmin.User_password = UserOpr.MD5(adminPassword);
                    Admin entireAdmin = AdminOpr.isLegalLogin(loginAdmin);
                    if (entireAdmin != null)
                    {
                        //合法登录请求
                        entireAdmin.User_last_login_date = DateTime.Now;                                //登录时间
                        entireAdmin.User_last_login_ip   = HttpContext.Current.Request.UserHostAddress; //登录ip
                        AdminOpr.UpdateAdminInfo(entireAdmin);                                          //更新登录ip和时间
                        //分配cookies
                        HttpCookie adminAccountCookie  = new HttpCookie("adminAccount");
                        HttpCookie adminPasswordCookie = new HttpCookie("adminPassword");
                        adminAccountCookie.Value    = entireAdmin.User_account;
                        adminPasswordCookie.Value   = entireAdmin.User_password;
                        adminAccountCookie.Expires  = DateTime.Now.AddDays(1D); // 1天过期
                        adminPasswordCookie.Expires = DateTime.Now.AddDays(1D); //1天过期
                        //添加Cookie,相当于授权
                        Response.Cookies.Add(adminAccountCookie);
                        Response.Cookies.Add(adminPasswordCookie);

                        //UI操作
                        AdminLoginForm.Visible   = false; //不显示登录页面
                        AdminLoginStatus.Text    = "欢迎回来!尊敬的管理员" + entireAdmin.User_nickname + ",3秒后自动为您转入管理员首页";
                        AdminLoginStatus.Visible = true;
                        //重定向
                        HtmlMeta RedirectMeta = new HtmlMeta();            //重定向用Meta标签
                        RedirectMeta.HttpEquiv = "refresh";                //指定行为为跳转
                        RedirectMeta.Content   = "3;url=admin_index.aspx"; //时间为三秒,跳转到首页
                        this.Page.Header.Controls.Add(RedirectMeta);
                    }
                    else
                    {
                        //登录请求非法
                        AdminLoginStatus.Text    = "用户名或密码错误,请重试";
                        AdminLoginStatus.Visible = true;
                        AdminLoginForm.Visible   = true;
                    }
                }
                else
                {
                    //验证码校验失败,给出提示信息
                    AdminLoginStatus.Text    = "验证码校验失败,请刷新验证码后重试";
                    AdminLoginStatus.Visible = true;
                    AdminLoginForm.Visible   = true;
                }
            }
        }
Beispiel #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //判断是否已经登录,注意,由于这里不管是不是postBack,因此取到的对象,timeStamp一定是最新的那个!
            //换而言之,我们的策略就是LastComesWin——最新的一次提交总是屌的!
            User loggedUser = UserOpr.isLogged(Request);

            //未登录
            if (loggedUser == null)
            {
                //登录界面不显示
                loggedDiv.Visible = false;
                //提示信息
                logStatus.Text    = "主人大人,您未登录或已经登录过期哦!3秒后自动转向登录页面哦!请登录了再来调戏人家啦";
                logStatus.Visible = true; //提示信息开启

                //重定向
                HtmlMeta RedirectMeta = new HtmlMeta();                                               //重定向用Meta标签
                RedirectMeta.HttpEquiv = "refresh";                                                   //指定行为为跳转
                RedirectMeta.Content   = "3;url=" + ReadWebConfig.GetAppSettingValue("LoginPageURL"); //时间为三秒,跳转到首页
                this.Page.Header.Controls.Add(RedirectMeta);
            }
            else //已登录
            {
                //显示登录界面
                loggedDiv.Visible = true;
                //提示信息隐藏
                logStatus.Visible = false;

                if (!Page.IsPostBack)
                {
                    //用户未提交修改信息

                    //设置页面中对应的用户信息
                    //账户
                    txtUserAccount.Text = loggedUser.User_account;
                    //余额
                    lblMoney.Text = lblMoney.Text + loggedUser.User_money.ToString();
                    //头像,记得去空格
                    imgHead.ImageUrl = loggedUser.User_head.Trim();
                    //简介,记得去空格
                    txtUserIntroduction.Text = loggedUser.User_introduction.Trim();
                    //昵称。记得去空格
                    txtUserNickname.Text = loggedUser.User_nickname.Trim();
                    if (loggedUser.User_sex) //男生
                    {
                        UserSex.Items[0].Selected = true;
                        UserSex.Items[1].Selected = false;
                    }
                    else
                    {
                        UserSex.Items[0].Selected = false;
                        UserSex.Items[1].Selected = true; //女生
                    }
                }
                else
                {
                    //用户提交修改信息,验证的时候注意,从loggedUser里取账号和旧密码,旧密码和输入比对,账号直接带入操作
                    String oldPassword       = Request.Form["txtUserOldPassword"];
                    String newPassword       = Request.Form["txtUserNewPassword"];
                    String verifyNewPassword = Request.Form["txtUserVerifyNewPassword"];
                    String userIntroduction  = Request.Form["txtUserIntroduction"].Trim();
                    String userNickname      = Request.Form["txtUserNickName"].Trim(); //记得去空格
                    //头像!这里用完记得立刻释放掉Cookie
                    String userHead = Request.Cookies["userHead"].Value;

                    //转换为布尔型,注意用户性别1为男0为女
                    String  strUserSex = Request.Form["UserSex"].Trim();
                    Boolean userSex    = strUserSex.ToUpper().Trim().Equals("MALE");

                    User newInfoUser = new User(loggedUser);
                    #region 验证是否需要修改密码
                    if (!oldPassword.Equals("") &&
                        oldPassword != null)
                    //填写了旧密码,意味着要修改密码
                    {
                        if (!newPassword.Equals(verifyNewPassword)) //新密码与确认密码不匹配
                        {
                            lblChangePasswordStatus.Text    = "新密码与确认密码不匹配,请检查后再输入";
                            lblChangePasswordStatus.Visible = true;
                            return; //停止提交
                        }
                        else
                        {
                            if (!UserOpr.MD5(oldPassword).Equals(loggedUser.User_password))
                            {
                                //旧密码与账号密码不匹配
                                lblChangePasswordStatus.Text    = "旧密码输入错误,请重新输入";
                                lblChangePasswordStatus.Visible = true;
                                return; //停止提交
                            }
                            else
                            {
                                //旧密码与账号密码匹配,且新密码与确认密码匹配的情况下
                                if (newPassword.Length > 16 ||
                                    newPassword.Length < 6)
                                {
                                    //新密码长度不对
                                    lblChangePasswordStatus.Text    = "新密码长度不正确,请重新提交";
                                    lblChangePasswordStatus.Visible = true;
                                    return; //停止提交
                                }
                                else
                                {
                                    //修改后一并提交
                                    newInfoUser.User_password = UserOpr.MD5(newPassword);

                                    /*
                                     * //修改用户密码
                                     * if (UserOpr.ChagneUserPassword(newInfoUser, UserOpr.MD5(newPassword)))
                                     * {
                                     *  //更改成功
                                     *  lblChangePasswordStatus.Text = "修改密码成功,请重新登录";
                                     *  lblChangePasswordStatus.Visible = true;
                                     *  return;//停止提交
                                     * }
                                     * else
                                     * {
                                     *  //更改失败
                                     *  lblChangePasswordStatus.Text = "修改密码失败,请检查输入是否正确";
                                     *  lblChangePasswordStatus.Visible = true;
                                     *  return; //停止提交
                                     * }
                                     * */
                                }
                            }
                        }
                    }
                    #endregion

                    #region 修改用户信息,这里不用加验证,userOpr里有

                    newInfoUser.User_introduction = userIntroduction;
                    newInfoUser.User_nickname     = userNickname;
                    if (userHead != null)
                    {
                        newInfoUser.User_head = userHead; //这里注意看一下是相对路径还是绝对路径
                        //释放Cookie
                        HttpCookie userHeadCookie = new HttpCookie("userHead");
                        userHeadCookie.Expires = DateTime.Now.AddDays(-1D);
                        Response.Cookies.Add(userHeadCookie);
                    }

                    newInfoUser.User_sex = userSex;
                    #endregion


                    //开始调用BLL
                    if (UserOpr.UpdateUserInfo(newInfoUser))
                    {
                        //修改成功
                        logStatus.Text    = "资料修改成功了哦,3秒后回到用户主页哦";
                        logStatus.Visible = true;
                        loggedDiv.Visible = false;
                        //重定向
                        HtmlMeta RedirectMeta = new HtmlMeta();           //重定向用Meta标签
                        RedirectMeta.HttpEquiv = "refresh";               //指定行为为跳转
                        RedirectMeta.Content   = "3;url=user_index.aspx"; //时间为三秒,跳转到首页
                        this.Page.Header.Controls.Add(RedirectMeta);
                    }
                    else
                    {
                        //修改失败,给出提示信息
                        logStatus.Text    = "修改资料失败了呢,真是抱歉,是不是主人大人什么地方填错了呢?";
                        logStatus.Visible = true;
                    }
                }
            }
        }
Beispiel #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //第一次访问
                LoginForm.Visible = true;
            }
            else
            {
                //提交回来了,校验。
                String userAccount     = Request.Form["UserAccount"].Trim();
                String userPassword    = Request.Form["UserPassword"];
                String loginVerifyCode = Request.Form["LoginVerifyCode"];

                //先校验验证码
                if (
                    Session[LoginVerifyCodeGenerator.strIdentify] != null &&
                    Session[LoginVerifyCodeGenerator.strIdentify].ToString().ToUpper().Equals
                        (loginVerifyCode.ToUpper()) &&
                    !loginVerifyCode.Equals("") &&
                    loginVerifyCode != null
                    //以上三行防止后退提交用的
                    )
                {
                    Session.Remove(LoginVerifyCodeGenerator.strIdentify); //防止后退提交
                    //验证码校验通过,设定要取回的User的账号密码
                    User verifyUser = new User();
                    verifyUser.User_account  = userAccount;
                    verifyUser.User_password = UserOpr.MD5(userPassword);
                    //验证用户是否是合法登录请求
                    User entireUser = UserOpr.isLegalLogin(verifyUser);
                    if (entireUser == null) //账号或密码错误,未注册,都是这个
                    {
                        LoginInfo.Text    = "账号或密码错误";
                        LoginForm.Visible = true;
                    }
                    else
                    {
                        //登录成功,更改提示信息,更新登录信息中的IP和日期,这里记得换成UpdateUserInfo!

                        entireUser.User_last_login_date = DateTime.Now;                                //获取当前登录日期
                        entireUser.User_last_login_ip   = HttpContext.Current.Request.UserHostAddress; //最后一次登录ip
                        UserOpr.UpdateUserInfo(entireUser);
                        LoginInfo.Text = "登录成功!3秒后跳转回主页";
                        //授予Cookies,相当于授权了

                        HttpCookie userAccountCookie  = new HttpCookie("userAccount");
                        HttpCookie userPasswordCookie = new HttpCookie("userPassword");
                        userAccountCookie.Value  = verifyUser.User_account;
                        userPasswordCookie.Value = verifyUser.User_password;

                        if (RememberMe.Checked) //这个判断很诡异,貌似Request.Form不好用的样子。
                        {
                            //如果选了RememberMe就保留一个星期
                            userPasswordCookie.Expires = DateTime.Now.AddDays(7D);
                            userAccountCookie.Expires  = DateTime.Now.AddDays(7D);
                        }
                        else
                        {
                            //否则只保存1天
                            userPasswordCookie.Expires = DateTime.Now.AddDays(1D);
                            userAccountCookie.Expires  = DateTime.Now.AddDays(1D);
                        }
                        //添加Cookie,相当于授权
                        Response.Cookies.Add(userAccountCookie);
                        Response.Cookies.Add(userPasswordCookie);
                        //重定向
                        HtmlMeta RedirectMeta = new HtmlMeta();                                         //重定向用Meta标签
                        RedirectMeta.HttpEquiv = "refresh";                                             //指定行为为跳转
                        RedirectMeta.Content   = "3;url=" + ReadWebConfig.GetAppSettingValue("Domain"); //时间为三秒,跳转到首页
                        this.Page.Header.Controls.Add(RedirectMeta);
                        //UI操作
                        LoginForm.Visible = false;
                    }
                }
                else
                {
                    //验证码校验失败
                    LoginInfo.Text    = "验证码输入错误,请检查";
                    LoginForm.Visible = true;
                }
            }
        }
Beispiel #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Admin loggedAdmin = AdminOpr.isLogged(Request);

            if (loggedAdmin == null)
            {
                //未登录
                lblLoginStatus.Text    = "您未登录或已经登录过期,请重新登录,3秒后转回管理员登录页。";
                lblLoginStatus.Visible = true;
                LoggedForm.Visible     = false;
                //重定向
                HtmlMeta RedirectMeta = new HtmlMeta();            //重定向用Meta标签
                RedirectMeta.HttpEquiv = "refresh";                //指定行为为跳转
                RedirectMeta.Content   = "3;url=admin_login.aspx"; //时间为三秒,跳转到首页
                this.Page.Header.Controls.Add(RedirectMeta);
            }
            else
            {
                //已登录
                if (!Page.IsPostBack)
                {
                    //首次访问
                    lblLoginStatus.Visible = false;
                    LoggedForm.Visible     = true;
                    txtAdminNickname.Text  = loggedAdmin.User_nickname.Trim();
                }
                else
                {
                    //提交修改信息
                    String adminOldPassword       = Request.Form[txtOldPassword.ID];
                    String adminNewPassword       = Request.Form[txtNewPassword.ID];
                    String adminVerifyNewPassword = Request.Form[txtVerifyNewPassword.ID];
                    String adminNickname          = Request.Form[txtAdminNickname.ID].Trim();

                    //修改密码的验证,填写了旧密码,要修改密码
                    if (!adminOldPassword.Equals("") &&
                        adminOldPassword != null
                        )
                    {
                        //长度验证
                        if (adminOldPassword.Length < 6 ||
                            adminOldPassword.Length > 16 ||
                            !UserOpr.MD5(adminOldPassword).Equals(loggedAdmin.User_password)
                            )
                        { //长度不对或输入不符
                            lblChangeInfo.Text    = "旧密码输入错误或旧密码格式不正确,旧密码长度应在6-16位之间,请重试";
                            lblChangeInfo.Visible = true;
                        }
                        else
                        {
                            //新密码一致性检查
                            if (adminNewPassword.Equals("") ||
                                adminNewPassword == null ||
                                adminNewPassword.Length < 6 ||
                                adminNewPassword.Length > 16 ||
                                !adminNewPassword.Equals(adminVerifyNewPassword))
                            {
                                lblChangeInfo.Text = "新密码与确认密码不一致或长度不正确(应在6-16位之间),请重试";
                            }
                            else
                            {
                                //新密码一致性检查通过,赋值赋值赋值。
                                loggedAdmin.User_password = UserOpr.MD5(adminNewPassword);
                                loggedAdmin.User_nickname = adminNickname;
                                if (AdminOpr.UpdateAdminInfo(loggedAdmin))
                                {
                                    //修改成功
                                    lblLoginStatus.Text    = "您已成功修改密码,请重新登录,3秒后跳转到登录页面";
                                    LoggedForm.Visible     = false;
                                    lblLoginStatus.Visible = true;

                                    //跳转
                                    HtmlMeta RedirectMeta = new HtmlMeta();            //重定向用Meta标签
                                    RedirectMeta.HttpEquiv = "refresh";                //指定行为为跳转
                                    RedirectMeta.Content   = "3;url=admin_login.aspx"; //时间为三秒,跳转到首页
                                    this.Page.Header.Controls.Add(RedirectMeta);
                                }
                                else
                                {
                                    //修改失败
                                    lblLoginStatus.Text    = "修改密码失败,请检查输入项";
                                    lblLoginStatus.Visible = true;
                                    LoggedForm.Visible     = true;
                                }
                            }
                        }
                    }
                    else
                    {
                        //没填旧密码,修改其他信息
                        loggedAdmin.User_nickname = adminNickname;
                        if (AdminOpr.UpdateAdminInfo(loggedAdmin))
                        {
                            lblLoginStatus.Text    = "您已成功修改信息";
                            LoggedForm.Visible     = true;
                            lblLoginStatus.Visible = true;
                        }
                        else
                        {
                            lblLoginStatus.Text    = "修改信息失败,原因可能是服务器大姨妈或您的输入有误,请重试";
                            LoggedForm.Visible     = true;
                            lblLoginStatus.Visible = true;
                        }
                    }
                }
            }
        }