Exemple #1
0
        private static IRestResponse <T> GetApiInfo(string url, object pars, Method type)
        {
            var request = new RestRequest(type);

            if (pars != null)
            {
                request.AddObject(pars);
            }
            var cm = CacheManager <UserInfo> .GetInstance();

            string uniqueKey = PubGet.GetUserKey;

            if (cm.ContainsKey(uniqueKey))
            {
                request.AddCookie(PubConst.UserUniqueKey, CookiesManager <string> .GetInstance()[PubConst.UserUniqueKey]);
            }
            var client = new RestClient(RequestInfo.HttpDomain + url);

            client.CookieContainer = new System.Net.CookieContainer();
            IRestResponse <T> reval = client.Execute <T>(request);

            if (reval.ErrorException != null)
            {
                PubMethod.WirteExp(new Exception(reval.Content));
                throw new Exception("请求出错");
            }
            return(reval);
        }
Exemple #2
0
        public JsonResult RepliesSubmit(int tid, string content, int fid)
        {
            ResultModel <string> model = new ResultModel <string>();

            _service.Command <MainOutsourcing>((db, o) =>
            {
                model.IsSuccess = false;
                if (base.IsLogin.IsFalse())
                {
                    model.ResultInfo = "-1";
                }
                else
                {
                    db.BeginTran();
                    try
                    {
                        var prePost = db.Queryable <BBS_Posts>().OrderBy(it => it.Postdatetime, OrderByType.Desc).FirstOrDefault(it => it.Posterid == _userInfo.Id);
                        if (prePost != null && (DateTime.Now - prePost.Postdatetime.TryToDate()).Seconds <= 6)
                        {
                            model.ResultInfo = "你回复的太快了,请在等"
                                               + (5 - (DateTime.Now - prePost.Postdatetime.TryToDate()).Seconds) + "秒!";
                        }
                        else
                        {
                            BBS_Posts p    = new BBS_Posts();
                            p.Title        = "";
                            p.Parentid     = tid;
                            p.Message      = content;
                            p.Fid          = fid;
                            p.Tid          = tid;
                            p.Posterid     = base._userInfo.Id;
                            p.Poster       = base._userInfo.NickName;
                            p.Lastedit     = base._userInfo.NickName;
                            p.Postdatetime = DateTime.Now;
                            p.Ip           = RequestInfo.UserAddress;
                            db.Insert(p);
                            db.Update <BBS_Topics>(" Replies=isnull([Replies],0)+1,Lastpost=@lp,Lastposter=@Lastposter,Lastposterid=@Lastposterid",
                                                   it => it.Tid == tid,
                                                   new { lp = DateTime.Now, Lastposter = _userInfo.NickName, Lastposterid = _userInfo.Id });//回复数加1
                            model.IsSuccess = true;
                            base.RemoveForumsStatisticsCache();
                            db.CommitTran();

                            //发送邮箱提醒
                            o.SendMail(base._userInfo, tid, p, db);
                            //发送站内信
                            o.SendPMS(base._userInfo, tid, p, db);
                        }
                    }
                    catch (Exception ex)
                    {
                        model.ResultInfo = "回复失败!";
                        PubMethod.WirteExp(ex);
                        db.RollbackTran();
                    }
                }
            });
            return(Json(model));
        }
