예제 #1
0
        public HttpResponseMessage Sign([FromBody] LoginParameter loginPara)
        {
            string  res      = mUserMgr.Login(loginPara.MobileOrEmail, loginPara.Password);
            MsgInfo loginMsg = JsonConvert.DeserializeObject <MsgInfo>(res);

            if (!loginMsg.IsError)
            {
                LoginUsers loginUser   = JsonConvert.DeserializeObject <LoginUsers>(loginMsg.Msg);
                string     strUserData = JsonConvert.SerializeObject(loginUser);


                //保存身份信息
                FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket(1, loginUser.Mobile, DateTime.Now, DateTime.Now.AddHours(12), false, strUserData);

                CacheHelper.Add("LoginKey_" + Guid.NewGuid(), FormsAuthentication.Encrypt(Ticket));



                //CookieHelper.Add(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(Ticket), RootDomain);//加密身份信息,保存至Cookie
                loginMsg.Msg = loginPara.ReturnUrl;
                if (loginPara.IsRemember)
                {
                    CookieHelper.Add("remember", loginUser.Mobile + "$" + Security.DESEncrypt(loginPara.Password), RootDomain);
                }
                else
                {
                    CookieHelper.Remove("remember");
                }
            }
            return(loginMsg.toJson());
        }
예제 #2
0
        public HttpResponseMessage Post([FromBody] Register value)
        {
            UserInfo user = new UserInfo
            {
                CreateDate = DateTime.Now,
                CreateIP   = "",
                Mobile     = value.Mobile,
                Email      = Guid.NewGuid().ToString(),
                Status     = (int)UserStatusEnum.正常,
                Password   = Security.DESEncrypt(value.Password)
            };
            MsgInfo returnMsg = new MsgInfo {
                IsError = false,
                Msg     = "",
                MsgNo   = (int)ErrorEnum.成功
            };

            UserManager userMgr = new UserManager();
            int         id      = userMgr.Create(user);

            if (id > 0)
            {
                returnMsg.Msg = "成功";
            }
            else
            {
                returnMsg.Msg = "失败";
            }
            return(returnMsg.toJson());
        }
예제 #3
0
        public HttpResponseMessage SignOut()
        {
            CookieHelper.Remove(FormsAuthentication.FormsCookieName, RootDomain);//移除Cookie
            MsgInfo msgInfo = new MsgInfo {
                IsError = false,
                Msg     = "/Login.html",
                MsgNo   = 1
            };

            return(msgInfo.toJson());
        }
예제 #4
0
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            //if (AnonymousPage.Contains(actionContext.ActionDescriptor.ControllerDescriptor.ControllerName))
            return;

            string v = Convert.ToString(HttpContext.Current.Session["a"]);

            //如果不存在身份信息
            if (CheckLogin)
            {
                MsgInfo msgInfo = new MsgInfo
                {
                    IsError = true,
                    Msg     = "您已超时或未登陆,重新登陆",
                    MsgNo   = (int)ErrorEnum.超时未登录
                };
                actionContext.Response = msgInfo.toJson();
                //actionContext.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized);
            }
        }