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; }