示例#1
0
      /// <summary>
      ///  处理邀请码
      /// </summary>
      /// <param name="context"></param>
      public static void InviteCode(HttpContext context)
      {
         if (context.Request.IsAuthenticated)
         {
            UserStatusEntity entity = UserAccount.CurrentStatus;
            if (entity != null && entity.invited < entity.maxinvites)
            {
               IList<string> codes = UserAccount.GetInviteCode(entity.id);//获取可用的邀请码
               if (codes != null && codes.Count > 0)
               {
                  string ret = "[";
                  foreach (string code in codes)
                  {
                     if (ret != "[") ret += ",";
                     ret += string.Format("{{\"code\":\"{0}\"}}", code);
                  }
                  ret += "]";

                  context.Response.Write(JU.Build(true, ret));
                  context.Response.End();
               }
            }
         }
         context.Response.Write(JU.Build(false, "没有可用的邀请码!"));
         context.Response.End();
      }
示例#2
0
      /// <summary>
      ///  修改密码
      /// </summary>
      /// <param name="context"></param>
      public static void ChangePassword(HttpContext context)
      {
         if (context.Request.IsAuthenticated)
         {
            string op = context.Request.Form["op"];
            string np = context.Request.Form["np"];

            if (string.IsNullOrEmpty(op) || string.IsNullOrEmpty(np)) { context.Response.Write(JU.Build(false, "输入不完整,请完整输入当前密码和新密码后再试")); return; }
            
            UserEntity user = UserAccount.Current;
            if (user != null && user.password == MU.MD5(op))
            {
               string passwd = MU.MD5(np);
               if (UserData.ChangePassword(user.id, passwd) > 0)
               {
                  user.password = passwd;
                  //TODO:notify other server change
                  context.Response.Write(JU.AJAX_SUCCESS);
                  return;
               }
            }
            else { context.Response.Write(JU.Build(false, "当前密码错误,请重新输入当前使用的密码!")); return; }
         }

         context.Response.Write(JU.Build(false,"对不起,无法修改密码,请重新登录后再试!"));
      }
示例#3
0
 private JSourceStructure(JU ju, Universe[] jus, int[] js)
     : base(new JTSourceStructure <GT, JGTSD, JECGT>(ju), new JTSourceStructure <GTT, JGTTSD, JECGTT>(ju))
 {
     this.ju = ju;
     //            this.js = js;
     //            this.jn = js.Length;
 }
示例#4
0
        //Source structure for GT or GTT
        //T in {GT,GTT}
        #region instance creation
        public JTSourceStructure(JU ju)
        {
            Debug.Assert(ju.pus.Length <= 2);
            this.ju    = ju;
            jtToJECMap = (from j in js select new Dictionary <T, JEC>()).ToArray();
#if DEBUG
            jecMergeMap = (from j in js select new Dictionary <JEC, JEC>()).ToArray();
#endif
        }
示例#5
0
        private void ProcessAvatar(HttpContext context)
        {
            HttpPostedFile fileUpload = context.Request.Files["Filedata"];

            if (fileUpload != null && fileUpload.ContentLength > 0)
            {
                int    id   = CU.ToInt(context.Request.QueryString["i"]);
                string name = context.Request.QueryString["n"];

                UserEntity user = UserAccount.Current;
                if (user != null && user.id == id)
                {
                    if (name == null)
                    {
                        name = user.www;
                    }

                    string extension = Path.GetExtension(fileUpload.FileName).ToLower();
                    string fileName  = name + extension;

                    string originalPath = @"s\o\";
                    string datepath     = DateTime.Now.ToString("yyyyMM");
                    string ofileName    = rootPath + originalPath + datepath + "\\" + fileName;
                    if (SaveFile(fileUpload, ofileName))
                    {
                        string iconFileName = rootPath + originalPath + datepath + "\\" + name + ".png";
                        int    width, height;
                        if (IU.Resize(ofileName, iconFileName, 300, 300, out width, out height))
                        {
                            if (ofileName != iconFileName)
                            {
                                File.Delete(ofileName);
                            }
                        }
                        else /*TODO: log failed!*/ } {
                        FileController.CreateAttachment(new AttachmentEntity()
                        {
                            uid          = id,
                            url          = "/s/o/" + datepath + "/" + fileName,
                            physicalpath = iconFileName,
                            type         = 1
                        });

                        context.Response.StatusCode = 200;
                        string data = "{url:'" + "/s/o/" + datepath + "/" + name + ".png" + "',width:" + width + ",height:" + height + "}";
                        context.Response.Write(JU.BuildJSON(true, data));
                        return;
                }
            }
        }

        //内部服务器错误
        context.Response.StatusCode = 500;
        context.Response.Write(JU.Build(false, "图片上传失败"));
    }
