Exemple #1
0
        protected override void ShowPage()
        {
            pagetitle = "用户注册";

            if (userid != -1)
            {
                SetUrl(BaseConfigs.GetForumPath);
                SetMetaRefresh();
                SetShowBackLink(false);
                AddMsgLine("不能重复注册用户");
                ispost     = true;
                createuser = "******";
                agree      = "yes";
                return;
            }


            if (config.Regstatus < 1)
            {
                AddErrLine("论坛当前禁止新用户注册");
                return;
            }

            allowinvite = Utils.InArray(config.Regstatus.ToString(), "2,3");

            #region 用户IP判断
            string msg = Users.CheckRegisterDateDiff(DNTRequest.GetIP());
            if (msg != null)
            {
                AddErrLine(msg);
                return;
            }
            //if (config.Regctrl > 0)
            //{
            //    ShortUserInfo userinfo = Users.GetShortUserInfoByIP(DNTRequest.GetIP());
            //    if (userinfo != null)
            //    {
            //        int Interval = Utils.StrDateDiffHours(userinfo.Joindate, config.Regctrl);
            //        if (Interval <= 0)
            //        {
            //            AddErrLine("抱歉, 系统设置了IP注册间隔限制, 您必须在 " + (Interval * -1) + " 小时后才可以注册");
            //            return;
            //        }
            //    }
            //}

            //if (config.Ipregctrl.Trim() != "")
            //{
            //    string[] regctrl = Utils.SplitString(config.Ipregctrl, "\n");
            //    if (Utils.InIPArray(DNTRequest.GetIP(), regctrl))
            //    {
            //        ShortUserInfo userinfo = Users.GetShortUserInfoByIP(DNTRequest.GetIP());
            //        if (userinfo != null)
            //        {
            //            int Interval = Utils.StrDateDiffHours(userinfo.Joindate, 72);
            //            if (Interval < 0)
            //            {
            //                AddErrLine("抱歉, 系统设置了特殊IP注册限制, 您必须在 " + (Interval * -1) + " 小时后才可以注册");
            //                return;
            //            }
            //        }
            //    }
            //}
            #endregion

            //如果提交了用户注册信息...
            if (!Utils.StrIsNullOrEmpty(createuser) && ispost)
            {
                SetShowBackLink(true);
                InviteCodeInfo inviteCode = null;
                if (allowinvite)
                {
                    if (config.Regstatus == 3 && invitecode == "")
                    {
                        AddErrLine("邀请码不能为空!");
                        return;
                    }
                    if (invitecode != "")
                    {
                        inviteCode = Invitation.GetInviteCodeByCode(invitecode.ToUpper());
                        if (!Invitation.CheckInviteCode(inviteCode))
                        {
                            AddErrLine("邀请码不合法或已过期!");
                            return;
                        }
                    }
                }

                string tmpUserName = DNTRequest.GetString(config.Antispamregisterusername);
                string section     = DNTRequest.GetString("diseaseSection");
                if (!string.IsNullOrEmpty(section))
                {
                    tmpUserName = section + "_" + tmpUserName;
                }
                string email   = DNTRequest.GetString(config.Antispamregisteremail).Trim().ToLower();
                string tmpBday = DNTRequest.GetString("bday").Trim();

                if (tmpBday == "")
                {
                    tmpBday = string.Format("{0}-{1}-{2}", DNTRequest.GetString("bday_y").Trim(),
                                            DNTRequest.GetString("bday_m").Trim(), DNTRequest.GetString("bday_d").Trim());
                }
                tmpBday = (tmpBday == "--" ? "" : tmpBday);

                ValidateUserInfo(tmpUserName, email, tmpBday);

                if (IsErr())
                {
                    return;
                }

                //如果用户名符合注册规则, 则判断是否已存在
                if (Users.GetUserId(tmpUserName) > 0)
                {
                    AddErrLine("请不要重复提交!");
                    return;
                }

                UserInfo userInfo = CreateUser(tmpUserName, email, tmpBday);

                #region 发送欢迎信息
                if (config.Welcomemsg == 1)
                {
                    // 收件箱
                    PrivateMessageInfo privatemessageinfo = new PrivateMessageInfo();
                    privatemessageinfo.Message      = config.Welcomemsgtxt;
                    privatemessageinfo.Subject      = "欢迎您的加入! (请勿回复本信息)";
                    privatemessageinfo.Msgto        = userInfo.Username;
                    privatemessageinfo.Msgtoid      = userInfo.Uid;
                    privatemessageinfo.Msgfrom      = PrivateMessages.SystemUserName;
                    privatemessageinfo.Msgfromid    = 0;
                    privatemessageinfo.New          = 1;
                    privatemessageinfo.Postdatetime = Utils.GetDateTime();
                    privatemessageinfo.Folder       = 0;
                    PrivateMessages.CreatePrivateMessage(privatemessageinfo, 0);
                }
                #endregion

                //发送同步数据给应用程序
                Sync.UserRegister(userInfo.Uid, userInfo.Username, userInfo.Password, "");



                SetUrl("index.aspx");
                SetShowBackLink(false);
                SetMetaRefresh(config.Regverify == 0 ? 2 : 5);
                Statistics.ReSetStatisticsCache();

                if (inviteCode != null)
                {
                    Invitation.UpdateInviteCodeSuccessCount(inviteCode.InviteId);
                    if (config.Regstatus == 3)
                    {
                        if (inviteCode.SuccessCount + 1 >= inviteCode.MaxCount)
                        {
                            Invitation.DeleteInviteCode(inviteCode.InviteId);
                        }
                    }
                }

                if (config.Regverify == 0)
                {
                    UserCredits.UpdateUserCredits(userInfo.Uid);
                    ForumUtils.WriteUserCookie(userInfo, -1, config.Passwordkey);
                    OnlineUsers.UpdateAction(olid, UserAction.Register.ActionID, 0, config.Onlinetimeout);
                    MsgForward("register_succeed");
                    AddMsgLine("注册成功, 返回登录页");
                }
                else
                {
                    if (config.Regverify == 1)
                    {
                        AddMsgLine("注册成功, 请您到您的邮箱中点击激活链接来激活您的帐号");
                    }
                    else if (config.Regverify == 2)
                    {
                        AddMsgLine("注册成功, 但需要系统管理员审核您的帐户后才可登录使用");
                    }
                }
                //ManyouApplications.AddUserLog(userInfo.Uid, UserLogActionEnum.Add);
                agree = "yes";
            }
        }
