Save cookies per user (no 2FA on account switch)

This commit is contained in:
Natsumi
2021-08-20 22:01:54 +12:00
parent c388b7ef7e
commit dbb1554300
4 changed files with 34 additions and 4 deletions
+17
View File
@@ -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 #pragma warning disable CS4014
public async void Execute(IDictionary<string, object> options, IJavascriptCallback callback) public async void Execute(IDictionary<string, object> options, IJavascriptCallback callback)
{ {
+8 -3
View File
@@ -958,7 +958,6 @@ speechSynthesis.getVoices();
API.currentUser = {}; API.currentUser = {};
API.$on('LOGOUT', function () { API.$on('LOGOUT', function () {
webApiService.clearCookies();
this.isLoggedIn = false; this.isLoggedIn = false;
}); });
@@ -5436,6 +5435,7 @@ speechSynthesis.getVoices();
API.$on('LOGOUT', function () { API.$on('LOGOUT', function () {
$app.updateStoredUser(this.currentUser); $app.updateStoredUser(this.currentUser);
webApiService.clearCookies();
}); });
$app.methods.checkPrimaryPassword = function (args) { $app.methods.checkPrimaryPassword = function (args) {
@@ -5549,7 +5549,7 @@ speechSynthesis.getVoices();
} }
}; };
$app.methods.updateStoredUser = function (currentUser) { $app.methods.updateStoredUser = async function (currentUser) {
var savedCredentialsArray = {}; var savedCredentialsArray = {};
if (configRepository.getString('savedCredentials') !== null) { if (configRepository.getString('savedCredentials') !== null) {
var savedCredentialsArray = JSON.parse( var savedCredentialsArray = JSON.parse(
@@ -5568,6 +5568,7 @@ speechSynthesis.getVoices();
) { ) {
savedCredentialsArray[currentUser.username].user = currentUser; savedCredentialsArray[currentUser.username].user = currentUser;
} }
savedCredentialsArray[currentUser.username].cookies = await webApiService.getCookies();
this.loginForm.savedCredentials = savedCredentialsArray; this.loginForm.savedCredentials = savedCredentialsArray;
var jsonCredentialsArray = JSON.stringify(savedCredentialsArray); var jsonCredentialsArray = JSON.stringify(savedCredentialsArray);
configRepository.setString('savedCredentials', jsonCredentialsArray); configRepository.setString('savedCredentials', jsonCredentialsArray);
@@ -5575,7 +5576,11 @@ speechSynthesis.getVoices();
configRepository.setString('lastUserLoggedIn', currentUser.username); 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) => { return new Promise((resolve, reject) => {
if (this.enablePrimaryPassword) { if (this.enablePrimaryPassword) {
this.checkPrimaryPassword(loginParmas) this.checkPrimaryPassword(loginParmas)
+1 -1
View File
@@ -20,7 +20,7 @@ html
h2(style="font-weight:bold;text-align:center;margin:0") Saved Accounts h2(style="font-weight:bold;text-align:center;margin:0") Saved Accounts
.x-friend-list(style="margin-top:10px") .x-friend-list(style="margin-top:10px")
.x-friend-item(v-for="user in loginForm.savedCredentials" :key="user.user.id") .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 .avatar
img(v-if="user.user.profilePicOverride" v-lazy="user.user.profilePicOverride") img(v-if="user.user.profilePicOverride" v-lazy="user.user.profilePicOverride")
img(v-else-if="displayVRCPlusIconsAsAvatar && user.user.userIcon" v-lazy="user.user.userIcon") img(v-else-if="displayVRCPlusIconsAsAvatar && user.user.userIcon" v-lazy="user.user.userIcon")
+8
View File
@@ -5,6 +5,14 @@ class WebApiService {
return WebApi.ClearCookies(); return WebApi.ClearCookies();
} }
getCookies() {
return WebApi.GetCookies();
}
setCookies(cookie) {
return WebApi.SetCookies(cookie);
}
execute(options) { execute(options) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
WebApi.Execute(options, (err, response) => { WebApi.Execute(options, (err, response) => {