public IActionResult OnPostUserLogin(string loginName, string loginPwd) { ResultObject <EUserInfoBackEnd> result = new ResultObject <EUserInfoBackEnd>(); try { EUserInfoBackEnd eUserInfoBackEnd = _BackendSrv.UserLogin(loginName, loginPwd); if (eUserInfoBackEnd == null) { result.ErrorMsg = "用户名或密码错误!"; } else if ((int)eUserInfoBackEnd.UserRole < 30) { result.ErrorMsg = "权限不足"; } else { result.Entity = eUserInfoBackEnd; SetUserSesion(eUserInfoBackEnd); } } catch (Exception ex) { result.ErrorMsg = ex.Message; } return(new JsonResult(result)); }
public void SetUserSesion(EUserInfoBackEnd eUserInfoBackEnd) { BackendSession session = new BackendSession() { UserName = eUserInfoBackEnd.LoginName, UserRole = eUserInfoBackEnd.UserRole }; var json = JsonConvert.SerializeObject(session); HttpContext.Session.SetString(EduConstant.BackendSessionKey, json); }
public EUserInfoBackEnd UserLogin(string loginName, string loginPwd) { EUserInfoBackEnd result = _dbContext.DBUserInfoBackEnd.Where(a => a.LoginName == loginName && a.LoginPwd == loginPwd).FirstOrDefault(); return(result); }