public async Task <KgmApiResultEntity> LoginSystem([FromBody] LoginSystemModel loginModel) { if (string.IsNullOrEmpty(loginModel.Password)) { loginModel.Password = string.Empty; } KgmApiResultEntity result = await loginSystemAsync(loginModel); return(result); }
/// <summary> /// 登录系统 /// </summary> /// <param name="loginModel">登录对象</param> /// <returns></returns> private async Task <KgmApiResultEntity> loginSystemAsync(LoginSystemModel loginModel) { KgmApiResultEntity result = new KgmApiResultEntity();//返回对象 result.result = false; result.message = ""; string errorInfo = string.Empty; if (!bRegister(out errorInfo)) { result.result = false; result.message = errorInfo; return(result); } Sys_UserInfo loginResult;//登录对象 bool bAdmin = false; if (loginModel.Account.Equals(ConstValue.KGMADMIN_USERNAME) && loginModel.Password.Equals(ConstValue.KGMADMIN_PASSWORD)) { //超级管理员 loginResult = new Sys_UserInfo(); loginResult.F_Id = ConstValue.KGMADMIN_USERID; loginResult.F_UserPassword = ConstValue.KGMADMIN_PASSWORD; loginResult.F_RealName = ConstValue.KGMADMIN_USERNAME; bAdmin = true; } else { SearchCondition condition = new SearchCondition(); condition.AddCondition("F_Account", loginModel.Account, SqlOperator.Equal); loginResult = BLLFactory <Sys_User> .Instance.FindSingle(condition.BuildConditionSql().Replace(" Where (1=1) AND", string.Empty)); } if (loginResult == null) { SaveLoginLog(loginModel.Account, string.Empty, loginModel.LoginSystem.ToString(), false, "用户名不存在!"); result.result = false; result.message = "用户名不存在!"; } else if (!loginResult.F_UserPassword.Equals(DESEncrypt.Encrypt(loginModel.Password))) { SaveLoginLog(loginModel.Account, string.Empty, loginModel.LoginSystem.ToString(), false, "用户名与密码不匹配!"); result.result = false; result.message = "用户名与密码不匹配!"; } else { string token = ""; //token //生成token token = await JWTTokenHelper.GetTokenAsync(loginResult.F_Id, loginModel.LoginSystem, bAdmin); SaveLoginLog(loginResult.F_Account, loginResult.F_NickName, loginModel.LoginSystem.ToString(), true, "登录成功"); result.result = true; result.message = token; } return(result); }