Esempio n. 1
0
        public ActionResult Create(string spaceKey, string microblogBody, string tenantTypeId = null, long ownerId = 0, string imageUrl = null)
        {
            if (string.IsNullOrEmpty(microblogBody))
                return Json(new { MessageType = StatusMessageType.Error, MessageContent = "内容不能为空!" });
            if (!ValidateContentLength(microblogBody))
                return Json(new { MessageType = StatusMessageType.Error, MessageContent = "内容不能超过140个字!" });

            //当前用户登录
            IUser currentUser = UserContext.CurrentUser;

            bool isBanned = ModelState.HasBannedWord();
            MicroblogEntity entity = MicroblogEntity.New();
            entity.Author = currentUser.DisplayName;
            entity.Body = Tunynet.Utilities.WebUtility.HtmlEncode(microblogBody);
            entity.PostWay = PostWay.Web;
            entity.TenantTypeId = !string.IsNullOrEmpty(tenantTypeId) ? tenantTypeId : TenantTypeIds.Instance().User();
            entity.UserId = currentUser.UserId;
            entity.OwnerId = ownerId > 0 ? ownerId : currentUser.UserId;

            if (!authorizer.Microblog_Create(entity.TenantTypeId, entity.OwnerId))
                return HttpNotFound();

            //判断是否当前有,图片附件
            HttpCookie cookie = Request.Cookies["microblog_PhotoExists"];
            if (cookie != null && cookie.Value.Trim().ToLower().Equals("true"))
            {
                entity.HasPhoto = true;
                cookie.Value = "";
                Response.Cookies.Set(cookie);
            }

            if (!string.IsNullOrEmpty(imageUrl))
            {
                //by zhaoyx:获取到的图片地址如果带有“-”字符的话,会被ModelBinder屏蔽掉,导致图片无法加载
                imageUrl = Request["imageUrl"];
                entity.HasPhoto = true;
            }

            bool isSuccess = false;
            if (!isBanned)
            {
                isSuccess = microblogService.Create(entity) > 0;
            }

            //by zhengw:
            if (isSuccess)
            {
                //处理imageUrl
                if (!string.IsNullOrEmpty(imageUrl))
                    DownloadRemoteImage(imageUrl, entity.MicroblogId);

                //同步微博
                var accountBindingService = new AccountBindingService();
                foreach (var accountType in accountBindingService.GetAccountTypes(true, true))
                {
                    bool isSync = Request.Form.GetBool("sync_" + accountType.AccountTypeKey, false);
                    if (isSync)
                    {
                        var account = accountBindingService.GetAccountBinding(currentUser.UserId, accountType.AccountTypeKey);
                        if (account != null)
                        {
                            var thirdAccountGetter = ThirdAccountGetterFactory.GetThirdAccountGetter(accountType.AccountTypeKey);
                            if (entity.HasPhoto)
                            {
                                byte[] bytes = null;
                                var attachments = attachmentService.GetsByAssociateId(entity.MicroblogId);
                                string fileName = null;
                                if (attachments.Count() > 0)
                                {
                                    var attachment = attachments.First();
                                    IStoreProvider storeProvider = DIContainer.Resolve<IStoreProvider>();
                                    IStoreFile storeFile = storeProvider.GetResizedImage(attachment.GetRelativePath(), attachment.FileName, new Size(405, 600), Tunynet.Imaging.ResizeMethod.KeepAspectRatio);
                                    using (Stream stream = storeFile.OpenReadStream())
                                    {
                                        bytes = StreamToBytes(stream);
                                        stream.Dispose();
                                        stream.Close();
                                    }
                                    fileName = attachment.FriendlyFileName;
                                }
                                thirdAccountGetter.CreatePhotoMicroBlog(account.AccessToken, microblogBody, bytes, fileName, account.Identification);
                            }
                            else
                                thirdAccountGetter.CreateMicroBlog(account.AccessToken, microblogBody, account.Identification);
                        }
                    }
                }
                if ((int)entity.AuditStatus > (int)(new AuditService().GetPubliclyAuditStatus(MicroblogConfig.Instance().ApplicationId)))
                {
                    return Json(new { MessageType = StatusMessageType.Success, MessageContent = "发布成功", id = entity.MicroblogId });
                }
                else
                {
                    return Json(new { MessageType = StatusMessageType.Hint, MessageContent = "尚未通过审核,请耐心等待", id = entity.MicroblogId });
                }
            }

            if (isBanned)
                return Json(new { MessageType = StatusMessageType.Error, MessageContent = "内容中有非法词语!" });
            else
                return Json(new { MessageType = StatusMessageType.Error, MessageContent = "创建失败请联系管理员!" });
        }