示例#6
0
 public void Add(string name, string value, string ns)
 {
     if (nsData.ContainsKey(ns))
     {
         nsData[ns] += "," + JU.SingleWithoutBrackets(name, value);
     }
     else
     {
         nsData.Add(ns, JU.SingleWithoutBrackets(name, value));
     }
 }
示例#7
0
 /// <summary>
 ///  处理用户登录请求
 /// </summary>
 /// <param name="context"></param>
 public static void Login(HttpContext context)
 {
    string name = context.Request.Form["n"];
    string pwd = context.Request.Form["p"];
    if (UserAccount.Login(name, pwd))
    {
       string from = QA.GetCookie(SC.CK_LOGIN_FROM);
       if (from == null || from.Contains("login")) from = "/home";
       context.Response.Write(JU.Build(true, from));
    }
    else context.Response.Write(JU.Build(false, ""));
 }
示例#8
0
        public static void BeFriend(HttpContext context)
        {
            if (context.Request.IsAuthenticated)
            {
                int uid = CU.ToInt(context.Request.Form["uid"]);
                int mid = CU.ToInt(context.Request.Form["mid"]);
                int eid = CU.ToInt(context.Request.Form["eid"]);

                UserAccount.ConfirmFriend(uid, mid);
                EventData.Close(eid);
                context.Response.Write(JU.Build(true, ""));
                return;
            }

            context.Response.Write(JU.Build(false, "没有登录或登录已失效,请登录后再试"));
        }
示例#9
0
        private static void Handle(HttpContext context)
        {
            string cmd = context.Request.Params["m"];

            if (!string.IsNullOrEmpty(cmd))
            {
                AjaxMethod method = AjaxFactory.Create(cmd, context);
                if (method != null)
                {
                    method(context);
                }
                else
                {
                    context.Response.Write(JU.Build(false, 404, "Ajax调用出错"));
                }
            }
        }
示例#10
0
        public static void GetDistrict(HttpContext context)
        {
            string level = context.Request.QueryString["l"];
            string pid = context.Request.QueryString["p"];
            int    l, p;

            int.TryParse(level, out l);
            int.TryParse(pid, out p);

            IList <DistrictEntity> list = District.ListDistrict(l, p);

            if (list != null && list.Count > 0)
            {
                string json = JSON.Instance.ToJSON(list);
                context.Response.Write(JU.BuildJSON(true, json));
                return;
            }

            context.Response.Write(JU.AJAX_FAIL);
        }
示例#11
0
        /// <summary>
        ///  裁减并保存用户上传的图像
        /// </summary>
        /// <param name="context"></param>
        public static void SaveAvatar(HttpContext context)
        {
            int x = CU.ToInt(context.Request.QueryString["x"]);
            int y = CU.ToInt(context.Request.QueryString["y"]);
            int w = CU.ToInt(context.Request.QueryString["w"]);
            int h = CU.ToInt(context.Request.QueryString["h"]);

            if (w == 0 || h == 0)
            {
                context.Response.Write(JU.AJAX_FAIL); return;
            }

            UserEntity user = UserAccount.Current;

            if (user != null)
            {
                //get the originalfile & crop it.
                string filePath = FileController.GetFilePhysicalPath(1, user.id);
                if (File.Exists(filePath))
                {
                    string avatarPath = context.Server.MapPath("~/") + @"\s\u\avatar\";
                    if (!Directory.Exists(avatarPath))
                    {
                        Directory.CreateDirectory(avatarPath);
                    }

                    if (IU.Crop(filePath, avatarPath + user.www + ".png", new Rectangle(x, y, w, h), 50, 50))
                    {
                        string tURL = "/s/u/avatar/" + user.www + ".png";
                        if (UserAccount.SetAvatar(tURL, user.id) > 0)
                        {
                            context.Response.Write(JU.Build(true, tURL));
                            return;
                        }
                    }
                }
            }

            context.Response.Write(JU.AJAX_FAIL);
        }
