//用户信息 public ActionResult UserInfo() { ViewBag.ClientID = ConfigurationManager.AppSettings["client_id"]; //开发用OAuth跳转至changetolocalhost.com,修改changetolocalhost.com为localhost:2221完成本地OAuth登录 #if Debug ViewBag.Domain = "changetolocalhost.com"; #endif #if Release ViewBag.Domain = "objnull.com"; #endif if (CurrentUser != null) { ViewBag.User = CurrentUser; ViewBag.MsgCount = MyRedisDB.RedisDB.SetLength(MyRedisKeys.Pre_CMsg + CurrentUser.ID) + MyRedisDB.RedisDB.SetLength(MyRedisKeys.Pre_RMsg + CurrentUser.ID) + MyRedisDB.RedisDB.SetLength(MyRedisKeys.Pre_SysMsg + CurrentUser.ID); if (string.IsNullOrEmpty(HttpContext.ReadCookie("LastLogin"))) { NullUser user = NullUserDataSvc.GetByID(CurrentUser.ID); user.LastLoginDate = DateTime.Now; user.LastLoginIP = HttpContext.Request.UserHostAddress; NullUserDataSvc.Update(user); HttpContext.WriteCookie("LastLogin", DateTime.Now.ToString(), DateTime.Now.AddDays(1).Date); } } return(PartialView()); }
//个人主页 public ActionResult UserProfile(string id = null) { Guid userID = id == null ? CurrentUser.ID : Guid.Parse(id); NullUser user = NullUserDataSvc.GetByID(userID); ViewBag.User = user; ViewBag.Login = CurrentUser != null; ViewBag.Owner = ViewBag.Login ? userID == CurrentUser.ID : false; if (ViewBag.Login) { NullUser cuser = NullUserDataSvc.GetByID(CurrentUser.ID); ViewBag.Token = cuser.GitHubAccessToken; ViewBag.ShowPro = false; string key = MyRedisKeys.Pre_UserRecord + CurrentUser.ID; IEnumerable <UserRecord> userRecords = MyRedisDB.GetSet <UserRecord>(key); if (userRecords.Count() == 0) { ViewBag.ShowPro = true; } else if (userRecords.Where(r => r.ObjID == userID && r.type == (int)EnumRecordType.点赞).Count() == 0) { ViewBag.ShowPro = true; } } return(View()); }
//用户加赞 public void ProUser(Guid id) { NullUser user = NullUserDataSvc.GetByID(id); user.ProCount += 1; NullUserDataSvc.Update(user); }
//更新账号 public ActionResult UpdateInfo() { NullUser user = NullUserDataSvc.GetByID(CurrentUser.ID); if (UpdateUserInfo("github", user.GitHubAccessToken)) { return(Json(new { msg = "done" })); } else { return(Json(new { msg = "error" })); } }
//用户信息 public ActionResult UserInfo() { if (CurrentUser != null) { ViewBag.User = CurrentUser; ViewBag.MsgCount = MyRedisDB.RedisDB.SetLength(MyRedisKeys.Pre_CMsg + CurrentUser.ID) + MyRedisDB.RedisDB.SetLength(MyRedisKeys.Pre_RMsg + CurrentUser.ID) + MyRedisDB.RedisDB.SetLength(MyRedisKeys.Pre_SysMsg + CurrentUser.ID); if (string.IsNullOrEmpty(HttpContext.ReadCookie("LastLogin"))) { NullUser user = NullUserDataSvc.GetByID(CurrentUser.ID); user.LastLoginDate = DateTime.Now; user.LastLoginIP = HttpContext.Request.UserHostAddress; NullUserDataSvc.Update(user); HttpContext.WriteCookie("LastLogin", DateTime.Now.ToString(), DateTime.Now.AddDays(1).Date); } } return(PartialView()); }
public ActionResult SetEmail(string email) { NullUser user = NullUserDataSvc.GetByID(CurrentUser.ID); if (string.IsNullOrEmpty(email)) { user.Email = email; NullUserDataSvc.Update(user); return(Json(new { msg = "done" })); } if (email.Length > 100) { return(Json(new { msg = "邮箱最多100个字符" })); } Regex re = new Regex(@"[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?"); if (!re.IsMatch(email)) { return(Json(new { msg = "邮箱格式不正确" })); } user.Email = email; NullUserDataSvc.Update(user); return(Json(new { msg = "done" })); }