Exemple #1
0
        private void btn_login_Click(object sender, EventArgs e)
        {
            //获取用户输入的信息
            string name = cb_user.Text.Trim();
            string pwd  = txt_password.Text.Trim();

            UserInfoBll uiBll      = new UserInfoBll();
            LoginState  loginState = uiBll.Login(name, pwd);

            switch (loginState)
            {
            case LoginState.Ok:
                //将员工级别传递过去
                UserInfo.CurrentLevel = UserInfo.UserLevel.Technician;
                LoginEvent.Invoke("工程师");
                this.Close();
                break;

            case LoginState.NameError:
                MessageBox.Show("用户名错误");
                break;

            case LoginState.PwdError:
                MessageBox.Show("密码错误");
                break;
            }
        }
        public ApiResult <string> Login(string name, string pass)
        {
            ApiResult <string> result = new ApiResult <string>();

            UserInfo user = bll.Login(name, pass);  // 登陆

            if (user != null)
            {
                Dictionary <string, object> dic = new Dictionary <string, object>();// 创建内容
                dic.Add("Id", user.Id);
                dic.Add("Name", user.Name);
                dic.Add("Url", user.Url);

                JWTHelper helper = new JWTHelper();
                string    token  = helper.GetToken(dic, 1200);// 获取令牌

                result.Code   = 0;
                result.Msg    = "成功";
                result.Result = token;
            }
            else
            {
                result.Code = 1;
                result.Msg  = "用户名或密码错误";
            }
            return(result);
        }
Exemple #3
0
 public void LoginTest()
 {
     int             systemId = 0;
     int             userId   = 0;
     string          userName = "";
     List <RoleInfo> roleList = null;
     UserInfoBll     userInfo = new UserInfoBll();
     int             rlt      = userInfo.Login(Consts.ConstValue.SystemCode, "admin", "admin", out systemId, out userId, out userName, out roleList);
 }
Exemple #4
0
        public void LoginTest()
        {
            int systemId = 0;
            int userId = 0; 
            string userName = "";
            List<RoleInfo> roleList = null;
            UserInfoBll userInfo = new UserInfoBll();
            int rlt = userInfo.Login(Consts.ConstValue.SystemCode, "admin", "admin", out systemId, out userId, out userName, out roleList);

        }
Exemple #5
0
        public string Login(string username, string password)
        {
            var user = UserInfoBll.Login(username, password);

            if (user == null)
            {
                return(string.Empty);
            }
            string token = Guid.NewGuid().ToString().MDString();
            bool   b     = RedisHelper.SetString(token, user, TimeSpan.FromMinutes(20));

            return(b ? token : string.Empty);
        }
Exemple #6
0
 public int Login(dynamic info)
 {
     try
     {
         string account = info.UserAccount;
         string pwd     = info.UserPwd;
         return(ubll.Login(account, pwd));
     }
     catch (Exception)
     {
         return(0);
     }
 }
Exemple #7
0
        public ActionResult Login(string username, string password, string valid, string remem)
        {
            string validSession = Session.GetByCookieRedis <string>("valid") ?? String.Empty; //将验证码从Session中取出来,用于登录验证比较

            if (String.IsNullOrEmpty(validSession) || !valid.Trim().Equals(validSession, StringComparison.InvariantCultureIgnoreCase))
            {
                return(ResultData(null, false, "验证码错误"));
            }

            Session.RemoveByCookieRedis("valid"); //验证成功就销毁验证码Session,非常重要
            if (String.IsNullOrEmpty(username.Trim()) || String.IsNullOrEmpty(password.Trim()))
            {
                return(ResultData(null, false, "用户名或密码不能为空"));
            }

            var userInfo = UserInfoBll.Login(username, password);

            if (userInfo != null)
            {
                Session.SetByRedis(userInfo);
                if (remem.Trim().Contains(new[] { "on", "true" })) //是否记住登录
                {
                    HttpCookie userCookie = new HttpCookie("username", Server.UrlEncode(username.Trim()));
                    Response.Cookies.Add(userCookie);
                    userCookie.Expires = DateTime.Now.AddDays(7);
                    HttpCookie passCookie = new HttpCookie("password", password.Trim().DesEncrypt(ConfigurationManager.AppSettings["BaiduAK"]))
                    {
                        Expires = DateTime.Now.AddDays(7)
                    };
                    Response.Cookies.Add(passCookie);
                }
#if !DEBUG
                HangfireHelper.CreateJob(typeof(IHangfireBackJob), "LoginRecord", "default", userInfo, Request.UserHostAddress);
#endif
                string refer = CookieHelper.GetCookieValue("refer");
                if (string.IsNullOrEmpty(refer))
                {
                    return(ResultData(null, true, "/"));
                }

                return(ResultData(null, true, refer));
            }

            return(ResultData(null, false, "用户名或密码错误"));
        }
