diff --git a/WebApi.cs b/WebApi.cs index 147ea2a5..24d4fac0 100644 --- a/WebApi.cs +++ b/WebApi.cs @@ -106,6 +106,23 @@ namespace VRCX } } + public string GetCookies() + { + using (var memoryStream = new MemoryStream()) + { + new BinaryFormatter().Serialize(memoryStream, _cookieContainer); + return Convert.ToBase64String(memoryStream.ToArray()); + } + } + + public void SetCookies(string cookies) + { + using (var stream = new MemoryStream(Convert.FromBase64String(cookies))) + { + _cookieContainer = (CookieContainer)new BinaryFormatter().Deserialize(stream); + } + } + #pragma warning disable CS4014 public async void Execute(IDictionary options, IJavascriptCallback callback) { diff --git a/html/src/app.js b/html/src/app.js index 8d28c9e9..14de399f 100644 --- a/html/src/app.js +++ b/html/src/app.js @@ -958,7 +958,6 @@ speechSynthesis.getVoices(); API.currentUser = {}; API.$on('LOGOUT', function () { - webApiService.clearCookies(); this.isLoggedIn = false; }); @@ -5436,6 +5435,7 @@ speechSynthesis.getVoices(); API.$on('LOGOUT', function () { $app.updateStoredUser(this.currentUser); + webApiService.clearCookies(); }); $app.methods.checkPrimaryPassword = function (args) { @@ -5549,7 +5549,7 @@ speechSynthesis.getVoices(); } }; - $app.methods.updateStoredUser = function (currentUser) { + $app.methods.updateStoredUser = async function (currentUser) { var savedCredentialsArray = {}; if (configRepository.getString('savedCredentials') !== null) { var savedCredentialsArray = JSON.parse( @@ -5568,6 +5568,7 @@ speechSynthesis.getVoices(); ) { savedCredentialsArray[currentUser.username].user = currentUser; } + savedCredentialsArray[currentUser.username].cookies = await webApiService.getCookies(); this.loginForm.savedCredentials = savedCredentialsArray; var jsonCredentialsArray = JSON.stringify(savedCredentialsArray); configRepository.setString('savedCredentials', jsonCredentialsArray); @@ -5575,7 +5576,11 @@ speechSynthesis.getVoices(); configRepository.setString('lastUserLoggedIn', currentUser.username); }; - $app.methods.relogin = function (loginParmas) { + $app.methods.relogin = function (user) { + var { loginParmas } = user; + if (user.cookies) { + webApiService.setCookies(user.cookies); + } return new Promise((resolve, reject) => { if (this.enablePrimaryPassword) { this.checkPrimaryPassword(loginParmas) diff --git a/html/src/index.pug b/html/src/index.pug index 6fe2c7ee..807f55c9 100644 --- a/html/src/index.pug +++ b/html/src/index.pug @@ -20,7 +20,7 @@ html h2(style="font-weight:bold;text-align:center;margin:0") Saved Accounts .x-friend-list(style="margin-top:10px") .x-friend-item(v-for="user in loginForm.savedCredentials" :key="user.user.id") - .x-friend-item(@click="relogin(user.loginParmas)" style="width:202px;padding:0") + .x-friend-item(@click="relogin(user)" style="width:202px;padding:0") .avatar img(v-if="user.user.profilePicOverride" v-lazy="user.user.profilePicOverride") img(v-else-if="displayVRCPlusIconsAsAvatar && user.user.userIcon" v-lazy="user.user.userIcon") diff --git a/html/src/service/webapi.js b/html/src/service/webapi.js index 3af43383..fa326d1e 100644 --- a/html/src/service/webapi.js +++ b/html/src/service/webapi.js @@ -5,6 +5,14 @@ class WebApiService { return WebApi.ClearCookies(); } + getCookies() { + return WebApi.GetCookies(); + } + + setCookies(cookie) { + return WebApi.SetCookies(cookie); + } + execute(options) { return new Promise((resolve, reject) => { WebApi.Execute(options, (err, response) => {