示例#12
0
      /// <summary>
      ///  响应账户注册请求
      ///  成功:1 失败:0 邀请码错误:-1
      /// </summary>
      /// <param name="context"></param>
      public static void Signup(HttpContext context)
      {
         string name = context.Request.Form["n"];
         string pwd = context.Request.Form["p"];
         string email = context.Request.Form["e"];
         string code = context.Request.Form["c"];
         string id = context.Request.Form["i"];

         if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(pwd) || string.IsNullOrEmpty(email))
         {
            context.Response.Write(JU.Build(false, "数据输入不完整或者格式不正确!"));
            context.Response.End();
         }

         if (UserAccount.Signup(name, pwd, email, code, id))
         {
            context.Response.Write(JU.Build(true, ""));
            context.Response.End();
         }

         context.Response.Write(JU.Build(false, "注册失败,请联系管理员"));
      }
示例#13
0
        public void SaveThread(HttpContext context)
        {
            if (context.Request.IsAuthenticated)
            {
                UserEntity u     = UserAccount.Current;
                int        bid   = CU.ToInt(context.Request.Form["bid"]);
                int        tid   = CU.ToInt(context.Request.Form["tid"]);
                string     name  = context.Request.Form["name"];
                string     story = context.Request.Form["story"];
                string     ip    = QA.ClientIP;

                if (tid > 0)
                {
                    int ret = Forum.SavePost(bid, tid, u.id, u.name, name, ip, story);
                    if (ret > 0)
                    {
                        //更新统计数据
                        Forum.IncThreadReplies(tid);

                        string url = string.Concat("/bbs/thread/", bid, "_", tid, ".html#", ret);
                        context.Response.Write(JU.Build(true, url));
                    }
                }
                else
                {
                    int ret = Forum.SaveThread(bid, u.id, u.name, name, ip, story);
                    if (ret > 0)
                    {
                        string url = string.Concat("/bbs/thread/", bid, "_", ret, ".html");
                        context.Response.Write(JU.Build(true, url));
                    }
                }
            }
            else
            {
                context.Response.Write(JU.Build(false, "没有权限发帖"));
            }
        }
示例#14
0
      public static void SaveRole(HttpContext context)
      {
         int id = CU.ToInt(context.Request.Form["id"]);
         string name = context.Request.Form["name"];
         string displayname = context.Request.Form["dn"];
         string description = context.Request.Form["desc"];
         string action = context.Request.Form["action"];


         RoleEntity entity = new RoleEntity()
         {
            id = id,
            name = name,
            displayname = displayname,
            description = description
         };

         int ret = 0;
         if (action == "edit") ret = RoleData.Update(entity);
         else if (action == "create") ret = RoleData.Create(entity);
         if (ret > 0) context.Response.Write(JU.Build(true, ""));
         else context.Response.Write(JU.Build(false, ""));
      }
        public IHttpActionResult Get()
        {
            var    re      = Request;
            var    headers = re.Headers;
            string token   = "";

            if (headers.Contains("APIKey"))
            {
                token = headers.GetValues("APIKey").First();
            }
            Validation validation = new Validation();
            bool       valid      = validation.CheckApiKey(token);

            if (valid) // APIKey is valid
            {
                using (incposdbEntities entity = new incposdbEntities())
                {
                    var medalsList = (from MA in entity.medalAgent
                                      join M in entity.medals on MA.medalId equals M.medalId into JM
                                      join A in entity.agents on MA.agentId equals A.agentId into JA


                                      join U in entity.users on MA.createUserId equals U.userId into JU
                                      from JMM in JM.DefaultIfEmpty()
                                      from JAA in JA.DefaultIfEmpty()


                                      from JUU in JU.DefaultIfEmpty()

                                      select new MedalAgentModel()
                    {
                        id = MA.id,
                        medalId = MA.medalId,
                        agentId = MA.agentId,

                        notes = MA.notes,
                        isActive = MA.isActive,
                        createDate = MA.createDate,
                        updateDate = MA.updateDate,
                        createUserId = MA.createUserId,
                        updateUserId = MA.updateUserId,
                        agentName = JAA.name,
                        medalName = JMM.name,

                        createUserName = JUU.username,
                    }



                                      ).Select(c => new MedalAgentModel()
                    {
                    })
                                     .ToList();

                    /*
                     *
                     * id
                     * medalId
                     * agentId
                     * offerId
                     * couponId
                     * notes
                     * isActive
                     * createDate
                     * updateDate
                     * createUserId
                     * updateUserId
                     * */
                    // can delet or not


                    if (medalsList == null)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        return(Ok(medalsList));
                    }
                }
            }
            //else
            return(NotFound());
        }
 private JSyncTemplateMaker(JU universe, Revision[] predecessorRevisions)
     : base(universe)
 {
     this.jRevisions = predecessorRevisions;
 }
 public static Universe.IEmbedTemplate make(JU universe, Revision[] predecessorRevisions, bool satEqs)
 {
     return(new JSyncTemplateMaker(universe, predecessorRevisions).make(satEqs));
 }
 public static Universe.IEmbedTemplate makeGTT(JU universe, IEnumerable <GT> gtT)
 {
     return(new JMergeTemplateMaker(universe).makeGTT(gtT));
 }