Exemple #3
0
        public JsonResult RegisterSubmit(UserInfo user, string vercode, string confirmPassword, string returnUrl)
        {
            string oldPassword = user.Password;
            var    model       = new ResultModel <string>();

            _service.Command <HomeOutsourcing>((db, o) =>
            {
                ExpCheck.Exception(user.UserName.IsNullOrEmpty() || user.Password.IsNullOrEmpty(), "用户名和密码不能为空!");
                ExpCheck.Exception(user.UserName.IsEamil().IsFalse(), "不是有效邮箱!");
                ExpCheck.Exception(user.NickName.IsNullOrEmpty(), "妮称不能为空!");
                ExpCheck.Exception(user.Password != confirmPassword, "两次密码不一致!");
                user.Password = new EncryptSugar().MD5(user.Password);
                var sm        = SessionManager <string> .GetInstance();
                var severCode = sm[PubConst.SessionVerifyCode];
                try
                {
                    if (oldPassword.Length < 6 || oldPassword.Length > 16)
                    {
                        model.IsSuccess  = false;
                        model.ResultInfo = "密码长度为6-16个字符";
                    }
                    else if (severCode != vercode)
                    {
                        model.IsSuccess  = false;
                        model.ResultInfo = "验证码不正确!";
                    }
                    else
                    {
                        var isAny = db.Queryable <UserInfo>().Any(it => it.UserName == user.UserName);
                        if (isAny)
                        {
                            model.IsSuccess  = false;
                            model.ResultInfo = "邮箱已经被注册!";
                        }
                        else
                        {
                            user.RoleId      = PubEnum.RoleType.User.TryToInt();
                            user.CreateTime  = DateTime.Now;
                            var id           = db.Insert(user).ObjToInt();
                            var loginUser    = db.Queryable <UserInfo>().InSingle(id);
                            var cm           = CacheManager <UserInfo> .GetInstance();
                            string uniqueKey = PubGet.GetUserKey;
                            cm.Add(uniqueKey, loginUser, cm.Day * 365);//保存一年
                            model.IsSuccess  = true;
                            model.ResultInfo = returnUrl;
                            RemoveNewUserListCache();
                        }
                    }
                }
                catch (Exception ex)
                {
                    PubMethod.WirteExp(ex);
                    model.IsSuccess  = false;
                    model.ResultInfo = "用户注册失败,请联系我们!";
                }
            });
            return(Json(model));
        }
Exemple #4
0
        public JsonResult AskSubmit(short fid, string title, string content, string vercode, int rate = 0, int id = 0)
        {
            ResultModel <string> model = new ResultModel <string>();

            _service.Command <MainOutsourcing>((db, o) =>
            {
                Check.Exception(fid == 0 || title.IsNullOrEmpty() || content.IsNullOrEmpty() || vercode.IsNullOrEmpty(), "参数不合法!");
                Check.Exception(title.Length < 5 && content.Length < 20 || content.Length > 1000000, "参数不合法!");
                Check.Exception(base.GetForumsList != null && base.GetForumsList.Any(it => it.Fid == fid).IsFalse(), "参数不合法!");
                var sm          = SessionManager <string> .GetInstance();
                var severCode   = sm[PubConst.SessionVerifyCode];
                model.IsSuccess = false;
                if (vercode != severCode)
                {
                    model.ResultInfo = "验证码错误!";
                }
                else if (IsLogin.IsFalse())
                {
                    model.ResultInfo = "对不起您还没有登录!";
                }
                else
                {
                    try
                    {
                        db.BeginTran();
                        var isAdd = id == 0;
                        if (isAdd)
                        {
                            //插贴子标题
                            BBS_Topics t = o.GetTopics(fid, title, rate, _userInfo);
                            var tid      = db.Insert(t).ObjToInt();
                            t.Tid        = tid;
                            //插贴子主体
                            BBS_Posts p = o.GetPosts(fid, content, _userInfo, t);
                            db.Insert(p);
                        }
                        else
                        {
                            var topics = db.Queryable <BBS_Topics>().InSingle(id);
                            Check.Exception(topics.Posterid != _userInfo.Id && _userInfo.RoleId == PubEnum.RoleType.User.TryToInt(), "您没有权限修改!");
                            db.Update <BBS_Topics>(new { Title = title, Rate = rate, Fid = fid }, it => it.Tid == id);
                            db.Update <BBS_Posts>(new { Title = title, Rate = rate, Fid = fid, Message = content }, it => it.Tid == id && it.Parentid == 0);
                        }
                        db.CommitTran();
                        model.IsSuccess = true;
                        base.RemoveForumsStatisticsCache();//清除统计缓存
                    }
                    catch (Exception ex)
                    {
                        model.ResultInfo = "发布失败!";
                        db.RollbackTran();
                        PubMethod.WirteExp(ex);
                    }
                }
            });
            return(Json(model));
        }