Exemple #2
0
        /// <summary>
        /// 注册用户
        /// </summary>
        /// <returns></returns>
        public string Register()
        {
            string returnStr = string.Empty;

            if (Signature != GetParam("sig").ToString())
            {
                ErrorCode = (int)ErrorType.API_EC_SIGNATURE;
                return(returnStr);
            }

            if (CallId <= LastCallId)
            {
                ErrorCode = (int)ErrorType.API_EC_CALLID;
                return(returnStr);
            }

            if (!CheckRequiredParams("user_name,password,email"))
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return(returnStr);
            }

            if (this.App.ApplicationType == (int)ApplicationType.DESKTOP)//如果是桌面程序则不允许此方法
            {
                if (Uid < 1 || Discuz.Forum.UserGroups.GetUserGroupInfo(Discuz.Forum.Users.GetShortUserInfo(Uid).Groupid).Radminid != 1)
                {
                    ErrorCode = (int)ErrorType.API_EC_PERMISSION_DENIED;
                    return("");
                }
            }
            else if (Uid > 0)//已经登录的用户不能再注册
            {
                ErrorCode = (int)ErrorType.API_EC_USER_ONLINE;
                return(returnStr);
            }

            string username = GetParam("user_name").ToString();
            string password = GetParam("password").ToString();
            string email    = GetParam("email").ToString();

            bool isMD5Passwd = GetParam("password_format") != null && GetParam("password_format").ToString() == "md5" ? true : false;

            //用户名不符合规范
            if (!CheckUsername(username))
            {
                ErrorCode = (int)ErrorType.API_EC_USERNAME_ILLEGAL;
                return(returnStr);
            }

            if (Discuz.Forum.Users.GetUserId(username) != 0)//如果用户名符合注册规则, 则判断是否已存在
            {
                ErrorCode = (int)ErrorType.API_EC_USER_ALREADY_EXIST;
                return(returnStr);
            }

            if (!isMD5Passwd && password.Length < 6)
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return(returnStr);
            }

            if (!CheckEmail(email))
            {
                ErrorCode = (int)ErrorType.API_EC_EMAIL;
                return(returnStr);
            }

            UserInfo userInfo = new UserInfo();

            userInfo.Username      = username;
            userInfo.Nickname      = string.Empty;
            userInfo.Password      = isMD5Passwd ? password : Utils.MD5(password);
            userInfo.Secques       = string.Empty;
            userInfo.Gender        = 0;
            userInfo.Adminid       = 0;
            userInfo.Groupexpiry   = 0;
            userInfo.Extgroupids   = "";
            userInfo.Regip         = DNTRequest.GetIP();
            userInfo.Joindate      = Utils.GetDateTime();
            userInfo.Lastip        = DNTRequest.GetIP();
            userInfo.Lastvisit     = Utils.GetDateTime();
            userInfo.Lastactivity  = Utils.GetDateTime();
            userInfo.Lastpost      = Utils.GetDateTime();
            userInfo.Lastpostid    = 0;
            userInfo.Lastposttitle = "";
            userInfo.Posts         = 0;
            userInfo.Digestposts   = 0;
            userInfo.Oltime        = 0;
            userInfo.Pageviews     = 0;
            userInfo.Credits       = 0;
            userInfo.Extcredits1   = Scoresets.GetScoreSet(1).Init;
            userInfo.Extcredits2   = Scoresets.GetScoreSet(2).Init;
            userInfo.Extcredits3   = Scoresets.GetScoreSet(3).Init;
            userInfo.Extcredits4   = Scoresets.GetScoreSet(4).Init;
            userInfo.Extcredits5   = Scoresets.GetScoreSet(5).Init;
            userInfo.Extcredits6   = Scoresets.GetScoreSet(6).Init;
            userInfo.Extcredits7   = Scoresets.GetScoreSet(7).Init;
            userInfo.Extcredits8   = Scoresets.GetScoreSet(8).Init;
            userInfo.Email         = email;
            userInfo.Bday          = string.Empty;
            userInfo.Sigstatus     = 0;

            userInfo.Tpp        = 0;
            userInfo.Ppp        = 0;
            userInfo.Templateid = 0;
            userInfo.Pmsound    = 0;
            userInfo.Showemail  = 0;
            userInfo.Salt       = "0";
            int receivepmsetting = Config.Regadvance == 0 ? 7 : 1;

            userInfo.Newsletter   = (ReceivePMSettingType)receivepmsetting;
            userInfo.Invisible    = 0;
            userInfo.Newpm        = Config.Welcomemsg == 1 ? 1 : 0;
            userInfo.Medals       = "";
            userInfo.Accessmasks  = 0;
            userInfo.Website      = string.Empty;
            userInfo.Icq          = string.Empty;
            userInfo.Qq           = string.Empty;
            userInfo.Yahoo        = string.Empty;
            userInfo.Msn          = string.Empty;
            userInfo.Skype        = string.Empty;
            userInfo.Location     = string.Empty;
            userInfo.Customstatus = string.Empty;
            userInfo.Bio          = string.Empty;
            userInfo.Signature    = string.Empty;
            userInfo.Sightml      = string.Empty;
            userInfo.Authtime     = Utils.GetDateTime();

            //邮箱激活链接验证
            if (Config.Regverify == 1)
            {
                userInfo.Authstr  = ForumUtils.CreateAuthStr(20);
                userInfo.Authflag = 1;
                userInfo.Groupid  = 8;
                Emails.DiscuzSmtpMail(username, email, string.Empty, userInfo.Authstr);
            }
            //系统管理员进行后台验证
            else if (Config.Regverify == 2)
            {
                userInfo.Authstr  = string.Empty;
                userInfo.Groupid  = 8;
                userInfo.Authflag = 1;
            }
            else
            {
                userInfo.Authstr  = "";
                userInfo.Authflag = 0;
                userInfo.Groupid  = UserCredits.GetCreditsUserGroupId(0).Groupid;
            }
            userInfo.Realname = string.Empty;
            userInfo.Idcard   = string.Empty;
            userInfo.Mobile   = string.Empty;
            userInfo.Phone    = string.Empty;

            if (Config.Passwordmode > 1 && PasswordModeProvider.GetInstance() != null)
            {
                userInfo.Uid = PasswordModeProvider.GetInstance().CreateUserInfo(userInfo);
            }
            else
            {
                userInfo.Uid = Discuz.Forum.Users.CreateUser(userInfo);
            }

            if (Config.Welcomemsg == 1)
            {
                PrivateMessageInfo privatemessageinfo = new PrivateMessageInfo();
                // 收件箱
                privatemessageinfo.Message      = Config.Welcomemsgtxt;
                privatemessageinfo.Subject      = "欢迎您的加入! (请勿回复本信息)";
                privatemessageinfo.Msgto        = userInfo.Username;
                privatemessageinfo.Msgtoid      = userInfo.Uid;
                privatemessageinfo.Msgfrom      = PrivateMessages.SystemUserName;
                privatemessageinfo.Msgfromid    = 0;
                privatemessageinfo.New          = 1;
                privatemessageinfo.Postdatetime = Utils.GetDateTime();
                privatemessageinfo.Folder       = 0;
                PrivateMessages.CreatePrivateMessage(privatemessageinfo, 0);
            }

            Statistics.ReSetStatisticsCache();

            //信息同步通知不会发向当前请求接口的应用程序,所以此处应保留,以支持论坛向其他关联应用程序发送通知
            Sync.UserRegister(userInfo.Uid, userInfo.Username, userInfo.Password, ApiKey);

            UserCredits.UpdateUserCredits(userInfo.Uid);

            if (Format == FormatType.JSON)
            {
                return(string.Format("\"{0}\"", userInfo.Uid));
            }

            RegisterResponse rr = new RegisterResponse();

            rr.Uid = userInfo.Uid;

            return(SerializationHelper.Serialize(rr));
        }