示例#19
0
        public string GetBranchesByUserId(string token)
        {
            token = TokenManager.readToken(HttpContext.Current.Request);
            var strP = TokenManager.GetPrincipal(token);

            if (strP != "0") //invalid authorization
            {
                return(TokenManager.GenerateToken(strP));
            }
            else
            {
                int userId = 0;
                IEnumerable <Claim> claims = TokenManager.getTokenClaims(token);
                foreach (Claim c in claims)
                {
                    if (c.Type == "itemId")
                    {
                        userId = int.Parse(c.Value);
                    }
                }
                using (incposdbEntities entity = new incposdbEntities())
                {
                    var List = (from S in entity.branchesUsers
                                join B in entity.branches on S.branchId equals B.branchId into JB
                                join U in entity.users on S.userId equals U.userId into JU
                                from JBB in JB.DefaultIfEmpty()
                                from JUU in JU.DefaultIfEmpty()
                                where S.userId == userId
                                select new BranchesUsersModel()
                    {
                        branchsUsersId = S.branchsUsersId,

                        branchId = S.branchId,
                        userId = S.userId,
                        createDate = S.createDate,
                        updateDate = S.updateDate,
                        createUserId = S.createUserId,
                        updateUserId = S.updateUserId,
                        // branch
                        bbranchId = JBB.branchId,
                        bcode = JBB.code,
                        bname = JBB.name,
                        baddress = JBB.address,
                        bemail = JBB.email,
                        bphone = JBB.phone,
                        bmobile = JBB.mobile,
                        bcreateDate = JBB.createDate,
                        bupdateDate = JBB.updateDate,
                        bcreateUserId = JBB.createUserId,
                        bupdateUserId = JBB.updateUserId,
                        bnotes = JBB.notes,
                        bparentId = JBB.parentId,
                        bisActive = JBB.isActive,
                        btype = JBB.type,
                        // user
                        uuserId = JUU.userId,
                        uusername = JUU.username,
                        upassword = JUU.password,
                        uname = JUU.name,
                        ulastname = JUU.lastname,
                        ujob = JUU.job,
                        uworkHours = JUU.workHours,
                        ucreateDate = JUU.createDate,
                        uupdateDate = JUU.updateDate,
                        ucreateUserId = JUU.createUserId,
                        uupdateUserId = JUU.updateUserId,
                        uphone = JUU.phone,
                        umobile = JUU.mobile,
                        uemail = JUU.email,
                        unotes = JUU.notes,
                        uaddress = JUU.address,
                        uisActive = JUU.isActive,
                        uisOnline = JUU.isOnline,

                        uimage = JUU.image,
                    }).ToList();
                    return(TokenManager.GenerateToken(List));
                }
            }
        }
 private JImportTemplateMaker(JU universe)
     : base(universe)
 {
 }
示例#21
0
 protected JTemplateMaker(JU u)
     : base(u)
 {
     //            jecgttMergeToMap = (from ju in u.js select new Dictionary<JECGTT, JECGTT>()).ToArray();
 }
 public static Universe.IEmbedTemplate make(JU universe, Function function, GTT arguments)
 {
     return(new JImportTemplateMaker(universe).make(function, arguments));
 }
示例#23
0
 public JSourceStructure(JU ju)
     : this(ju, ju.pus, ju.js)
 {
     jecTKeyToJECGTT = (from j in js select new Dictionary <JECAKey, JECGTT>()).ToArray();
     pus             = ju.pus;
 }
 public static Universe.IEmbedTemplate make(JU universe, IEnumerable <ISet <GT> > canonicalSets)
 {
     return(new JMergeTemplateMaker(universe).make(canonicalSets));
 }
 private JMergeTemplateMaker(JU universe)
     : base(universe)
 {
 }
 public static Universe.IEmbedTemplate makeOriginals(JU universe, IEnumerable <FunctionApplicationFormula> fas)
 {
     return(new JImportTemplateMaker(universe).makeOriginals(fas));
 }