public JsonResult Login(ViewModels.VMUser inModel) { JsonResult json = new JsonResult(); if (string.IsNullOrEmpty(inModel.UserName) || string.IsNullOrEmpty(inModel.Password)) { json.Data = new { result = false, msg = "ERROR" }; } if (inModel.UID == 0) { bool exist = Logic.LUsers.ExistUser(inModel.UserName); if (exist) { json.Data = new { result = false, msg = "用户名已存在" }; return(json); } Model.MUsers model = new Model.MUsers { UserName = inModel.UserName, Password = inModel.Password, Email = inModel.Email ?? "" }; bool result = Logic.LUsers.CreateUser(model) > 0; string msg = result ? "" : "注册失败"; if (result) { Model.MUsers user = Logic.LUsers.GetUsers(inModel.UserName, inModel.Password); SetSession(user); } json.Data = new { result, msg }; } else { Model.MUsers model = Logic.LUsers.GetUsers(inModel.UserName, inModel.Password); bool result = model != null; if (result) { SetSession(model); } json.Data = new { result, msg = "用户名或密码错误" }; } return(json); }
private void SetSession(Model.MUsers inUser) { ViewModels.VMUser vModel = new ViewModels.VMUser { UID = inUser.UID, UserName = inUser.UserName, Password = inUser.Password, Email = inUser.Email }; Session["LoginUser"] = vModel; }
public ActionResult Index(string search = "", int catid = 0) { List <Model.MContent> articleList = LContent.GetRandomArticles(10, 0); categoryId = catid; searchStr = search; pageIndex = 0; aList.Clear(); var list = (from l in articleList where l.Conten.Contains("<img src=") orderby Guid.NewGuid() select l).Take(6).ToList(); List <ViewModels.VMArticle> vList = GetVmList(list); ViewData["ShowList"] = vList; //首页图片轮播 var ywList = (from l in articleList where l.Conten.Contains("<img src=") orderby l.ReleaseTime descending select l).Take(4).ToList(); List <ViewModels.VMArticle> vywList = GetVmList(ywList); ViewData["NewList"] = vywList; //最新要闻 decimal total = LContent.GetArticleTotal(); int pcount = Convert.ToInt32(Math.Ceiling(total / 10)); //页数 ViewBag.PageCount = pcount; ViewBag.Search = search; ViewBag.CatID = catid; ViewModels.VMUser vUser = Session["LoginUser"] as ViewModels.VMUser; //获取session ViewBag.IsLogin = vUser == null; ViewBag.Name = vUser == null ? "" : vUser.UserName; ViewBag.VCount = LVisitorCount.GetVisitorCount().Count; if (State) { return(View("MobileIndex")); } return(View()); }