Пример #1
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if (txt_username.Value.Trim().Length == 0)
            {
                Message.Dialog("提示信息", "用户名不能为空!", "-1", MessageIcon.Stop, 0);
            }
            else if (txt_password.Value.Trim().Length == 0)
            {
                Message.Dialog("提示信息", "用户密码不能为空!", "-1", MessageIcon.Stop, 0);
            }
            else if (txt_checkcode.Value.Trim().Length == 0)
            {
                Message.Dialog("提示信息", "验证码不能为空!", "-1", MessageIcon.Stop, 0);
            }
            else
            {
                if (txt_checkcode.Value.Trim() != Session["ValidateCodekey"].ToString())
                {
                    Message.Dialog("提示信息", "验证码填写错误!", "-1", MessageIcon.Stop, 0);
                }
                else
                {
                    UsersBLL userBll  = new UsersBLL();
                    Users    userInfo = userBll.CheckLogin(txt_username.Value.Trim(), txt_password.Value.Trim(), true);

                    if (userInfo == null)
                    {
                        Message.Dialog("提示信息", "用户名或密码不正确!", "-1", MessageIcon.Stop, 0);
                    }
                    else
                    {
                        if (userInfo.IsLock == 1)
                        {
                            Message.Dialog("提示信息", "对不起,您的帐号被锁定,暂时不能登陆系统后台,请联系网站管理员!", "-1", MessageIcon.Stop, 0);
                        }
                        else if (userInfo.IsVerify == 0)
                        {
                            Message.Dialog("提示信息", "对不起,您的帐号还未通过审核,暂时不能登陆系统后台,请联系网站管理员!", "-1", MessageIcon.Stop, 0);
                        }
                        else
                        {
                            Session["AdminUser"] = userInfo;
                            //更新用户登陆信息
                            userBll.UpdateLoginInfo(userInfo.UID, Request.UserHostAddress);
                            Message.Dialog("提示信息", "登陆成功,正在转向管理后台!", "main_index.aspx", MessageIcon.Success, 2);
                        }
                    }
                }
            }
        }
Пример #2
0
 protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
 {
     if (identify.Text != null && identify.Text.ToString() != "")
     {
         if (identify.Text.ToString().ToLower() != Session["check"].ToString().ToLower())
         {
             Response.Write("<script lanuage=javascript>alert('您输入的验证码不正确,请重新输入!')</script>");
             identify.Text = "";
             return;
         }
         UsersBLL             adminbll = new UsersBLL();
         string               UserName = txtUserName.Text;
         string               UserPass = txtUserPass.Text;
         InventionModel.Users u        = new InventionModel.Users();
         u.UserName = UserName;
         u.Password = CJ_DBOperater.CJ.PwdSecurity(UserPass);
         if (adminbll.CheckLogin(u))
         {
             InventionModel.Users mgr = adminbll.GetUser(u.UserName);
             string m = mgr.Role.ToString();
             if (m != "管理员")
             {
                 Response.Write("<script>alert('您的权限不够,登录失败!');</script>");
                 return;
             }
             Session["UserName"] = mgr.UserName;
             Session["UserID"]   = mgr.UserId;
             Session["UserPwd"]  = mgr.Password;
             Session["class"]    = mgr.Role;
             Session["Mark"]     = mgr.UserMark;
             mgr.LoginTime       = DateTime.Now;
             adminbll.Update(mgr);//记录用户当前登录时间
             FormsAuthentication.RedirectFromLoginPage(mgr.UserName, false);
             Response.Redirect("adminindex.aspx");
         }
         else
         {
             Response.Write("<script>alert('用户名或密码有误!');</script>");
             Response.Write(" <script lanuage=javascript> location.href= './Login.aspx' </script> ");
         }
     }
     else
     {
         Response.Write("<script lanuage=javascript>alert('请输入验证码!')</script>");
     }
 }
Пример #3
0
        public void Login()
        {
            //1.
            string name     = Request.Form["username"];
            string pwd      = Request.Form["password"];
            string vcode    = Request.Form["vcode"];
            string remember = Request.Form["remember_me"];

            //2.
            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(pwd))
            {
                ErrorMsg = "不能为空";
                return;
            }
            var scode = Session["user_vcode"];

            Session["user_vcode"] = null;
            if (scode == null || !scode.ToString().Equals(vcode, StringComparison.InvariantCultureIgnoreCase))//不分大小写
            {
                ErrorMsg = "验证码错误";
                return;
            }

            //3。
            Users       user = null;
            LoginResult res  = bll.CheckLogin(name, pwd, out user);

            switch (res)
            {
            case LoginResult.InvalidUserName:
                ErrorMsg = "Invalid UserName or Pwd";
                break;

            case LoginResult.InvalidPassword:
                ErrorMsg = "Invalid UserName or Pwd";
                break;

            case LoginResult.StateError:
                ErrorMsg = "State Error";
                break;

            case LoginResult.LoginSuccessful:
                if (!string.IsNullOrEmpty(remember))
                {
                    HttpCookie cookieName = new HttpCookie("ckName")
                    {
                        Value   = name,
                        Expires = DateTime.Now.AddDays(7),
                    };
                    Response.Cookies.Add(cookieName);
                    HttpCookie cookiePwd = new HttpCookie("ckPwd")
                    {
                        Value   = pwd,
                        Expires = DateTime.Now.AddDays(7),
                    };
                    Response.Cookies.Add(cookiePwd);
                }
                //Session["LoginUser"] = user;
                //if (Request["redirect"]!=null)
                //{
                //    Response.Redirect(Request["redirect"]);
                //}

                //Response.Redirect("/index.aspx");

                string redirect = Request["redirect"] ?? "/index.aspx?AspxAutoDetectCookieSupport=1";
                //'??'-->redirect= Request["redirect"] if Request["redirect"] not null, if null go to home page
                Session["LoginUser"] = user;
                Response.Redirect(redirect);
                // Response.Redirect("/index.aspx");
                break;
            }
        }