Exemple #5
0
        public ActionResult CallBack(string state)
        {
            var current = OAuth2Factory.Current;

            if (current.openID.IsNullOrEmpty())
            {
                return(Content("第三方登录失败!"));
            }
            _service.Command <OauthOutsourcing>((db, o) =>
            {
                var pwd = new EncryptSugar().MD5(RandomSugar.GetRandomString(10));
                try
                {
                    var userMapping = db.Queryable <UserOAuthMapping>().SingleOrDefault(it => it.AppId == current.openID);
                    if (userMapping == null)//注册
                    {
                        db.BeginTran();
                        UserInfo u          = o.GetUser(current, pwd);
                        var id              = db.Insert(u).ObjToInt();
                        UserOAuthMapping um = o.GetUserOauthMapping(current, id);
                        db.Insert(um);
                        db.CommitTran();
                        userMapping = um;
                        RemoveNewUserListCache();
                    }
                    var user = db.Queryable <UserInfo>().InSingle(userMapping.UserId);
                    o.SaveAvatar(db, user);
                    var cm           = CacheManager <UserInfo> .GetInstance();
                    string uniqueKey = PubGet.GetUserKey;
                    cm.Add(uniqueKey, user, cm.Day * 365);//保存一年
                    LoginHistory lh = new LoginHistory()
                    {
                        CreateDate = DateTime.Now,
                        IsDeleted  = false,
                        Uid        = user.Id,
                        UniqueKey  = uniqueKey
                    };
                    db.Insert(lh);
                }
                catch (Exception ex)
                {
                    PubMethod.WirteExp(ex);
                    db.RollbackTran();
                    throw new Exception("第三方登录注册失败!" + ex.Message);
                }
            });
            return(this.Redirect("~/ask"));
        }
        public JsonResult UploadAvatar()
        {
            ResultModel <string> model = new ResultModel <string>();

            if (base.IsLogin.IsFalse())
            {
                model.ResultInfo = "您还没有登录!";
                return(Json(model, JsonRequestBehavior.AllowGet));
            }
            try
            {
                _service.Command <UserCenterOutsourcing>((db, o) =>
                {
                    var imgObj = new UploadImage();
                    var file   = Request.Files[0];
                    if (file.ContentLength / 1024.0 / 1024.0 > 1)
                    {
                        model.ResultInfo = "上传图片不能超过一M!";
                    }
                    else if (file.ContentType.IsIn("image/png", "image/gif", "image/jpg", "image/jpeg").IsFalse())
                    {
                        model.ResultInfo = "上传失败,您的图片不是PNG GIF JPG 格式!";
                    }
                    else
                    {
                        model.IsSuccess  = true;
                        string webPath   = "/_theme/img/avatar" + _userInfo.Id + ".jpg";
                        string savePath  = FileSugar.GetMapPath("~" + webPath);
                        string smallPath = FileSugar.GetMapPath("~/_theme/img/_avatar" + _userInfo.Id + ".jpg");
                        file.SaveAs(savePath);
                        model.ResultInfo = Url.Content("~/" + webPath) + "?r=" + Guid.NewGuid();
                        imgObj.CreateSmallPhoto(savePath, 100, 100, smallPath);//生成缩略图
                        FileSugar.DeleteFile(savePath);
                        FileSugar.Move(smallPath, savePath);
                        db.Update <UserInfo>(new { avatar = webPath + "?r=" + RandomSugar.GetRandomNum(5) }, it => it.Id == _userInfo.Id);
                        RestCurrentUserCache();
                    }
                });
                return(Json(model));
            }
            catch (Exception ex)
            {
                PubMethod.WirteExp(ex);
                model.ResultInfo = "上传失败!";
            }
            return(Json(model, JsonRequestBehavior.AllowGet));
        }
 /// <summary>
 /// 将错误信息写入日志
 /// </summary>
 /// <param name="ex"></param>
 private static void WriteExMessage(Exception ex)
 {
     PubMethod.WirteExp(ex);
 }