private async void PageLoaded(object sender, RoutedEventArgs e) { var uri = ConfigurationUtil.GetApiUri() + "/dashBoard"; var result = await HttpClientUtil.GetResponseAsync <DashboardModel>(uri); DataContext = result; }
private async Task LoadCaptcha() { var uri = ConfigurationUtil.GetApiUri() + "/captcha"; var data = await HttpClientUtil.GetResponseAsync <CaptchaModel>(uri); if (data != null) { byte[] bytes = Convert.FromBase64String(data.CaptchaData); MemoryStream memStream = new MemoryStream(bytes); BitmapImage bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = memStream; bitmapImage.EndInit(); captchaImage.Source = bitmapImage; _captchaKey = data.CaptchaKey; } }
private async void LoginSubmit(object sender, RoutedEventArgs e) { var vm = DataContext as LoginViewModel; if (string.IsNullOrEmpty(vm.UserName) || string.IsNullOrEmpty(PasswordBox.Password) || string.IsNullOrEmpty(vm.CaptchaValue)) { MessageBox.Show("请输入内容!"); return; } var uri = ConfigurationUtil.GetApiUri() + "/login"; var loginData = new LoginModel { UserName = vm.UserName, Password = PasswordBox.Password, CaptchaKey = _captchaKey, CaptchaValue = vm.CaptchaValue }; var result = await HttpClientUtil.PostRequestAsync <LoginModel, LoginResult>(uri, loginData); if (result != null) { HttpClientUtil.RemoveBearaHeader(); HttpClientUtil.AddBearaHeader(result.Token); var json = new JwtBuilder().Decode(result.Token); var jo = JObject.Parse(json); var expire = jo["exp"].ToString(); _appDbContext.LoginInfos.RemoveRange(_appDbContext.LoginInfos); _appDbContext.LoginInfos.Add(new Data.Entity.LoginInfo { Token = result.Token, Avatar = result.Avatar, Name = result.Name, ExpireTime = DataTimeUtil.ConvertStringToDateTime(expire) }); _appDbContext.SaveChanges(); ShowMainWindow(); } }