public async Task <string> GetCurrentUser(LoginModel model) { KgmApiResultEntity result = new KgmApiResultEntity();//返回对象 SearchCondition condition = new SearchCondition(); condition.AddCondition("F_Account", model.Account, SqlOperator.Equal); Sys_UserInfo loginResult = BLLFactory <Sys_User> .Instance.FindSingle(condition.BuildConditionSql().Replace(" Where (1=1) AND", string.Empty)); if (loginResult == null) { result.result = false; result.message = "用户名不存在!"; } else if (!loginResult.F_UserPassword.Equals(DESEncrypt.Encrypt(model.Password))) { result.result = false; result.message = "用户名与密码不匹配!"; } else { bool isadmin = false; if (loginResult.F_EnabledMark == false) { result.result = false; result.message = "该用户已被禁用,请联系管理员启用后再进行登录!"; } else { if (loginResult.F_IsAdministrator == true) { isadmin = true; } //生成token var token = await JWTTokenHelper.GetTokenAsync(loginResult.F_Id, "0", isadmin); var id = currentUserId; result.result = true; result.message = token; } } return(JsonAppHelper.ToJson(new { status = result.result, token = result.message, User = loginResult })); }
/// <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); }