Exemple #3
0
        protected override void ShowPage()
        {
            //pagetitle = "编辑帖子";
            #region 判断是否是灌水
            AdminGroupInfo admininfo = AdminGroups.GetAdminGroupInfo(usergroupid);
            this.disablepostctrl = 0;
            if (admininfo != null)
            {
                disablepostctrl = admininfo.Disablepostctrl;
            }
            #endregion

            if (userid == -1)
            {
                forum    = new ForumInfo();
                topic    = new TopicInfo();
                postinfo = new PostInfo();
                AddErrLine("您尚未登录");
                return;
            }

            #region 获取帖子和主题相关信息
            // 如果帖子ID非数字
            if (postid == -1)
            {
                AddErrLine("无效的帖子ID");
                return;
            }

            postinfo = Posts.GetPostInfo(topicid, postid);
            // 如果帖子不存在
            if (postinfo == null)
            {
                AddErrLine("不存在的帖子ID");
                return;
            }
            pagetitle   = (postinfo.Title == "") ? "编辑帖子" : postinfo.Title;
            htmlon      = postinfo.Htmlon;
            message     = postinfo.Message;
            isfirstpost = postinfo.Layer == 0;

            // 获取主题ID
            if (topicid != postinfo.Tid || postinfo.Tid == -1)
            {
                AddErrLine("无效的主题ID");
                return;
            }

            // 获取该主题的信息
            topic = Topics.GetTopicInfo(postinfo.Tid);
            // 如果该主题不存在
            if (topic == null)
            {
                AddErrLine("不存在的主题ID");
                return;
            }

            if (topic.Special == 1 && postinfo.Layer == 0)
            {
                pollinfo       = Polls.GetPollInfo(topic.Tid);
                polloptionlist = Polls.GetPollOptionList(topic.Tid);
            }

            if (topic.Special == 4 && postinfo.Layer == 0)
            {
                debateinfo = Debates.GetDebateTopic(topic.Tid);
            }
            #endregion

            #region 获取并检查版块信息
            ///得到所在版块信息
            forumid = topic.Fid;
            forum   = Forums.GetForumInfo(forumid);

            // 如果该版块不存在
            if (forum == null || forum.Layer == 0)
            {
                AddErrLine("版块已不存在");
                forum = new ForumInfo();
                return;
            }

            if (!Utils.StrIsNullOrEmpty(forum.Password) && Utils.MD5(forum.Password) != ForumUtils.GetCookie("forum" + forumid + "password"))
            {
                AddErrLine("本版块被管理员设置了密码");
                SetBackLink(base.ShowForumAspxRewrite(forumid, 0));
                return;
            }

            if (forum.Applytopictype == 1)  //启用主题分类
            {
                topictypeselectoptions = Forums.GetCurrentTopicTypesOption(forum.Fid, forum.Topictypes);
            }

            #endregion

            //是否有编辑帖子的权限
            if (!UserAuthority.CanEditPost(postinfo, userid, useradminid, ref msg))
            {
                AddErrLine(msg);
                return;
            }
            #region  附件信息绑定
            //得到用户可以上传的文件类型
            string attachmentTypeSelect = Attachments.GetAllowAttachmentType(usergroupinfo, forum);
            attachextensions       = Attachments.GetAttachmentTypeArray(attachmentTypeSelect);
            attachextensionsnosize = Attachments.GetAttachmentTypeString(attachmentTypeSelect);
            //得到今天允许用户上传的附件总大小(字节)
            int MaxTodaySize = (userid > 0 ? MaxTodaySize = Attachments.GetUploadFileSizeByuserid(userid) : 0);
            attachsize = usergroupinfo.Maxsizeperday - MaxTodaySize;//今天可上传得大小
            //是否有上传附件的权限
            canpostattach = UserAuthority.PostAttachAuthority(forum, usergroupinfo, userid, ref msg);

            userinfo = Users.GetShortUserInfo(userid);
            if (canpostattach && (config.Enablealbum == 1) && apb != null &&
                (UserGroups.GetUserGroupInfo(userinfo.Groupid).Maxspacephotosize - apb.GetPhotoSizeByUserid(userid) > 0))
            {
                caninsertalbum = true;
                albumlist      = apb.GetSpaceAlbumByUserId(userid);
            }
            else
            {
                caninsertalbum = false;
            }

            attachmentlist  = Attachments.GetAttachmentListByPid(postinfo.Pid);
            attachmentcount = attachmentlist.Rows.Count;
            //当前用户是否有允许下载附件权限
            allowviewattach = UserAuthority.DownloadAttachment(forum, userid, usergroupinfo);

            #endregion

            smileyoff          = (!DNTRequest.IsPost()) ? postinfo.Smileyoff : 1 - forum.Allowsmilies;
            allowimg           = forum.Allowimgcode;
            parseurloff        = postinfo.Parseurloff;
            bbcodeoff          = (usergroupinfo.Allowcusbbcode == 1) ? postinfo.Bbcodeoff : 1;
            usesig             = postinfo.Usesig;
            userextcreditsinfo = Scoresets.GetScoreSet(Scoresets.GetTopicAttachCreditsTrans());
            if (bonusCreditsTrans > 0 && bonusCreditsTrans < 9)
            {
                bonusextcreditsinfo = Scoresets.GetScoreSet(bonusCreditsTrans);
                mybonustranscredits = Users.GetUserExtCredits(userid, bonusCreditsTrans);
            }

            //是否有访问当前版块的权限
            if (!UserAuthority.VisitAuthority(forum, usergroupinfo, userid, ref msg))
            {
                AddErrLine(msg);
                return;
            }

            // 判断当前用户是否有修改权限, 检查是否具有版主的身份
            if (!Moderators.IsModer(useradminid, userid, forumid))
            {
                if (postinfo.Posterid != userid)
                {
                    AddErrLine("你并非作者, 且你当前的身份 \"" + usergroupinfo.Grouptitle + "\" 没有修改该帖的权限");
                    return;
                }
                else if (config.Edittimelimit > 0 && Utils.StrDateDiffMinutes(postinfo.Postdatetime, config.Edittimelimit) > 0)
                {
                    AddErrLine("抱歉, 系统规定只能在帖子发表" + config.Edittimelimit + "分钟内才可以修改");
                    return;
                }
                else if (config.Edittimelimit == -1)
                {
                    AddErrLine("抱歉,系统不允许修改帖子");
                    return;
                }
            }

            #region htmltitle标题
            if (postinfo.Layer == 0)
            {
                canhtmltitle = usergroupinfo.Allowhtmltitle == 1;
            }

            if (Topics.GetMagicValue(topic.Magic, MagicType.HtmlTitle) == 1)
            {
                htmltitle = Topics.GetHtmlTitle(topic.Tid).Replace("\"", "\\\"").Replace("'", "\\'");
            }
            #endregion

            #region tag信息
            enabletag = (config.Enabletag & forum.Allowtag) == 1;
            if (enabletag && Topics.GetMagicValue(topic.Magic, MagicType.TopicTag) == 1)
            {
                foreach (TagInfo tag in ForumTags.GetTagsListByTopic(topic.Tid))
                {
                    if (tag.Orderid > -1)
                    {
                        topictags += string.Format(" {0}", tag.Tagname);
                    }
                }
                topictags = topictags.Trim();
            }
            #endregion
            userGroupInfoList.Sort(delegate(UserGroupInfo x, UserGroupInfo y) { return((x.Readaccess - y.Readaccess) + (y.Groupid - x.Groupid)); });
            //如果是提交...
            if (ispost)
            {
                SetBackLink("editpost.aspx?topicid=" + postinfo.Tid + "&postid=" + postinfo.Pid);

                if (ForumUtils.IsCrossSitePost())
                {
                    AddErrLine("您的请求来路不正确,无法提交。如果您安装了某种默认屏蔽来路信息的个人防火墙软件(如 Norton Internet Security),请设置其不要禁止来路信息后再试。");
                    return;
                }

                //设置相关帖子信息
                SetPostInfo(admininfo, userinfo, Utils.StrToInt(DNTRequest.GetString("htmlon"), 0) == 1);

                if (IsErr())
                {
                    return;
                }

                //通过验证的用户可以编辑帖子
                Posts.UpdatePost(postinfo);

                //设置附件相关信息
                System.Text.StringBuilder sb = SetAttachmentInfo();

                if (IsErr())
                {
                    return;
                }

                UserCredits.UpdateUserCredits(userid);

                #region 设置提示信息和跳转链接
                //辩论地址
                if (topic.Special == 4)
                {
                    SetUrl(Urls.ShowDebateAspxRewrite(topic.Tid));
                }
                else if (DNTRequest.GetQueryString("referer") != "")//ajax快速回复将传递referer参数
                {
                    SetUrl(string.Format("showtopic.aspx?page=end&forumpage={2}&topicid={0}#{1}", topic.Tid, postinfo.Pid, forumpageid));
                }
                else if (pageid > 1)//如果不是ajax,则应该是带pageid的参数
                {
                    if (config.Aspxrewrite == 1)
                    {
                        SetUrl(string.Format("showtopic-{0}-{2}{1}#{3}", topic.Tid, config.Extname, pageid, postinfo.Pid));
                    }
                    else
                    {
                        SetUrl(string.Format("showtopic.aspx?topicid={0}&forumpage={3}&page={2}#{1}", topic.Tid, postinfo.Pid, pageid, forumpageid));
                    }
                }
                else//如果都为空.就跳转到第一页(以免意外情况)
                {
                    if (config.Aspxrewrite == 1)
                    {
                        SetUrl(string.Format("showtopic-{0}{1}", topic.Tid, config.Extname));
                    }
                    else
                    {
                        SetUrl(string.Format("showtopic.aspx?topicid={0}&forumpage={1}", topic.Tid, forumpageid));
                    }
                }

                if (sb.Length > 0)
                {
                    SetMetaRefresh(5);
                    SetShowBackLink(true);
                    if (infloat == 1)
                    {
                        AddErrLine(sb.ToString());
                        return;
                    }
                    else
                    {
                        sb.Insert(0, "<table cellspacing=\"0\" cellpadding=\"4\" border=\"0\"><tr><td colspan=2 align=\"left\"><span class=\"bold\"><nobr>编辑帖子成功,但图片/附件上传出现问题:</nobr></span><br /></td></tr>");
                        sb.Append("</table>");
                        AddMsgLine(sb.ToString());
                    }
                }
                else
                {
                    SetMetaRefresh();
                    SetShowBackLink(false);
                    MsgForward("editpost_succeed");
                    AddMsgLine("编辑帖子成功, 返回该主题");
                }
                #endregion

                // 删除主题游客缓存
                if (postinfo.Layer == 0)
                {
                    ForumUtils.DeleteTopicCacheFile(topic.Tid);
                }
            }
            else
            {
                AddLinkCss(BaseConfigs.GetForumPath + "templates/" + templatepath + "/editor.css", "css");
            }
        }
