/// <summary> /// /// </summary> /// <param name="userName"></param> /// <param name="password"></param> /// <returns></returns> public WebResponseContent Login(string userName, string password) { WebResponseContent responseContent = new WebResponseContent(); if (string.IsNullOrWhiteSpace(userName) || string.IsNullOrWhiteSpace(password)) { return(responseContent.Error("登录错误")); } // var encryptPwd = AESEncrypt.Encrypt(password, AESEncrypt.pwdKey); var user = repository.Sys_User.Where(q => q.Enable == (byte)DataStatus.Enable) .Where(q => q.UserName == userName && q.UserPwd == password).First(); if (user == null) { return(responseContent.Error("账户或密码错误")); } var adminToken = new AdminUser { User_Id = user.UID, Email = user.Email, Role_Id = user.Role_Id, UserName = user.UserName, }; //获取token配置 var tokenManagement = AutofacContainerModule.GetService <IOptions <TokenManagement> >().Value; var token = TokenHelper.CreateAdminToken(tokenManagement, adminToken); //HttpContext.Current.Response.Headers.Add("Authorization", new StringValues(token)); return(responseContent.OK("登录成功", new M_AdminUserRP { id = user.UID, UserName = user.UserName, RoleId = user.Role_Id, HeadImageUrl = user.HeadImageUrl, Moblie = user.Mobile, Email = user.Email, Token = token, })); }