Ejemplo n.º 1
0
        public void SaveReg()
        {
            if (ctx.viewer.IsLogin)
            {
                echo("您有帐号,并且已经登录");
                return;
            }

            if (config.Instance.Site.RegisterType == RegisterType.CloseUnlessInvite)
            {
                int    friendId   = ctx.PostInt("friendId");
                String friendCode = ctx.Post("friendCode");
                Result result     = inviteService.Validate(friendId, friendCode);
                if (result.HasErrors)
                {
                    echo(result.ErrorsHtml);
                    return;
                }
            }

            // 验证
            User user = validateUser();

            if (errors.HasErrors)
            {
                run(Register);
                return;
            }

            // 用户注册
            user = userService.Register(user, ctx);
            if ((user == null) || errors.HasErrors)
            {
                run(Register);
                return;
            }

            // 是否开启空间
            RegUtils.CheckUserSpace(user, ctx);

            // 好友处理
            RegUtils.ProcessFriend(user, ctx);

            // 是否需要审核、激活
            if (config.Instance.Site.UserNeedApprove)
            {
                user.Status = MemberStatus.Approving;
                user.update("Status");

                view("needApproveMsg");
                set("siteName", config.Instance.Site.SiteName);
            }
            else if (config.Instance.Site.EnableEmail)
            {
                if (config.Instance.Site.LoginType == LoginType.Open)
                {
                    loginService.Login(user, LoginTime.Forever, ctx.Ip, ctx);
                }

                redirectUrl(to(Done) + "?email=" + user.Email);
            }
            else
            {
                loginService.Login(user, LoginTime.Forever, ctx.Ip, ctx);
                echoRedirect(lang("registerok"), getSavedReturnUrl());
            }
        }