Esempio n. 2
0
 /// <summary>
 /// 绑定第三方帐号提示信息
 /// </summary>
 /// <param name="accountTypeKey"></param>
 /// <returns></returns>
 public ActionResult _BindThirdAccount(string accountTypeKey)
 {
     var accountBindingService = new AccountBindingService();
     AccountType accountType = accountBindingService.GetAccountType(accountTypeKey);
     var currentUserId = UserContext.CurrentUser != null ? UserContext.CurrentUser.UserId : 0;
     AccountBinding accountBinding = accountBindingService.GetAccountBinding(currentUserId, accountType.AccountTypeKey);
     ViewData["isExpired"] = accountBinding != null && accountBinding.ExpiredDate.CompareTo(DateTime.UtcNow) < 0;
     return View(accountType);
 }
Esempio n. 3
0
        public ActionResult ThirdRegister()
        {
            pageResourceManager.InsertTitlePart("首次登录完善帐号资料");
            ThirdUser thirdUser = TempData.Get<ThirdUser>("thirdCurrentUser", null);
            TempData["thirdCurrentUser"] = thirdUser;
            ViewData["thirdCurrentUser"] = thirdUser;

            if (thirdUser == null)
                return Redirect(SiteUrls.Instance().Login());
            int expires_in = TempData.Get<int>("expires_in", 0);
            TempData["expires_in"] = expires_in;
            ViewData["expires_in"] = expires_in;

            if (new AccountBindingService().GetUserId(thirdUser.AccountTypeKey, thirdUser.Identification) > 0)
                return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                {
                    Title = "重复绑定",
                    Body = "已经有网站帐号绑定过,不允许重复绑定第三方帐号",
                    StatusMessageType = StatusMessageType.Hint
                }));

            ThirdAccountGetter thirdAccountGetter = ThirdAccountGetterFactory.GetThirdAccountGetter(thirdUser.AccountTypeKey);
            ViewData["AccountType"] = new AccountBindingService().GetAccountType(thirdUser.AccountTypeKey);
            ViewData["AccountTypeName"] = thirdAccountGetter.AccountTypeName;
            thirdUser.NickName = thirdUser.NickName.Replace("%", "").Replace("+", "").Replace(" ", "").Replace("/", "").Replace("?", "").Replace("&", "").Replace("=", "").Replace("#", "");
            var model = new ThirdRegisterEditModel();
            model.UserName = thirdUser.NickName;
            model.ShareToFirend = true;
            model.FollowOfficial = true;

            ViewData["Content"] = string.Format(ResourceAccessor.GetString("AccountBinding_ShareToFirend"), thirdAccountGetter.AccountTypeName, DIContainer.Resolve<ISettingsManager<SiteSettings>>().Get().SiteName, SiteUrls.FullUrl(SiteUrls.Instance().SiteHome()));

            return View(model);
        }