Exemple #4
0
        public string SetExtCredits()
        {
            if (Signature != GetParam("sig").ToString())
            {
                ErrorCode = (int)ErrorType.API_EC_SIGNATURE;
                return("");
            }

            //如果是桌面程序则需要验证用户身份
            if (this.App.ApplicationType == (int)ApplicationType.DESKTOP)
            {
                if (Uid < 1)
                {
                    ErrorCode = (int)ErrorType.API_EC_SESSIONKEY;
                    return("");
                }

                if (Discuz.Forum.Users.GetShortUserInfo(Uid).Adminid != 1)
                {
                    ErrorCode = (int)ErrorType.API_EC_PERMISSION_DENIED;
                    return("");
                }
            }

            if (CallId <= LastCallId)
            {
                ErrorCode = (int)ErrorType.API_EC_CALLID;
                return("");
            }

            if (!this.CheckRequiredParams("uids,additional_values"))
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return("");
            }

            if (!Utils.IsNumericArray(GetParam("additional_values").ToString().Split(',')) || !Utils.IsNumericArray(GetParam("uids").ToString().Split(',')))
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return("");
            }

            string[] values = GetParam("additional_values").ToString().Split(',');
            if (values.Length != 8)
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return("");
            }

            List <float> list = new List <float>();

            for (int i = 0; i < values.Length; i++)
            {
                list.Add(Utils.StrToFloat(values[i], 0));
            }

            foreach (string uId in GetParam("uids").ToString().Split(','))
            {
                int id = TypeConverter.StrToInt(uId);
                if (id == 0)
                {
                    continue;
                }
                UserCredits.UpdateUserExtCredits(id, list.ToArray(), true);
                UserCredits.UpdateUserCredits(id);

                //向第三方应用同步积分
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i] != 0.0)
                    {
                        Sync.UpdateCredits(TypeConverter.StrToInt(uId), i + 1, list[i].ToString(), ApiKey);
                    }
                }
            }

            int successful = 1;

            if (Format == FormatType.JSON)
            {
                return(successful == 1 ? "true" : "false");
            }

            SetExtCreditsResponse secr = new SetExtCreditsResponse();

            secr.Successfull = successful;

            return(SerializationHelper.Serialize(secr));
        }