Пример #4
0
        /// <summary>
        /// event rise when user click Agree button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAgree_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(txtUsername.Text.Trim()) && String.IsNullOrWhiteSpace(txtPassword.Text.Trim()))
            {
                CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("PleaseInputInformationLogin"),
                                                                 Common.clsLanguages.GetResource("Information"),
                                                                 Common.Config.CUSTOM_MESSAGEBOX_ICON.Information,
                                                                 Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK);
                return;
            }
            if (String.IsNullOrWhiteSpace(txtUsername.Text.Trim()))
            {
                CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("PleaseInputUsername"),
                                                                 Common.clsLanguages.GetResource("Information"),
                                                                 Common.Config.CUSTOM_MESSAGEBOX_ICON.Information,
                                                                 Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK);
                return;
            }
            if (String.IsNullOrWhiteSpace(txtPassword.Text.Trim()))
            {
                CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("PleaseInputPassword"),
                                                                 Common.clsLanguages.GetResource("Information"),
                                                                 Common.Config.CUSTOM_MESSAGEBOX_ICON.Information,
                                                                 Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK);
                return;
            }
            //if (chkAdvanced.Checked == true)
            //{
            //    string tss = txtServer.Text;
            //    tss = tss.Replace("http://", "");
            //    tss = tss.Replace("/", "");
            //    Program.urlImage = tss;
            //    Program.destopService.Url = "http://" + tss + "/VVPosService.asmx";

            //    Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            //    configuration.AppSettings.Settings["MyLastURL"].Value = tss;
            //    configuration.Save();

            //    ConfigurationManager.RefreshSection("appSettings");

            //    string APPNODE = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + ".Properties.Settings";
            //    string val = "http://" + txtServer.Text.Trim() + "/VVPosService.asmx";
            //    Common.Utility.UpdateApplicationSettings(APPNODE, "VVPosS_VVPosService_VVPosService", val);
            //}
            try
            {
                UsersBLL usersBLL     = new UsersBLL();
                string   idOrUsername = txtUsername.Text;
                string   password     = Program.ConvertStringToMD5(txtPassword.Text.Trim());
                bool     ok           = usersBLL.CheckLogin(idOrUsername, password);

                if (ok)
                {
                    // gán culture vào hệ thống
                    Common.clsLanguages.SetCulture(Common.clsLanguages.StrCulture);
                    //RolesBLL rolesBLL = new RolesBLL();
                    //Program.lstRole = rolesBLL.GetRoleOfUser(Program.users.EmployeeId);
                    if (Program.users.RoleId == "letan" || Program.users.RoleId == "admin")
                    {
                        if (string.IsNullOrEmpty(usersBLL.ErrorString))
                        {
                            string _sObjectId = usersBLL.GetObjectIdByUserId(idOrUsername).Rows[0][0].ToString();

                            ObjectBLL objectBLL = new ObjectBLL();
                            Program.FullName  = objectBLL.GetObjectByObjectId(_sObjectId).Rows[0]["FullName"].ToString();
                            Program.ImageUser = objectBLL.GetObjectByObjectId(_sObjectId).Rows[0]["Image"].ToString();

                            MainForm frm = new MainForm();
                            frm.Show();
                            txtUsername.Clear();
                            txtPassword.Clear();
                            //cbbLanguage.SelectedIndex = -1;
                            txtUsername.Focus();
                            this.Hide();
                        }
                        else
                        {
                            MessageBox.Show(usersBLL.ErrorString, Common.clsLanguages.GetResource("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("YouAreNotPermissionAccess"),
                                                                         Common.clsLanguages.GetResource("Error"),
                                                                         Common.Config.CUSTOM_MESSAGEBOX_ICON.Error,
                                                                         Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK);
                        txtUsername.Focus();
                        return;
                    }
                }
                else
                {
                    CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("LoginError"),
                                                                     Common.clsLanguages.GetResource("Error"),
                                                                     Common.Config.CUSTOM_MESSAGEBOX_ICON.Error,
                                                                     Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK);
                    return;
                }
            }
            catch (Exception ex)
            {
                string code = System.Runtime.InteropServices.Marshal.GetExceptionCode().ToString();
                if (code == "-532462766")
                {
                    CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CurrentlyTheDeviceIsNotConnectedInternet") + " - Last Link : " + Program.destopService.Url,
                                                                     Common.clsLanguages.GetResource("Information"),
                                                                     Common.Config.CUSTOM_MESSAGEBOX_ICON.Information,
                                                                     Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK);
                }
                return;
            }
        }
