public ActionResult Index() { bool state = false; string message = string.Empty; int boardid = Convert.ToInt32(Request["boardid"]); int pagecount; //获取版块的信息 ViewBoardIndex boardIndex = new ViewBoardIndex(); //获取版块信息 boardIndex.Board = BoardService.GetBoard(boardid); boardIndex.ViewPosts = PostService.GetViewPost(1, boardid, out pagecount); boardIndex.PageCount = pagecount; sessionModel = UserState.GetCurrentUser(SessionId.GetSessionId()); if (sessionModel != null && sessionModel.User != null) { ViewBag.User = UserService.GetViewUser(sessionModel.User); ViewBag.logined = true; } else { ViewBag.logined = false; } return(View(boardIndex)); }
public ActionResult SetValidateEmail() { string emailcode = Request["emailcode"]; bool state = true; string message = string.Empty; try { state = UserService.CheckEamilValidate(emailcode, sessionModel.User.UserId, sessionModel.EmailValidateCode); if (state) { UserService.ChangeEmailValidateStatus(sessionModel.User.UserId, EmailValide.Valide); } sessionModel.EmailValidateCode = string.Empty; CacheResolver.SetCache(SessionId.GetSessionId(), sessionModel); message = state ? "邮箱验证成功" : "邮箱验证失败"; } catch (EmailValideCodeException e) { state = false; message = e.Message; } return(Content(JsonString.GetString(new { state = state, message = message }))); }
public ActionResult Register() { bool state = false; string message = string.Empty; if (!ValidateUserCode(Request["validatecode"])) { message = "验证码错误"; return(Content(JsonString.GetString(new { state = state, message = message }))); } string account = Request["account"]; string username = Request["username"]; string password1 = Request["password1"]; string password2 = Request["password2"]; string description = Request["description"]; try { UserService.RegsiterUser(account, username, description, password1, password2); //注册成功了,当前session必须记住改用户,最终这个session是保存在memecache中的 UserState.SetCurrentUser(SessionId.GetSessionId(), new SessionModel() { User = UserService.Login(account, password1) }); message = "注册成功"; state = true; } catch (UserException e) { message = e.Message; } return(Content(JsonString.GetString(new { state = state, message = message }))); }
/// <summary> /// 帖子详细信息 /// </summary> /// <returns></returns> public ActionResult Index() { //判断当前否非为一个登录状态 sessionModel = UserState.GetCurrentUser(SessionId.GetSessionId()); if (sessionModel != null && sessionModel.User != null) { ViewBag.User = UserService.GetViewUser(sessionModel.User); ViewBag.logined = true; } else { ViewBag.logined = false; } int postid = Convert.ToInt32(Request["postid"]); int commentPageCount; ViewPostIndex postIndex = new ViewPostIndex(); try { postIndex.post = PostService.GetForumPost(postid); postIndex.userinfo = UserService.GetViewUserInfo(postIndex.post.UserId); //这里就获取到了用户的相关的信息 postIndex.comments = CommentServcie.GetViewCommentByPage(postid, 1, out commentPageCount); postIndex.commentPagecount = commentPageCount; } catch (UserException) { //发生错误强制跳转到首页 Response.Redirect("/home/index", true); } //获取发帖人相关的信息 return(View(postIndex)); }
public ActionResult Login() { string message = string.Empty; bool state = false; if (!ValidateUserCode(Request["validatecode"])) { message = "验证码错误"; CacheResolver.DeleteCache(ValidateCodeId.GetValidateCodeId()); return(Content(JsonString.GetString(new { state = state, message = message }))); } string account = Request["account"]; string password = Request["password"]; SessionModel currentSessionModel = new SessionModel(); try { currentSessionModel.User = UserService.Login(account, password); state = true; message = "登录成功"; } catch (UserException e) { message = e.Message; } catch (ArgumentNullException e) { message = e.Message; }//删除验证码 finally { CacheResolver.DeleteCache(ValidateCodeId.GetValidateCodeId()); } if (state == false) { //开始返回 return(Content(JsonString.GetString(new { state = state, message = message }))); } //在请求的开始已经处理了sessionid的写入了 UserState.SetCurrentUser(SessionId.GetSessionId(), currentSessionModel); //不进行捕获异常,由mvc来进行处理 bool rem = Request["remember"] == "1"; //其中的密码是md5密码 RememeberMe(account, currentSessionModel.User.Password, rem); //登录成功要做的就是要消除这个验证码 CacheResolver.DeleteCache(ValidateCodeId.GetValidateCodeId()); return(Content(JsonString.GetString(new { state = state, message = message, user = UserService.GetViewUser(currentSessionModel.User) }))); }
public ActionResult Index() { //判断当前是否为一个登录的状态 sessionModel = UserState.GetCurrentUser(SessionId.GetSessionId()); if (sessionModel != null && sessionModel.User != null) { ViewBag.User = UserService.GetViewUser(sessionModel.User); ViewBag.logined = true; } else { ViewBag.logined = false; } ViewHomeIndex homeIndex = new ViewHomeIndex(); homeIndex.Boards = BoardService.GetBoards(); //现在要做的就是获取前5个帖子 homeIndex.Posts = PostService.GetViewPostTop(); homeIndex.PostsRandom = PostService.GetViewPostRandom(); return(View(homeIndex)); }
public ActionResult ValidateEmail() { bool state = UserService.IsEmailValidated(sessionModel.User.UserId); if (state) { return(Content("邮箱已经被验证了")); } //开始邮箱验证工作,首先产生验证码,然后存入SessionModel中去 ValidateCode codeobj = new ValidateCode(); string emailcode = codeobj.CreateValidateCode(6); //更改缓存对象,同时我们数据库也要进行一次更改,用户完成了验证之后,记得要进行删除 sessionModel.EmailValidateCode = emailcode; //缓存服务器保存 CacheResolver.SetCache(SessionId.GetSessionId(), sessionModel); UserService.SetUserEmailValidateCode(sessionModel.User.UserId, emailcode); //设置完数据库之后,我们就要进行一次邮件的发送了 UserService.SendValidateEmail(UserService.GetUserEmail(sessionModel.User.UserId), emailcode); return(Content("验证邮件已经发送,注意接收")); }
public static string GetValidateCodeId() { return("validatecode_" + SessionId.GetSessionId()); }