public JsonResult Edit(SysAccount model)
 {
     try
     {
         if (model.SysAccountId > 0)
         {
             var entity = _SysAccountService.GetById(model.SysAccountId);
             //修改
             entity.EditTime    = DateTime.Now;
             entity.NickName    = model.NickName;
             entity.MobilePhone = model.MobilePhone;
             entity.BaseImageId = model.BaseImageId;
             entity.Remarks     = model.Remarks;
             _SysAccountService.Update(entity);
         }
         else
         {
             //添加
             model.PassWord   = MD5Util.GetMD5_32(model.PassWord);
             model.EditTime   = DateTime.Now;
             model.CreateTime = DateTime.Now;
             model.IsDelete   = (int)IsDeleteEnum.效;
             model.Status     = (int)EnabledEnum.效;
             _SysAccountService.Insert(model);
         }
         return(Json(new { Status = Successed.Ok }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception)
     {
         return(Json(new { Status = Successed.Error }, JsonRequestBehavior.AllowGet));
     }
 }
示例#2
0
 public ActionResult Enable(string id, bool status)
 {
     return(Json(_sysAccountService.Update(a => new SysAccount()
     {
         EnabledMark = status
     }, c => c.AccountId == id)));
 }
示例#3
0
        public ResponseModel <BCSysAccountDTO> Login(BCLoginDTO bcloginDTO)
        {
            var result = new ResponseModel <BCSysAccountDTO>();
            var data   = new BCSysAccountDTO();

            result.error_code = Result.SUCCESS;
            result.message    = "";
            var info = _sysAccountService.Login(bcloginDTO.account, bcloginDTO.password);//.SysBusinessAccount(sysBusinessAccountLoginDto.account, sysBusinessAccountLoginDto.password);

            if (info == null || info.SysAccountId <= 0)
            {
                result.error_code = Result.ERROR;
                result.message    = "您输入的帐号或密码错误,请重新输入";
                result.data       = data;
                return(result);
            }
            else
            {
                DateTime time = System.DateTime.Now;
                if (info.LoginTime.AddMonths(1) < System.DateTime.Now || string.IsNullOrWhiteSpace(info.Token))//过期
                {
                    string tokenstr = MD5Util.GetMD5_32(info.PassWord + info.SysAccountId + time.ToString("yyyy:MM:dd HH:mm:ss") + token_key);
                    data.last_loin_time          = info.LoginTime.ToString("yyyy:MM:dd HH:mm:ss");
                    data.nick_name               = info.NickName;
                    data.path                    = info.BaseImage == null ? "" : info.BaseImage.Source + info.BaseImage.Path;
                    data.phone_no                = info.MobilePhone;
                    data.sys_business_account_id = info.BusinessInfoId;
                    data.token_str               = tokenstr;
                    data.account                 = info.Account;
                    info.Token                   = tokenstr;
                    info.LoginTime               = time;
                    _sysAccountService.Update(info);
                    result.data = data;
                }
                else
                {
                    data.last_loin_time          = info.LoginTime.ToString("yyyy:MM:dd HH:mm:ss");
                    data.nick_name               = info.NickName;
                    data.path                    = info.BaseImage == null ? "" : info.BaseImage.Source + info.BaseImage.Path;
                    data.phone_no                = info.MobilePhone;
                    data.sys_business_account_id = info.BusinessInfoId;
                    data.token_str               = info.Token;
                    data.account                 = info.Account;
                    info.LoginTime               = System.DateTime.Now;
                    _sysAccountService.Update(info);
                    result.data = data;
                }
            }
            return(result);
        }
示例#4
0
        /// <summary>
        /// 重写OnActionExecuting 验证tokenStr
        /// </summary>
        /// <param name="actionContext">HttpActionContext</param>
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            var request = actionContext.Request;
            HttpResponseMessage response = actionContext.Request.CreateResponse(HttpStatusCode.OK);
            string SysBusinessAccountId = String.Empty, Token_Str = string.Empty, jsonStr = string.Empty;//, nonce = string.Empty, signature = string.Empty;
            var    result = new ResponseModel <string>();

            result.data       = "";
            result.error_code = Result.SUCCESS;
            result.message    = "";
            if (request.Headers.Contains("SysBusinessAccountId") && request.Headers.Contains("TokenStr"))
            {
                SysBusinessAccountId = HttpUtility.UrlDecode(request.Headers.GetValues("SysBusinessAccountId").FirstOrDefault());
                Token_Str            = HttpUtility.UrlDecode(request.Headers.GetValues("TokenStr").FirstOrDefault());

                if (string.IsNullOrWhiteSpace(SysBusinessAccountId) || int.Parse(SysBusinessAccountId) <= 0)
                {
                    result.error_code      = Result.ERROR;
                    result.message         = "2";
                    jsonStr                = JsonConvert.SerializeObject(result);
                    response.Content       = new StringContent(jsonStr, Encoding.UTF8);
                    actionContext.Response = response;
                    base.OnActionExecuting(actionContext);
                    return;
                }
                else if (string.IsNullOrWhiteSpace(Token_Str))
                {
                    result.error_code      = Result.ERROR;
                    result.message         = "3";
                    jsonStr                = JsonConvert.SerializeObject(result);
                    response.Content       = new StringContent(jsonStr, Encoding.UTF8);
                    actionContext.Response = response;
                    base.OnActionExecuting(actionContext);
                    return;
                }
                else if (_sysAccountService.GetAccountByToken(Token_Str) == null)//token错误
                {
                    result.error_code      = Result.ERROR;
                    result.message         = "5";
                    jsonStr                = JsonConvert.SerializeObject(result);
                    response.Content       = new StringContent(jsonStr, Encoding.UTF8);
                    actionContext.Response = response;
                    base.OnActionExecuting(actionContext);
                    return;
                }
                else
                {
                    var sysAccount = _sysAccountService.GetAccountByToken(Token_Str);
                    if (int.Parse(SysBusinessAccountId) == sysAccount.BusinessInfoId)
                    {
                        if (sysAccount.LoginTime.AddMonths(1) <= System.DateTime.Now)//登录过期
                        {
                            sysAccount.Token = "";
                            _sysAccountService.Update(sysAccount);
                            result.error_code = Result.ERROR;
                            result.message    = "6";
                            jsonStr           = JsonConvert.SerializeObject(result);
                            //jsonStr = JsonConvert.SerializeObject(new { Success = false, Msg = "4", Data = new { } });
                            response.Content       = new StringContent(jsonStr, Encoding.UTF8);
                            actionContext.Response = response;
                            base.OnActionExecuting(actionContext);
                            return;
                        }
                        else
                        {
                            base.OnActionExecuting(actionContext);
                        }
                    }
                    else//商家id错误
                    {
                        result.error_code      = Result.ERROR;
                        result.message         = "4";
                        jsonStr                = JsonConvert.SerializeObject(result);
                        response.Content       = new StringContent(jsonStr, Encoding.UTF8);
                        actionContext.Response = response;
                        base.OnActionExecuting(actionContext);
                        return;
                    }
                    //Token token = (Token)HttpRuntime.Cache.Get(SysBusinessAccountId);
                    //if (!token.Token_Str.Equals(Token_Str))
                    //{
                    //    jsonStr = JsonConvert.SerializeObject(new { Success = false, Msg = "5", Data = new { } });
                    //    response.Content = new StringContent(jsonStr, Encoding.UTF8);
                    //    actionContext.Response = response;
                    //    base.OnActionExecuting(actionContext);
                    //    return;
                    //}
                    //else if (token.Token_Str.Equals(Token_Str) && token.Erpert_Time < System.DateTime.Now)
                    //{
                    //    HttpRuntime.Cache.Remove(SysBusinessAccountId);
                    //    jsonStr = JsonConvert.SerializeObject(new { Success = false, Msg = "6", Data = new { } });
                    //    response.Content = new StringContent(jsonStr, Encoding.UTF8);
                    //    actionContext.Response = response;
                    //    base.OnActionExecuting(actionContext);
                    //    return;
                    //}
                    //else
                    //{
                    //    base.OnActionExecuting(actionContext);
                    //}
                }
            }
            else
            {
                result.error_code      = Result.ERROR;
                result.message         = "1";
                jsonStr                = JsonConvert.SerializeObject(result);
                response.Content       = new StringContent(jsonStr, Encoding.UTF8);
                actionContext.Response = response;
                base.OnActionExecuting(actionContext);
                return;
            }
        }