Ejemplo n.º 1
0
        /// <summary>
        /// 到数据库进行校验登录信息
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="cityid">城市ID</param>
        /// <param name="User">当前登录用户信息</param>
        /// <returns></returns>
        private bool CheckUser(string username, string password, string cityid, ref tblFW_User User)
        {
            bool bOk = true;

            RuletblFW_User ruleUser = new RuletblFW_User();

            DDYZ.Ensis.Rule.BusinessRule.UserManage.Common comm = new DDYZ.Ensis.Rule.BusinessRule.UserManage.Common();

            tblFW_User objUser = ruleUser.ByUserName(username, cityid);

            User = objUser;
            if (objUser == null || objUser.IsEmpty)
            {
                bOk = false;
            }
            if (objUser.fldActive == false)
            {
                bOk = false;
            }
            if (objUser.fldPassword != password)
            {
                bOk = false;
            }

            return(bOk);
        }
        /// <summary>
        /// 到数据库进行校验登录信息
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="massge">提示信息</param>
        /// <returns></returns>
        private bool CheckUser(string username, string password, ref string massge)
        {
            bool bOk = true;

            RuletblFW_User ruleUser = new RuletblFW_User();

            using (YYPlayContext db = new YYPlayContext())
            {
                tbleMerchant tbleMerchant = (from x in db.tbleMerchant
                                             where x.fldMerchID == username &&
                                             x.fldMaPass == password
                                             select x).SingleOrDefault();

                if (tbleMerchant == null)
                {
                    bOk = false;
                }



                return(bOk);
            }
        }
Ejemplo n.º 3
0
        public HttpResponseMessage UserInfo(string token)
        {
            string     result = string.Empty;
            RuleCommon rule   = new RuleCommon();

            try
            {
                tblFW_User objUser = new tblFW_User();

                //var strTicket = FormsAuthentication.Decrypt(token).UserData;

                IJsonSerializer   serializer = new JsonNetSerializer();
                IDateTimeProvider provider   = new UtcDateTimeProvider();
                IJwtValidator     validator  = new JwtValidator(serializer, provider);
                IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder();
                IJwtDecoder       decoder    = new JwtDecoder(serializer, validator, urlEncoder);
                string            json       = "[" + decoder.Decode(token, "YYplay", verify: true).ToString() + "]";//token为之前生成的字符串
                string            userName   = "";
                JArray            jsonObj    = JArray.Parse(json);
                string            password   = "";
                for (int i = 0; i < jsonObj.Count; i++)
                {
                    userName = jsonObj[i]["name"].ToString();
                    password = jsonObj[i]["pass"].ToString();
                }



                RuletblFW_User users = new RuletblFW_User();
                if (CheckUser(userName, password, "", ref objUser) == false)
                {
                    result = rule.JsonStr("error", "请重新登录,获取Token!", "");
                    return(new HttpResponseMessage {
                        Content = new StringContent(result, System.Text.Encoding.UTF8, "application/json")
                    });
                }



                LoginInfo lginfo = new LoginInfo();
                lginfo.userid       = objUser.fldAutoID.ToString();
                lginfo.roleid       = objUser.fldRoleID;
                lginfo.token        = "";
                lginfo.cityid       = objUser.fldCityID.ToString();
                lginfo.username     = objUser.fldUserName;
                lginfo.roles        = objUser.fldroles;
                lginfo.introduction = objUser.fldintroduction;
                lginfo.avatar       = objUser.fldavatar;
                result = rule.JsonStr("ok", "", lginfo);
                return(new HttpResponseMessage {
                    Content = new StringContent(result, System.Text.Encoding.UTF8, "application/json")
                });
            }
            catch (Exception e)
            {
                result = rule.JsonStr("error", e.Message, "");
                return(new HttpResponseMessage {
                    Content = new StringContent(result, System.Text.Encoding.UTF8, "application/json")
                });
            }
        }