public void SaveFirstLogin() { if (ctx.viewer.IsLogin) { echoError("对不起,您已经登录"); return; } Object connectType = ctx.web.SessionGet("__connectType"); if (connectType == null) { echoError("无效的 connect type"); return; } AuthConnect connect = AuthConnectFactory.GetConnect(connectType.ToString()); if (connect == null) { echoError("此连接类型不存在:" + connectType); return; } AccessToken accessToken = getAccessToken(); OAuthUserProfile userProfile = connect.GetUserProfile(accessToken); if (userProfile == null) { echoError("无法获取正常 user profile"); return; } accessToken.Name = userProfile.Name; // 注册用户 User user = new User(); user.Name = ctx.Post("userName"); user.Url = ctx.Post("userUrl"); Result result = userService.RegisterNoPwd(user); if (result.HasErrors) { echoError(result); return; } result = AvatarUploader.SaveRemote(userProfile.PicUrlBig, user.Id); if (result.IsValid) { user.Pic = result.Info.ToString(); user.update(); } else { echoError(result); return; } // 是否开启空间 RegUtils.CheckUserSpace(user, ctx); // 绑定用户 Result saveResult = connectService.Create(user, connect.GetType().FullName, accessToken); if (saveResult.IsValid) { UserConnect userConnect = saveResult.Info as UserConnect; loginService.Login(user, userConnect.Id, LoginTime.OneWeek, ctx.Ip, ctx); // 登录 echoRedirect("登录成功", "/"); } else { echoError(saveResult); } }
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()); } }