Exemple #5
0
        /// <summary>
        /// 获取用户id
        /// </summary>
        /// <returns></returns>
        private ShortUserInfo GetShortUserInfo(string postusername, string postpassword, string mobile, string email)
        {
            //postpassword = !Utils.StrIsNullOrEmpty(loginauth) ?
            //        DES.Decode(loginauth.Replace("[", "+"), config.Passwordkey) :
            //        DNTRequest.GetString("password");

            //postusername = Utils.StrIsNullOrEmpty(postusername) ? DNTRequest.GetString("username") : postusername;

            int uid = -1;

            switch (config.Passwordmode)
            {
            case 1:    //动网兼容模式
            {
                if (config.Secques == 1 && (!Utils.StrIsNullOrEmpty(loginauth) || !loginsubmit))
                {
                    uid = Users.CheckDvBbsPasswordAndSecques(postusername, postpassword, DNTRequest.GetFormInt("question", 0), DNTRequest.GetString("answer"));
                }
                else
                {
                    uid = Users.CheckDvBbsPassword(postusername, postpassword);
                }
                break;
            }

            case 0:    //默认模式
            {
                if (config.Secques == 1 && (!Utils.StrIsNullOrEmpty(loginauth) || !loginsubmit))
                {
                    uid = Users.CheckPasswordAndSecques(postusername, postpassword, true, DNTRequest.GetFormInt("question", 0), DNTRequest.GetString("answer"));
                }
                else
                {
                    #region 原始登录
                    //原始的登录
                    // uid = Users.CheckPassword(postusername, postpassword, true);
                    #endregion

                    #region 现在的登录
                    //现在的登录
                    uid = Users.GetUserId(postusername);
                    if (uid > 0)        //更新用户手机号、邮箱
                    {
                        #region 更新用户手机号、邮箱
                        UserInfo oldUserInfo = Users.GetUserInfo(uid);
                        UserInfo userInfo    = oldUserInfo.Clone();
                        //需要判断签名是否修改过
                        string sig = oldUserInfo.Sightml;        //保存旧的签名
                        userInfo.Uid      = uid;
                        userInfo.Username = postusername;        //当前登录的用户名


                        #region 基本资料
                        //userInfo.Realname = DNTRequest.GetString("realname");
                        //userInfo.Gender = DNTRequest.GetInt("gender", 0);
                        //userInfo.Bday = Utils.HtmlEncode(DNTRequest.GetString("bday"));
                        //userInfo.Location = Utils.HtmlEncode(DNTRequest.GetString("location"));
                        //userInfo.Idcard = DNTRequest.GetString("idcard");
                        //userInfo.Nickname = Utils.HtmlEncode(ForumUtils.BanWordFilter(DNTRequest.GetString("nickname")));
                        //userInfo.Bio = Utils.HtmlEncode(ForumUtils.BanWordFilter(DNTRequest.GetString("bio")));
                        #endregion

                        #region 联系方式
                        userInfo.Mobile = mobile;
                        //userInfo.Phone = DNTRequest.GetString("phone");
                        userInfo.Email = email;

                        //if (userInfo.Email != oldUserInfo.Email && !Users.ValidateEmail(userInfo.Email, userid))
                        //{
                        //    AddErrLine("Email: \"" + userInfo.Email + "\" 已经被其它用户注册使用");
                        //    return;
                        //}
                        //userInfo.Showemail = DNTRequest.GetInt("showemail", 1);

                        //if (DNTRequest.GetString("website").IndexOf(".") > -1 && !DNTRequest.GetString("website").ToLower().StartsWith("http"))
                        //    userInfo.Website = Utils.HtmlEncode("http://" + DNTRequest.GetString("website"));
                        //else
                        //    userInfo.Website = Utils.HtmlEncode(DNTRequest.GetString("website"));
                        //userInfo.Msn = Utils.HtmlEncode(DNTRequest.GetString("msn"));
                        //userInfo.Qq = Utils.HtmlEncode(DNTRequest.GetString("qq"));
                        //userInfo.Skype = Utils.HtmlEncode(DNTRequest.GetString("skype"));
                        //userInfo.Icq = Utils.HtmlEncode(DNTRequest.GetString("icq"));
                        //userInfo.Yahoo = Utils.HtmlEncode(DNTRequest.GetString("yahoo"));

                        #endregion


                        //PostpramsInfo postPramsInfo = new PostpramsInfo();
                        //postPramsInfo.Usergroupid = usergroupid;
                        //postPramsInfo.Attachimgpost = config.Attachimgpost;
                        //postPramsInfo.Showattachmentpath = config.Showattachmentpath;
                        //postPramsInfo.Hide = 0;
                        //postPramsInfo.Price = 0;
                        ////获取提交的内容并进行脏字和Html处理
                        ////postPramsInfo.Sdetail = Utils.HtmlEncode(ForumUtils.BanWordFilter(DNTRequest.GetString("signature"))); ;
                        //postPramsInfo.Smileyoff = 1;
                        //postPramsInfo.Bbcodeoff = 1 - usergroupinfo.Allowsigbbcode;
                        //postPramsInfo.Parseurloff = 1;
                        //postPramsInfo.Showimages = usergroupinfo.Allowsigimgcode;
                        //postPramsInfo.Allowhtml = 0;
                        //postPramsInfo.Signature = 1;
                        //postPramsInfo.Smiliesinfo = Smilies.GetSmiliesListWithInfo();
                        //postPramsInfo.Customeditorbuttoninfo = null;
                        //postPramsInfo.Smiliesmax = config.Smiliesmax;
                        //postPramsInfo.Signature = 1;

                        //userInfo.Sightml = UBB.UBBToHTML(postPramsInfo);
                        //if (sig != userInfo.Sightml)
                        //{
                        //    Sync.UpdateSignature(userid, userInfo.Username, userInfo.Sightml, "");
                        //}
                        //if (userInfo.Sightml.Length >= 1000)
                        //{
                        //    AddErrLine("您的签名转换后超出系统最大长度, 请返回修改");
                        //    return;
                        //}

                        //userInfo.Signature = postPramsInfo.Sdetail;
                        //userInfo.Sigstatus = DNTRequest.GetInt("sigstatus", 0) != 0 ? 1 : 0;


                        if (CheckModified(oldUserInfo, userInfo))
                        {
                            Users.UpdateUserProfile(userInfo);
                            Sync.UpdateProfile(userInfo.Uid, userInfo.Username, "");
                        }
                        OnlineUsers.DeleteUserByUid(userid);            //删除在线表中的信息,使之重建该用户在线表信息
                        //ManyouApplications.AddUserLog(userid, UserLogActionEnum.Update);

                        ForumUtils.WriteCookie("sigstatus", userInfo.Sigstatus.ToString());

                        //SetUrl("usercpprofile.aspx");
                        //SetMetaRefresh();
                        //SetShowBackLink(true);
                        //AddMsgLine("修改个人档案完毕");
                        #endregion
                    }
                    else         //注册新用户
                    {
                        #region 注册新用户
                        //如果提交了用户注册信息...
                        InviteCodeInfo inviteCode = null;

                        string tmpUserName = postusername;
                        //string email = email;
                        string tmpBday = string.Empty;


                        UserInfo userInfo = CreateUser(tmpUserName, email, tmpBday, mobile);

                        #region 发送欢迎信息
                        if (config.Welcomemsg == 1)
                        {
                            // 收件箱
                            PrivateMessageInfo privatemessageinfo = new PrivateMessageInfo();
                            privatemessageinfo.Message      = config.Welcomemsgtxt;
                            privatemessageinfo.Subject      = "欢迎您的加入! (请勿回复本信息)";
                            privatemessageinfo.Msgto        = userInfo.Username;
                            privatemessageinfo.Msgtoid      = userInfo.Uid;
                            privatemessageinfo.Msgfrom      = PrivateMessages.SystemUserName;
                            privatemessageinfo.Msgfromid    = 0;
                            privatemessageinfo.New          = 1;
                            privatemessageinfo.Postdatetime = Utils.GetDateTime();
                            privatemessageinfo.Folder       = 0;
                            PrivateMessages.CreatePrivateMessage(privatemessageinfo, 0);
                        }
                        #endregion

                        #region 发送同步数据给应用程序
                        //发送同步数据给应用程序
                        Sync.UserRegister(userInfo.Uid, userInfo.Username, userInfo.Password, "");

                        Statistics.ReSetStatisticsCache();

                        if (inviteCode != null)
                        {
                            Invitation.UpdateInviteCodeSuccessCount(inviteCode.InviteId);
                            if (config.Regstatus == 3)
                            {
                                if (inviteCode.SuccessCount + 1 >= inviteCode.MaxCount)
                                {
                                    Invitation.DeleteInviteCode(inviteCode.InviteId);
                                }
                            }
                        }

                        if (config.Regverify == 0)
                        {
                            UserCredits.UpdateUserCredits(userInfo.Uid);
                            ForumUtils.WriteUserCookie(userInfo, -1, config.Passwordkey);
                            OnlineUsers.UpdateAction(olid, UserAction.Register.ActionID, 0, config.Onlinetimeout);
                        }
                        #endregion

                        uid = Users.GetUserId(postusername);
                        #endregion
                    }
                    #endregion
                }
                break;
            }

            default:     //第三方加密验证模式
            {
                return((ShortUserInfo)Users.CheckThirdPartPassword(postusername, postpassword, DNTRequest.GetFormInt("question", 0), DNTRequest.GetString("answer")));
            }
            }
            if (uid != -1)
            {
                Users.UpdateTrendStat(TrendType.Login);
            }
            return(uid > 0 ? Users.GetShortUserInfo(uid) : null);
        }