Пример #5
0
        private void btnAgree_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(txtUsername.Text.Trim()) && String.IsNullOrWhiteSpace(txtPassword.Text.Trim()))
            {
                CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("PleaseInputInformationLogin"),
                                                                 Common.clsLanguages.GetResource("Information"),
                                                                 Common.Config.CUSTOM_MESSAGEBOX_ICON.Information,
                                                                 Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK);
                return;
            }
            if (String.IsNullOrWhiteSpace(txtUsername.Text.Trim()))
            {
                CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("PleaseInputUsername"),
                                                                 Common.clsLanguages.GetResource("Information"),
                                                                 Common.Config.CUSTOM_MESSAGEBOX_ICON.Information,
                                                                 Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK);
                return;
            }
            if (String.IsNullOrWhiteSpace(txtPassword.Text.Trim()))
            {
                CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("PleaseInputPassword"),
                                                                 Common.clsLanguages.GetResource("Information"),
                                                                 Common.Config.CUSTOM_MESSAGEBOX_ICON.Information,
                                                                 Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK);
                return;
            }
            if (chkAdvanced.Checked == true)
            {
                //Program.destopService.Url = "http://" + txtServer.Text + ":8389/DestopService.asmx";
                string tss = txtServer.Text;
                tss = tss.Replace("http://", "");
                tss = tss.Replace("/", "");
                Program.urlImage          = tss;
                Program.destopService.Url = "http://" + tss + "/VVPosService/VVPosService.asmx";

                Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                configuration.AppSettings.Settings["MyLastURL"].Value = tss;
                configuration.Save();

                ConfigurationManager.RefreshSection("appSettings");

                //ConfigurationManager.AppSettings["MyLastURL"] = txtServer.Text;

                //ConfigurationManager.AppSettings.
            }
            try
            {
                UsersBLL usersBLL     = new UsersBLL();
                string   idOrUsername = txtUsername.Text;
                string   password     = Program.ConvertStringToMD5(txtPassword.Text.Trim());
                bool     ok           = usersBLL.CheckLogin(idOrUsername, password);

                if (ok)
                {
                    Program.RoleId = Program.user.RoleId;

                    //DataTable dt = rolesBLL.GetRoleOfUser(Program.users.RoleId);
                    //if (dt.Rows[0]["RoleName"].ToString() == "letan" || dt.Rows[0]["RoleName"].ToString() == "admin")
                    if (Program.RoleId == "admin")
                    {
                        if (string.IsNullOrEmpty(usersBLL.ErrorString))
                        {
                            //Hung 09-12-2014
                            //string _sObjectId = usersBLL.GetUserIdByUserId(idOrUsername).Rows[0][0].ToString();

                            // ObjectBLL objectBLL = new ObjectBLL();
                            Program.FullName = Program.user.UserId;//usersBLL.GetEmployeesByUserId(idOrUsername).Rows[0]["EmployeeName"].ToString();
                            //Program.ImageUser = usersBLL.GetEmployeesByUserId(idOrUsername).Rows[0]["Image"].ToString();

                            frmMain frm = new frmMain();
                            frm.Show();
                            txtUsername.Clear();
                            txtPassword.Clear();
                            cbbLanguage.SelectedIndex = -1;
                            txtUsername.Focus();
                            this.Hide();
                        }
                        else
                        {
                            MessageBox.Show(usersBLL.ErrorString, Common.clsLanguages.GetResource("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("NoRole"),
                                                                         Common.clsLanguages.GetResource("Error"),
                                                                         Common.Config.CUSTOM_MESSAGEBOX_ICON.Error,
                                                                         Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK);
                        txtUsername.Focus();
                        return;
                    }
                }
                else
                {
                    CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("LoginError"),
                                                                     Common.clsLanguages.GetResource("Error"),
                                                                     Common.Config.CUSTOM_MESSAGEBOX_ICON.Error,
                                                                     Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK);
                    return;
                }
            }
            catch (Exception)
            {
                string code = System.Runtime.InteropServices.Marshal.GetExceptionCode().ToString();
                if (code == "-532462766")
                {
                    CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CurrentlyTheDeviceIsNotConnectedInternet") + " - Last Link : " + Program.destopService.Url,
                                                                     Common.clsLanguages.GetResource("Information"),
                                                                     Common.Config.CUSTOM_MESSAGEBOX_ICON.Information,
                                                                     Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK);
                }
                return;
            }
        }