public HttpResponseMessage ChangePassword()
        {
            string  oldpwd  = HttpContext.Current.Request["oldpwd"];
            string  newpwd  = HttpContext.Current.Request["newpwd"];
            JObject data    = new JObject();
            int     Status  = 0;
            string  Message = "操作成功";

            var userInfo = HttpContext.Current.GetOwinContext().Authentication.User.Claims;
            int mid      = Convert.ToInt32(userInfo.ElementAt(0).Value);

            EMC.Model.tb001 model = EMC.DbUtility.Utility.GetModel <EMC.Model.tb001>(mid);
            if (model.F003TB001 != EMC.Com.Common.StringToMD5(oldpwd))
            {
                Status  = 1;
                Message = "原始密码不正确";
            }
            else
            {
                model.F003TB001 = EMC.Com.Common.StringToMD5(newpwd);
                model.F200TB001 = mid;
                model.F201TB001 = DateTime.Now;
                EMC.DbUtility.Utility.Update <EMC.Model.tb001>(model);
            }

            ReturnJson.Add("Status", Status);
            ReturnJson.Add("Message", Message);
            ReturnJson.Add("data", data);
            return(ResponseJson(this.ReturnJson.ToString()));
        }
        public HttpResponseMessage GetSystemConfig()
        {
            JObject data    = new JObject();
            int     Status  = 0;
            string  Message = "操作成功";

            var userInfo = HttpContext.Current.GetOwinContext().Authentication.User.Claims;
            int mid      = Convert.ToInt32(userInfo.ElementAt(0).Value);

            EMC.Model.tb001 model = EMC.DbUtility.Utility.GetModel <EMC.Model.tb001>(mid);
            data.Add("AdminName", model.F001TB001);

            List <EMC.Model.tb003> menuList = dal_System.GetMainMenu(mid);
            JArray listMenu = new JArray();

            foreach (EMC.Model.tb003 modelTB003 in menuList)
            {
                JObject j = new JObject();
                j.Add("ID", modelTB003.NOIDTB003);
                j.Add("Name", modelTB003.F001TB003);
                listMenu.Add(j);
            }
            data.Add("MainMenu", listMenu);

            ReturnJson.Add("Status", Status);
            ReturnJson.Add("Message", Message);
            ReturnJson.Add("data", data);
            return(ResponseJson(this.ReturnJson.ToString()));
        }
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            string adminID = "";

            #region 登陆验证
            string          userName = context.UserName;
            string          password = EMC.Com.Common.StringToMD5(context.Password);
            string          message  = "";
            EMC.Model.tb001 model    = null;

            int res = dal.AdminLogin(userName, password, EMC.Com.Common.GetIPAddress(), ref model, ref message);
            if (res != 0)
            {
                context.SetError("invalid_grant", message);
                return;
            }
            else
            {
                adminID = model.NOIDTB001.ToString();
            }
            #endregion
            var identity = new ClaimsIdentity(context.Options.AuthenticationType);
            identity.AddClaim(new Claim("adminID", adminID));
            context.Validated(identity);
            await base.GrantResourceOwnerCredentials(context);
        }
Beispiel #4
0
        /// <summary>
        /// 管理员登录
        /// </summary>
        /// <returns>0=成功;1=帐号密码错误;2=帐号已经过期;3=帐号已经锁定</returns>
        public int AdminLogin(string F002TB001, string F003TB001, string F006TB001, ref EMC.Model.tb001 model, ref string Message)
        {
            int res = 1;

            #region 管理员登录
            string sqlStr = "select * from TB001 where F002TB001={0} and F003TB001={1}";
            model = db.T(sqlStr, F002TB001, F003TB001).ExecuteDynamicObject();
            if (model != null)
            {
                if (model.F004TB001 > DateTime.Now || model.F005TB001 < DateTime.Now)
                {
                    res     = 2;
                    Message = "帐号已经过期";
                }
                else if (model.F099TB001 != 1)
                {
                    res     = 3;
                    Message = "帐号已经锁定";
                }
                else
                {
                    res     = 0;
                    Message = "登录成功";
                }
            }
            else
            {
                res     = 1;
                Message = "用户名或者密码错误";
            }
            #endregion
            #region 插入登录日志
            try
            {
                using (var tran = db.BeginTransaction())
                {
                    //更新最后登录时间日志
                    if (res == 0)
                    {
                        tran.T("update TB001 set F006TB001={1},F007TB001=now() where NOIDTB001={0}", model.NOIDTB001, F006TB001).ExecuteNonQuery();
                    }

                    //插入登录日志
                    Model.tb1001 model_TB1001 = new Model.tb1001();
                    model_TB1001.F001TB1001 = F002TB001;
                    model_TB1001.F002TB1001 = F003TB001;
                    model_TB1001.F003TB1001 = res;
                    model_TB1001.F004TB1001 = Message;
                    model_TB1001.F005TB1001 = F006TB001;
                    model_TB1001.TIMETB1001 = DateTime.Now;

                    TModel tmodel = EMC.DbUtility.Utility.GetInsertTModel <EMC.Model.tb1001>(model_TB1001);
                    tran.T(tmodel.SQL, tmodel.ParameterValues).ExecuteNonQuery();

                    tran.Commit();
                }
            }
            catch
            {
                //插入日志失败 暂不做处理
            }
            #endregion
            return(res);
        }