protected void Page_Load(object sender, EventArgs e) { CurrentUser = Session["current_user"] as Model.User; ////获得图片数据 //Picture.BLL.PictureInfoBLL bllPictureInfo = new Picture.BLL.PictureInfoBLL(); //List = bllPictureInfo.QueryList(-1, 10, new { UId = CurrentUser.UId }, "UploadDate"); //获得修改头像 IUcClient client = new UcClient(); Avatar = client.Avatar(CurrentUser.UId); Avatar = Avatar.Replace(@"id=""mycamera""", @"id=""mycamera"" class=""center-block"""); AvatarHref = client.AvatarUrl(CurrentUser.UId, AvatarSize.Big, AvatarType.Virtual); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; int ciShu = int.Parse(context.Request["ciShu"] ?? "0"); //取数据 Picture.BLL.PictureMoreInfoBLL pictureInfoBll = new Picture.BLL.PictureMoreInfoBLL(); //var models = bllPictureInfo.QueryList(ciShu + 1, 20,new {}, "UploadDate"); User user=context.Session["current_user"] as User; var models = pictureInfoBll.GetPictureInfoWithTagAndUserInfo(ciShu + 1, 20, "UploadDate", true, user != null ? user.UId : -1); //pictureInfoBll.GetPictureInfoWithTagAndUserInfo(ciShu + 1, 20, null, "UploadDate"); IUcClient client = new UcClient(); //构建要发送到前端的数据 List<Model.Picture> list = new List<Model.Picture>(); foreach (var item in models) { list.Add(new Model.Picture() { id=item.PId, imgUrl = CommonHelper.GetSmallImgPath(item.LargeImgPath), //userName = item.UInfo.UserName, userName=item.UserName, //userFace = client.AvatarUrl(item.UInfo.Uid, AvatarSize.Small),//@"assets/img/face/face1.jpg", userFace=client.AvatarUrl(item.UId, AvatarSize.Small), label = item.Tags.Select(t => t.TagName).ToList(), width = item.Width, height = item.Height, uploadDate = item.UploadDate, title = item.ImgSummary, isCollect=item.isCollect>0?1:0 }); } System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer(); context.Response.Write(jss.Serialize(list)); }
public void ProcessRequest(HttpContext context) { /* * 存在问题 * * 完全可以去掉,登入错误时候返回的提示信息 * 改为返回错误码,与前端定个规则,1代表表单未填满,2代表密码错误 * * 登入部分是否可以不用自己写的Enum,简化那个部分的代码 * * * 未完成 * * 校验用户是否为禁言状态 * */ context.Response.ContentType = "text/html"; string verify = context.Request["verify"]; string username = context.Request["username"]; string password = context.Request["password"]; #region 表单为空校验 if (string.IsNullOrEmpty(username) | string.IsNullOrEmpty(password) | string.IsNullOrEmpty(verify)) { LoginErrorReturnData("请填写完整", 0, context); return; } #endregion #region 用户名合法性校验,已经注释 ////长度校验 //int userNameByteLength = 0; //for (int i = 0; i < username.Length; i++) //{ // if (Regex.IsMatch(username[i].ToString(), @"[^\x00-\xff]")) // { // userNameByteLength += 2; // } // else // { // userNameByteLength++; // } //} //if (userNameByteLength > 20 || userNameByteLength < 2) //{ // LoginErrorReturnData("用户名过长或过短", 3, context); // return; //} ////合法性校验 //if (!Regex.IsMatch(username, @"^[\u4e00-\u9fa5a-zA-Z0-9_]{1,20}$")) //{ // LoginErrorReturnData("用户名非法", 3, context); // return; //} #endregion #region 验证码校验 //使用非法手段,当验证码未生成变请求这个网站时,验证码未空,所以要判断 var serverVCode = context.Session["user_vcode"]; if (serverVCode == null) { LoginErrorReturnData("验证码错误", 3, context); return; } //真正的验证码正误判断 if (serverVCode.ToString().ToUpper() != verify.ToUpper()) { LoginErrorReturnData("验证码错误", 3, context); return; } //验证码用完要扔掉 context.Session["user_vcode"] = null; #endregion #region 登入部分 IUcClient client = new UcClient(); UcUserLogin result = client.UserLogin(username, password); Picture.Model.Enums.LoginResult loginResult = Picture.Model.Enums.LoginResult.未知错误; Picture.BLL.UserInfoBLL bllUserInfo = new Picture.BLL.UserInfoBLL(); //登入结果获取 switch (result.Result) { case LoginResult.NotExist: loginResult = Picture.Model.Enums.LoginResult.用户名不存在; break; case LoginResult.PassWordError: loginResult = Picture.Model.Enums.LoginResult.密码错误; break; case LoginResult.QuestionError: break; case LoginResult.Success: loginResult = Picture.Model.Enums.LoginResult.登录成功; //如果论坛有这个用户,而图片网没有 if (bllUserInfo.QueryCount(new { Uid = result.Uid }) <= 0) { Picture.Model.UserInfoModel model = new Picture.Model.UserInfoModel() { UserStatus = 0, Uid = result.Uid, UserName = result.UserName }; //保存失败 if (bllUserInfo.Insert(model) <= 0) { loginResult = Picture.Model.Enums.LoginResult.未知错误; } } break; default: break; } #region 查看用户状态 UserInfoModel userInfo = bllUserInfo.QuerySingle(result.Uid); if (userInfo.UserStatus == 1) { loginResult = Picture.Model.Enums.LoginResult.用户已被冻结; } #endregion //对结果进行相应的处理 switch (loginResult) { case Picture.Model.Enums.LoginResult.用户名不存在: LoginErrorReturnData("用户名不存在", 1, context); return; case Picture.Model.Enums.LoginResult.密码错误: LoginErrorReturnData("密码错误", 2, context); return; case Picture.Model.Enums.LoginResult.用户已被冻结: //LoginErrorReturnData("用户已被冻结", 1, context); //return; case Picture.Model.Enums.LoginResult.登录成功: Random r = new Random(); User user = new User() { EMail = result.Mail, UserName = username, UserFaceMiddle = client.AvatarUrl(result.Uid, AvatarSize.Middle), UserFacePathLarge = client.AvatarUrl(result.Uid, AvatarSize.Big) , UserFacePathSmall = client.AvatarUrl(result.Uid, AvatarSize.Small), UId = result.Uid, UserStatus = userInfo.UserStatus }; //写入Session,搜索栏右侧的用户信息从Session中获取 context.Session["current_user"] = user; break; case Picture.Model.Enums.LoginResult.未知错误: LoginErrorReturnData("未知错误", 3, context); return; default: break; } #endregion #region 返回信息构建 //登入成功 var data = new { isLogined = true, }; context.Response.Write(JSONHelper.ToJSONString(data)); return; #endregion }
public void ProcessRequest(HttpContext context) { /* * 存在问题 * * 完全可以去掉,登入错误时候返回的提示信息 * 改为返回错误码,与前端定个规则,1代表表单未填满,2代表密码错误 * */ context.Response.ContentType = "text/html"; Picture.BLL.UserInfoBLL bllUserInfo = new Picture.BLL.UserInfoBLL(); string verify = context.Request["verify"]; string username = context.Request["username"]; string password = context.Request["password"]; string email = context.Request["email"]; #region 表单为空校验 if (string.IsNullOrEmpty(username) | string.IsNullOrEmpty(password) | string.IsNullOrEmpty(verify) | string.IsNullOrEmpty(email) ) { RegisterErrorReturnData("请填写完整", 0, context); return; } #endregion #region 邮箱,密码,用户名合法性校验,已注释 //if (!Regex.IsMatch(email, @"^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$")) //{ // RegisterErrorReturnData("邮箱格式错误", 1, context); // return; //} //if (!Regex.IsMatch(password, @"^[\@A-Za-z0-9\!\#\$\%\^\&\*\.\~]{6,20}$")) //{ // RegisterErrorReturnData("密码出现非法字符", 2, context); // return; //} ////长度校验 //int userNameByteLength = 0; //for (int i = 0; i < username.Length; i++) //{ // if (Regex.IsMatch(username[i].ToString(), @"[^\x00-\xff]")) // { // userNameByteLength += 2; // } // else // { // userNameByteLength++; // } //} //if (userNameByteLength > 20 || userNameByteLength < 4) //{ // RegisterErrorReturnData("用户名过长或过短", 3, context); // return; //} ////合法性校验 //if (!Regex.IsMatch(username, @"^[\u4e00-\u9fa5a-zA-Z0-9_]{1,20}$")) //{ // RegisterErrorReturnData("用户名非法", 3, context); // return; //} #endregion #region 验证码校验 var serverVCode = context.Session["user_vcode"]; if (serverVCode == null) { RegisterErrorReturnData("验证码错误", 4, context); return; } //真正的验证码正误判断 if (serverVCode.ToString().ToUpper() != verify.ToUpper()) { RegisterErrorReturnData("验证码错误", 4, context); return; } //验证码用完要扔掉 context.Session["user_vcode"] = null; #endregion #region Discuz,数据库注册 IUcClient client = new UcClient(); UcUserRegister result = client.UserRegister(username, password, email); //注册结果处理 switch (result.Result) { case RegisterResult.ContainsInvalidWords: RegisterErrorReturnData("包含不允许注册的词语", 4, context); return; case RegisterResult.EmailHasBeenRegistered: RegisterErrorReturnData("邮箱已经存在", 3, context); return; case RegisterResult.EmailNotAllowed: RegisterErrorReturnData("此邮箱不允许注册", 3, context); return; case RegisterResult.IncorrectEmailFormat: RegisterErrorReturnData("邮箱格式错误", 3, context); return; case RegisterResult.Success: //把新用户保存到数据库中 Picture.Model.UserInfoModel userModel = new Picture.Model.UserInfoModel(); userModel.Uid = result.Uid; userModel.UserStatus = 0; userModel.UserName = username; int insertResult = bllUserInfo.Insert(userModel); if (insertResult <= 0) { RegisterErrorReturnData("未知错误", 4, context); return; } break; case RegisterResult.UserNameExists: RegisterErrorReturnData("用户名已经存在", 1, context); return; case RegisterResult.UserNameIllegal: RegisterErrorReturnData("用户名非法", 1, context); return; default: break; } #endregion #region 构建数据对象 //在论坛改了头像后,但是头像的url是不变的,但内容会变,所以添加一个后缀,让浏览器每次都请求头像 Random r = new Random(); User testUser = new User() { UserName = username, EMail = email, UserFaceMiddle = client.AvatarUrl(result.Uid, AvatarSize.Middle) , UserFacePathLarge = client.AvatarUrl(result.Uid, AvatarSize.Big) , UserFacePathSmall = client.AvatarUrl(result.Uid, AvatarSize.Small) , UId = result.Uid, UserStatus = 0 }; #endregion #region 构建返回信息 //写入Session,搜索栏右侧的用户信息从Session中获取 context.Session["current_user"] = testUser; var returnData = new { isRegister = true, }; context.Response.Write(JSONHelper.ToJSONString(returnData)); return; #endregion }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; int pId = int.Parse(context.Request["pId"]); Picture.BLL.CommentMore commentBll = new Picture.BLL.CommentMore(); Picture.BLL.PictureMoreInfoBLL pictureInfoBll = new Picture.BLL.PictureMoreInfoBLL(); IUcClient client = new UcClient(); User user = context.Session["current_user"] as User; object commentlist = null; //构建评论信息 if (user != null) { commentlist = commentBll.GetCommentWithUserInfo(new { PId = pId }, "PostDate").Select(c => new { userFace = client.AvatarUrl(c.UId, AvatarSize.Small), content = c.Content, postDate = c.PostDate, userName = c.UserName, cId = c.CId, isMe = c.UId == user.UId ? true : false }); } else { commentlist = commentBll.GetCommentWithUserInfo(new { PId = pId }, "PostDate").Select(c => new { userFace = client.AvatarUrl(c.UId, AvatarSize.Small), content = c.Content, postDate = c.PostDate, cId = c.CId, userName = c.UserName, }); } //获得图片信息 var pictureInfo = pictureInfoBll.GetSinglePictureInfoWithTagAndUserInfo(pId, user==null?-1:user.UId); //把数据整合并返回 var result = new { url = pictureInfo.LargeImgPath, uploadDate = pictureInfo.UploadDate, tags = pictureInfo.Tags, summary = pictureInfo.ImgSummary, collectCount=pictureInfo.CollectCount, userInfo = new { //userName = pictureInfo.UInfo.UserName, //userStatus = pictureInfo.UInfo.UserStatus, //userFace = client.AvatarUrl(pictureInfo.UInfo.Uid, AvatarSize.Small) userName = pictureInfo.UserName, userStatus = pictureInfo.UserStatus, userFace = client.AvatarUrl(pictureInfo.UId, AvatarSize.Small) }, commentlist = commentlist, isCollect = pictureInfo.isCollect }; context.Response.Write(JSONHelper.ToJSONString(result)); }