mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
old client structure
This commit is contained in:
38
website/client/src/libs/modform.js
Normal file
38
website/client/src/libs/modform.js
Normal file
@@ -0,0 +1,38 @@
|
||||
// @TODO: I have abstracted this in another PR. Use that function when merged
|
||||
function getApiKey () {
|
||||
let AUTH_SETTINGS = localStorage.getItem('habit-mobile-settings');
|
||||
|
||||
if (AUTH_SETTINGS) {
|
||||
AUTH_SETTINGS = JSON.parse(AUTH_SETTINGS);
|
||||
|
||||
if (AUTH_SETTINGS.auth && AUTH_SETTINGS.auth.apiId && AUTH_SETTINGS.auth.apiToken) {
|
||||
return AUTH_SETTINGS.auth.apiToken;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function goToModForm (user) {
|
||||
if (!user) return;
|
||||
|
||||
const apiKey = getApiKey();
|
||||
if (!apiKey) return;
|
||||
|
||||
const tenMins = 10 * 60 * 1000;
|
||||
let dateTime;
|
||||
dateTime = new Date();
|
||||
dateTime.setTime(dateTime.getTime() + tenMins);
|
||||
const expires = `expires=${dateTime.toGMTString()}`;
|
||||
|
||||
const email = encodeURIComponent(user.auth.local.email);
|
||||
|
||||
const userData = {
|
||||
email,
|
||||
profileName: user.profile.name,
|
||||
uuid: user._id,
|
||||
apiKey,
|
||||
};
|
||||
|
||||
document.cookie = `habiticauserdata=${JSON.stringify(userData)};${expires};domain=.habitica.com;path=/`;
|
||||
|
||||
window.location.href = 'https://contact.habitica.com';
|
||||
}
|
||||
Reference in New Issue
Block a user