Esempio n. 4
0
        /// <summary>
        /// 登录第三方网站回调地址
        /// </summary>
        /// <param name="accountTypeKey"></param>
        /// <returns></returns>
        public ActionResult ThirdCallBack(string accountTypeKey)
        {
            ThirdAccountGetter thirdAccountGetter = ThirdAccountGetterFactory.GetThirdAccountGetter(accountTypeKey);
            string returnUrl = string.Empty;
            int expires_in = 0;
            string accessToken = thirdAccountGetter.GetAccessToken(Request, out expires_in);
            if (string.IsNullOrEmpty(accessToken))
            {
                ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "授权失败,请稍后再试!");
                return View();
            }
            var thirdCurrentUser = thirdAccountGetter.GetThirdUser(accessToken, null);
            if (thirdCurrentUser != null)
            {
                ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "登录成功");
                ViewData["thirdCurrentUser"] = thirdCurrentUser;
                TempData["thirdCurrentUser"] = thirdCurrentUser;
                TempData["expires_in"] = expires_in;
                var systemCurrentUser = UserContext.CurrentUser;
                AccountBindingService accountBindingService = new AccountBindingService();
                //是否已绑定过其他帐号
                long userId = accountBindingService.GetUserId(accountTypeKey, thirdCurrentUser.Identification);
                User systemUser = userService.GetFullUser(userId);

                //登录用户直接绑定帐号
                if (systemCurrentUser != null)
                {
                    if (systemUser != null)
                    {
                        if (systemCurrentUser.UserId != systemUser.UserId)
                            ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Hint, "此帐号已在网站中绑定过,不可再绑定其他网站帐号");
                        else
                        {
                            accountBindingService.UpdateAccessToken(systemUser.UserId, thirdCurrentUser.AccountTypeKey, thirdCurrentUser.Identification, thirdCurrentUser.AccessToken, expires_in);
                            ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "更新授权成功");
                        }
                    }
                    else
                    {
                        AccountBinding account = AccountBinding.New();
                        account.AccountTypeKey = accountTypeKey;
                        account.Identification = thirdCurrentUser.Identification;
                        account.UserId = systemCurrentUser.UserId;
                        account.AccessToken = accessToken;
                        if (expires_in > 0)
                            account.ExpiredDate = DateTime.UtcNow.AddSeconds(expires_in);
                        accountBindingService.CreateAccountBinding(account);
                        ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "绑定成功");
                    }
                }
                else
                {
                    //已经绑定过,直接登录
                    if (systemUser != null)
                    {
                        if ((!systemUser.IsActivated && !userSettings.EnableNotActivatedUsersToLogin)) //帐号未激活
                        {
                            ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "帐号未激活!");
                            ViewData["ShowSystemMessage"] = true;
                            string token = Utility.EncryptTokenForValidateEmail(0.004, systemUser.UserId);
                            returnUrl = SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                            {
                                Title = "帐号未激活!",
                                Body = "您的帐号还未激活,请尽快{0}您的帐号,以方便您更多操作!",
                                BodyLink = new Dictionary<string, string> { { "激活", SiteUrls.Instance()._ActivateByEmail(systemUser.AccountEmail, token) } },
                                StatusMessageType = StatusMessageType.Hint
                            });
                        }
                        else if (systemUser.IsBanned) //帐号被封禁
                        {
                            ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "帐号被封禁!");
                            ViewData["ShowSystemMessage"] = true;
                            returnUrl = SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                            {
                                Title = "帐号被封禁!",
                                Body = "不好意思,由于您的非法操作,帐号已经被封禁,封禁截止到" + systemUser.BanDeadline.ToFriendlyDate(),
                                StatusMessageType = StatusMessageType.Error
                            });
                        }
                        else
                        {
                            FormsAuthentication.SetAuthCookie(systemUser.UserName, true);
                            if (userSettings.MyHomePageAsSiteEntry)
                                returnUrl = SiteUrls.Instance().MyHome(systemUser.UserName);
                            else
                                returnUrl = SiteUrls.Instance().SiteHome();

                            #region 关于第三方站好登陆之后的回跳地址

                            if (Request.Cookies != null)
                            {
                                if (Request.Cookies.Get("returnUrl") != null && !String.IsNullOrEmpty(Request.Cookies.Get("returnUrl").Value))
                                {
                                    string returnUrlFromCookie = Request.Cookies.Get("returnUrl").Value;

                                    if (!string.IsNullOrEmpty(returnUrlFromCookie))
                                        returnUrl = Tunynet.Utilities.WebUtility.UrlDecode(returnUrlFromCookie);

                                    if (Response.Cookies != null)
                                        Response.Cookies["returnUrl"].Expires = DateTime.Now;
                                }
                            }

                            #endregion
                            accountBindingService.UpdateAccessToken(systemUser.UserId, thirdCurrentUser.AccountTypeKey, thirdCurrentUser.Identification, thirdCurrentUser.AccessToken, expires_in);
                            ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "登录成功");
                        }
                    }
                    else
                    {
                        if (userSettings.RegistrationMode == RegistrationMode.Disabled)
                        {
                            return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                            {
                                Title = "禁止注册",
                                Body = "管理员限制了新帐号的创建,请过后再试",
                                StatusMessageType = StatusMessageType.Hint
                            }));
                        }
                        else
                        {
                            ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, string.Empty);
                            ViewData["FirstLogin"] = true;
                            returnUrl = SiteUrls.Instance().ThirdRegister();
                        }
                    }
                }
            }
            else
                ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "参数错误,授权失败!");
            ViewData["SiteName"] = siteSettingsManager.Get().SiteName;
            ViewData["returnUrl"] = returnUrl;
            return View();
        }
        /// <summary>
        /// 将EditModel转为数据库实体
        /// </summary>
        /// <returns></returns>
        public AccountType AsAccountType()
        {
            AccountBindingService service = new AccountBindingService();
            AccountType accountType = service.GetAccountType(AccountTypeKey);

            accountType.AppKey = AppKey ?? string.Empty;
            accountType.AppSecret = AppSecret ?? string.Empty;
            accountType.IsSync = IsSync;
            accountType.IsShareMicroBlog = IsShareMicroBlog;
            accountType.IsFollowMicroBlog = IsFollowMicroBlog;
            accountType.OfficialMicroBlogAccount = OfficialMicroBlogAccount ?? string.Empty;
            accountType.IsEnabled = IsEnabled;

            return accountType;
        }
        private void DeleteUserEventMoudle_After(IUser sender, DeleteUserEventArgs eventArgs)
        {
            IUserService userService = DIContainer.Resolve<IUserService>();

            #region 数据
            //清除应用数据
            applicationService.DeleteUser(sender.UserId, eventArgs.TakeOverUserName, eventArgs.TakeOverAll);

            //删除用户信息
            new UserProfileService().Delete(sender.UserId);

            //清除用户内容计数数据
            OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
            ownerDataService.ClearOwnerData(sender.UserId);

            //清除用户关于分类的数据
            CategoryService categoryService = new CategoryService();
            categoryService.CleanByUser(sender.UserId);

            //清除用户动态
            ActivityService activityService = new ActivityService();
            activityService.CleanByUser(sender.UserId);

            //清除用户评论
            new CommentService().DeleteUserComments(sender.UserId, false);

            #endregion

            #region 消息

            //清除用户关于私信的数据
            MessageService messageService = new MessageService();
            messageService.ClearSessionsFromUser(sender.UserId);

            //清除请求的用户数据
            InvitationService invitationService = new InvitationService();
            invitationService.CleanByUser(sender.UserId);

            //清除通知的用户数据
            NoticeService noticeService = new NoticeService();
            noticeService.CleanByUser(sender.UserId);

            InviteFriendService inviteFriendService = new InviteFriendService();
            inviteFriendService.CleanByUser(sender.UserId);

            //清除站外提醒的用户数据
            ReminderService reminderService = new ReminderService();
            reminderService.CleanByUser(sender.UserId);

            #endregion

            #region 关注/访客

            //清除用户关于关注用户的数据
            FollowService followService = new FollowService();
            followService.CleanByUser(sender.UserId);

            //清除访客记录的用户数据
            VisitService visitService = new VisitService(string.Empty);
            visitService.CleanByUser(sender.UserId);

            #endregion

            #region 帐号

            //清除帐号绑定数据
            var accountBindingService = new AccountBindingService();
            var accountBindings = new AccountBindingService().GetAccountBindings(sender.UserId);
            foreach (var accountBinding in accountBindings)
            {
                accountBindingService.DeleteAccountBinding(accountBinding.UserId, accountBinding.AccountTypeKey);
            }

            #endregion

            #region 装扮

            //调整皮肤文件使用次数
            var user = userService.GetFullUser(sender.UserId);
            if (user == null)
                return;
            var presentArea = new PresentAreaService().Get(PresentAreaKeysOfBuiltIn.UserSpace);
            string defaultThemeAppearance = string.Join(",", presentArea.DefaultThemeKey, presentArea.DefaultAppearanceKey);
            if (!user.IsUseCustomStyle)
                new ThemeService().ChangeThemeAppearanceUserCount(PresentAreaKeysOfBuiltIn.UserSpace, null, !string.IsNullOrEmpty(user.ThemeAppearance) ? user.ThemeAppearance : defaultThemeAppearance);

            #endregion
        }