Exemple #8
0
        /// <summary>
        /// 登录页
        /// </summary>
        /// <returns></returns>
        public ActionResult Login()
        {
            string from = Request["ReturnUrl"];

            if (!string.IsNullOrEmpty(from))
            {
                from = Server.UrlDecode(from);
                CookieHelper.SetCookie("refer", from);
            }

            if (Session.GetByCookieRedis <UserInfoDto>() != null)
            {
                if (string.IsNullOrEmpty(from))
                {
                    return(RedirectToAction("Index", "Home"));
                }

                return(Redirect(from));
            }

            if (Request.Cookies.Count > 2)
            {
                string name     = CookieHelper.GetCookieValue("username");
                string pwd      = CookieHelper.GetCookieValue("password")?.DesDecrypt(ConfigurationManager.AppSettings["BaiduAK"]);
                var    userInfo = UserInfoBll.Login(name, pwd);
                if (userInfo != null)
                {
                    CookieHelper.SetCookie("username", name, DateTime.Now.AddDays(7));
                    CookieHelper.SetCookie("password", CookieHelper.GetCookieValue("password"), DateTime.Now.AddDays(7));
                    Session.SetByRedis(userInfo);
                    HangfireHelper.CreateJob(typeof(IHangfireBackJob), "LoginRecord", "default", userInfo, Request.UserHostAddress);
                    if (string.IsNullOrEmpty(from))
                    {
                        return(RedirectToAction("Index", "Home"));
                    }

                    return(Redirect(from));
                }
            }

            return(View());
        }
Exemple #9
0
        /// <summary>在调用操作方法前调用。</summary>
        /// <param name="filterContext">有关当前请求和操作的信息。</param>
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
            if (filterContext.HttpContext.Request.HttpMethod.Equals("GET", StringComparison.InvariantCultureIgnoreCase))//get方式的多半是页面
            {
                UserInfoOutputDto user = filterContext.HttpContext.Session.GetByRedis <UserInfoOutputDto>(SessionKey.UserInfo);
#if DEBUG
                user = UserInfoBll.GetByUsername("masuit").Mapper <UserInfoOutputDto>();
                Session.SetByRedis(SessionKey.UserInfo, user);
#endif
                if (user == null && Request.Cookies.Count > 2)//执行自动登录
                {
                    string name     = CookieHelper.GetCookieValue("username");
                    string pwd      = CookieHelper.GetCookieValue("password")?.DesDecrypt(ConfigurationManager.AppSettings["BaiduAK"]);
                    var    userInfo = UserInfoBll.Login(name, pwd);
                    if (userInfo != null)
                    {
                        CookieHelper.SetCookie("username", name, DateTime.Now.AddDays(7));
                        CookieHelper.SetCookie("password", CookieHelper.GetCookieValue("password"), DateTime.Now.AddDays(7));
                        Session.SetByRedis(SessionKey.UserInfo, userInfo);
                    }
                }
            }
            else
            {
                if (ModelState.IsValid)
                {
                    return;
                }
                List <string> errmsgs = new List <string>();
                ModelState.ForEach(kv => kv.Value.Errors.ForEach(error => errmsgs.Add(error.ErrorMessage)));
                if (errmsgs.Count > 1)
                {
                    for (var i = 0; i < errmsgs.Count; i++)
                    {
                        errmsgs[i] = i + 1 + ". " + errmsgs[i];
                    }
                }
                filterContext.Result = ResultData(errmsgs, false, "数据校验失败,错误信息:" + string.Join(" | ", errmsgs), true, HttpStatusCode.BadRequest);
            }
        }
Exemple #10
0
        private void OKbutton_Click(object sender, EventArgs e)
        {
            string oldPwd   = txt_oldPassword.Text.Trim();
            string newPwd   = txt_newPassword.Text.Trim();
            string finalPwd = txt_finalPassword.Text.Trim();

            UserInfoBll uiBll = new UserInfoBll();
            //首先确认旧密码是否正确
            LoginState login = uiBll.Login(user, oldPwd);

            if (LoginState.PwdError == login)
            {
                MessageBox.Show("原始密码错误!");
                return;
            }

            if (!newPwd.Equals(finalPwd))
            {
                MessageBox.Show("确认密码和新密码不一致!");
                return;
            }
            //开始修改密码
            UserInfo ui = new UserInfo()
            {
                Name = user,
                Pwd  = finalPwd
            };

            if (uiBll.AlterPwd(ui))
            {
                MessageBox.Show("密码修改成功");
                this.Close();
            }
            else
            {
                MessageBox.Show("密码修改失败,请稍后再试!");
            }
        }
Exemple #11
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            string userCode = this.txtUserCode.Text.Trim();
            string userPwd  = this.txtUserPwd.Text.Trim();

            #region 检查输入
            if (string.IsNullOrEmpty(userCode))
            {
                MessageBox.Show("账号不能为空");
                return;
            }
            if (string.IsNullOrEmpty(userPwd))
            {
                MessageBox.Show("密码不能为空");
                return;
            }
            #endregion

            #region 判断是否登录成功
            LoginState loginState = uiBll.Login(userCode, userPwd);
            if (loginState == LoginState.WithoutAcc)
            {
                MessageBox.Show("无此账户");
            }
            else if (loginState == LoginState.Failure)
            {
                MessageBox.Show("账号或密码输入错误");
            }
            else if (loginState == LoginState.Success)
            {
                FormMain main = new FormMain();
                this.Hide();
                main.Show();
            }
            #endregion
        }