@ -1,298 +0,0 @@ |
|||||||
Ext.define('Rambox.ux.Auth0', { |
|
||||||
singleton: true |
|
||||||
|
|
||||||
// private
|
|
||||||
,lock: null |
|
||||||
,auth0: null |
|
||||||
,authService: null |
|
||||||
,backupCurrent: false |
|
||||||
|
|
||||||
,init: function() { |
|
||||||
var me = this; |
|
||||||
|
|
||||||
var Auth0 = require('auth0-js'); |
|
||||||
var _AuthService = require('./resources/js/AuthService'); |
|
||||||
|
|
||||||
me.authService = new _AuthService.default({ |
|
||||||
clientId: auth0Cfg.clientID, |
|
||||||
authorizeEndpoint: 'https://'+auth0Cfg.domain+'/authorize', |
|
||||||
audience: 'https://'+auth0Cfg.domain+'/userinfo', |
|
||||||
scope: 'openid profile offline_access', |
|
||||||
redirectUri: 'https://'+auth0Cfg.domain+'/mobile', |
|
||||||
tokenEndpoint: 'https://'+auth0Cfg.domain+'/oauth/token' |
|
||||||
}); |
|
||||||
|
|
||||||
me.auth0 = new Auth0.WebAuth({ clientID: auth0Cfg.clientID, domain : auth0Cfg.domain }); |
|
||||||
|
|
||||||
//me.defineEvents();
|
|
||||||
} |
|
||||||
|
|
||||||
,onLogin: function(token, authWindow) { |
|
||||||
var me = this; |
|
||||||
|
|
||||||
authWindow.close(); |
|
||||||
|
|
||||||
me.auth0.client.userInfo(token.access_token, function(err, profile) { |
|
||||||
if ( err ) { |
|
||||||
if ( err.error === 401 || err.error === 'Unauthorized' ) return me.renewToken(me.checkConfiguration); |
|
||||||
Ext.Msg.hide(); |
|
||||||
return Ext.Msg.show({ |
|
||||||
title: 'Error' |
|
||||||
,message: 'There was an error getting the profile: ' + err.error_description |
|
||||||
,icon: Ext.Msg.ERROR |
|
||||||
,buttons: Ext.Msg.OK |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
profile.user_metadata = profile['https://rambox.pro/user_metadata']; |
|
||||||
delete profile['https://rambox.pro/user_metadata']; |
|
||||||
|
|
||||||
// Display a spinner while waiting
|
|
||||||
Ext.Msg.wait(locale['app.window[29]'], locale['app.window[28]']); |
|
||||||
|
|
||||||
// Google Analytics Event
|
|
||||||
ga_storage._trackEvent('Users', 'loggedIn'); |
|
||||||
|
|
||||||
// Set cookies to help Tooltip.io messages segmentation
|
|
||||||
Ext.util.Cookies.set('auth0', true); |
|
||||||
|
|
||||||
// User is logged in
|
|
||||||
// Save the profile and JWT.
|
|
||||||
localStorage.setItem('profile', JSON.stringify(profile)); |
|
||||||
localStorage.setItem('access_token', token.access_token); |
|
||||||
localStorage.setItem('id_token', token.id_token); |
|
||||||
localStorage.setItem('refresh_token', token.refresh_token); |
|
||||||
|
|
||||||
if ( !Ext.isEmpty(profile.user_metadata) && !Ext.isEmpty(profile.user_metadata.services) && !me.backupCurrent ) { |
|
||||||
Ext.each(profile.user_metadata.services, function(s) { |
|
||||||
var service = Ext.create('Rambox.model.Service', s); |
|
||||||
service.save(); |
|
||||||
Ext.getStore('Services').add(service); |
|
||||||
}); |
|
||||||
|
|
||||||
require('electron').remote.app.relaunch(); |
|
||||||
require('electron').remote.app.exit(); |
|
||||||
} |
|
||||||
|
|
||||||
Ext.Msg.hide(); |
|
||||||
Ext.cq1('app-main').getViewModel().set('username', profile.name); |
|
||||||
Ext.cq1('app-main').getViewModel().set('avatar', profile.picture); |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
,backupConfiguration: function(callback) { |
|
||||||
var me = this; |
|
||||||
|
|
||||||
Ext.Msg.wait('Saving backup...', 'Please wait...'); |
|
||||||
|
|
||||||
// Getting all services
|
|
||||||
var lastupdate = (new Date()).toJSON(); |
|
||||||
var services = []; |
|
||||||
Ext.getStore('Services').each(function(service) { |
|
||||||
var s = Ext.clone(service); |
|
||||||
delete s.data.id; |
|
||||||
delete s.data.zoomLevel; |
|
||||||
services.push(s.data); |
|
||||||
}); |
|
||||||
|
|
||||||
Ext.Ajax.request({ |
|
||||||
url: 'https://rambox.auth0.com/api/v2/users/'+Ext.decode(localStorage.getItem('profile')).sub |
|
||||||
,method: 'PATCH' |
|
||||||
,headers: { authorization: "Bearer " + localStorage.getItem('id_token') } |
|
||||||
,jsonData: { user_metadata: { services: services, services_lastupdate: lastupdate } } |
|
||||||
,success: function(response) { |
|
||||||
Ext.Msg.hide(); |
|
||||||
// Save the last update in localStorage
|
|
||||||
var profile = Ext.decode(localStorage.getItem('profile')); |
|
||||||
if ( !profile.user_metadata ) profile.user_metadata = {}; |
|
||||||
profile.user_metadata.services_lastupdate = lastupdate; |
|
||||||
localStorage.setItem('profile', Ext.encode(profile)); |
|
||||||
Ext.cq1('app-main').getViewModel().set('last_sync', new Date(lastupdate).toUTCString()); |
|
||||||
|
|
||||||
Ext.toast({ |
|
||||||
html: '<i class="fa fa-check fa-3x fa-pull-left" aria-hidden="true"></i> Your configuration were successfully backed up.' |
|
||||||
,title: 'Synchronize Configuration' |
|
||||||
,width: 300 |
|
||||||
,align: 't' |
|
||||||
,closable: false |
|
||||||
}); |
|
||||||
|
|
||||||
if ( Ext.isFunction(callback) ) callback.bind(me)(); |
|
||||||
} |
|
||||||
,failure: function(response) { |
|
||||||
if ( response.status === 401 ) return me.renewToken(me.backupConfiguration); |
|
||||||
|
|
||||||
Ext.Msg.hide(); |
|
||||||
Ext.toast({ |
|
||||||
html: '<i class="fa fa-times fa-3x fa-pull-left" aria-hidden="true"></i> Error occurred when trying to backup your configuration.' |
|
||||||
,title: 'Synchronize Configuration' |
|
||||||
,width: 300 |
|
||||||
,align: 't' |
|
||||||
,closable: false |
|
||||||
}); |
|
||||||
|
|
||||||
if ( Ext.isFunction(callback) ) callback.bind(me)(); |
|
||||||
|
|
||||||
console.error(response); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
,restoreConfiguration: function() { |
|
||||||
var me = this; |
|
||||||
|
|
||||||
me.auth0.client.userInfo(localStorage.getItem('access_token'), function(err, profile) { |
|
||||||
if ( err ) { |
|
||||||
if ( err.code === 401 ) return me.renewToken(me.restoreConfiguration); |
|
||||||
return Ext.Msg.show({ |
|
||||||
title: 'Error' |
|
||||||
,message: 'There was an error getting the profile: ' + err.description |
|
||||||
,icon: Ext.Msg.ERROR |
|
||||||
,buttons: Ext.Msg.OK |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
profile.user_metadata = profile['https://rambox.pro/user_metadata']; |
|
||||||
delete profile['https://rambox.pro/user_metadata']; |
|
||||||
|
|
||||||
// First we remove all current services
|
|
||||||
Ext.cq1('app-main').getController().removeAllServices(false, function() { |
|
||||||
if ( !profile.user_metadata || !profile.user_metadata.services ) return; |
|
||||||
Ext.each(profile.user_metadata.services, function(s) { |
|
||||||
var service = Ext.create('Rambox.model.Service', s); |
|
||||||
service.save(); |
|
||||||
Ext.getStore('Services').add(service); |
|
||||||
}); |
|
||||||
|
|
||||||
require('electron').remote.getCurrentWindow().reload(); |
|
||||||
}); |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
,checkConfiguration: function() { |
|
||||||
var me = this; |
|
||||||
|
|
||||||
me.auth0.client.userInfo(localStorage.getItem('access_token'), function(err, profile) { |
|
||||||
if ( err ) { |
|
||||||
if ( err.code === 401 ) return me.renewToken(me.checkConfiguration); |
|
||||||
return Ext.Msg.show({ |
|
||||||
title: 'Error' |
|
||||||
,message: 'There was an error getting the profile: ' + err.description |
|
||||||
,icon: Ext.Msg.ERROR |
|
||||||
,buttons: Ext.Msg.OK |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
profile.user_metadata = profile['https://rambox.pro/user_metadata']; |
|
||||||
delete profile['https://rambox.pro/user_metadata']; |
|
||||||
|
|
||||||
if ( !profile.user_metadata ) { |
|
||||||
Ext.toast({ |
|
||||||
html: 'You don\'t have any backup yet.' |
|
||||||
,title: 'Synchronize Configuration' |
|
||||||
,width: 300 |
|
||||||
,align: 't' |
|
||||||
,closable: false |
|
||||||
}); |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
if ( Math.floor(new Date(profile.user_metadata.services_lastupdate) / 1000) > Math.floor(new Date(Ext.decode(localStorage.getItem('profile')).user_metadata.services_lastupdate) / 1000) ) { |
|
||||||
Ext.toast({ |
|
||||||
html: 'Your settings are out of date.' |
|
||||||
,title: 'Synchronize Configuration' |
|
||||||
,width: 300 |
|
||||||
,align: 't' |
|
||||||
,closable: false |
|
||||||
}); |
|
||||||
} else { |
|
||||||
Ext.toast({ |
|
||||||
html: '<i class="fa fa-check fa-3x fa-pull-left" aria-hidden="true"></i> Latest backup is already applied.' |
|
||||||
,title: 'Synchronize Configuration' |
|
||||||
,width: 300 |
|
||||||
,align: 't' |
|
||||||
,closable: false |
|
||||||
}); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
,renewToken: function(callback) { |
|
||||||
var me = this; |
|
||||||
|
|
||||||
Ext.Ajax.request({ |
|
||||||
url: 'https://rambox.auth0.com/oauth/token' |
|
||||||
,method: 'POST' |
|
||||||
,jsonData: { |
|
||||||
grant_type: 'refresh_token' |
|
||||||
,client_id: auth0Cfg.clientID |
|
||||||
,client_secret: auth0Cfg.clientSecret |
|
||||||
,refresh_token: localStorage.getItem('refresh_token') |
|
||||||
,api_type: 'app' |
|
||||||
} |
|
||||||
,success: function(response) { |
|
||||||
var json = Ext.decode(response.responseText); |
|
||||||
localStorage.setItem('access_token', json.access_token); |
|
||||||
localStorage.setItem('id_token', json.id_token); |
|
||||||
|
|
||||||
if ( Ext.isFunction(callback) ) callback.bind(me)(); |
|
||||||
} |
|
||||||
,failure: function(response) { |
|
||||||
console.error(response); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
,login: function() { |
|
||||||
var me = this; |
|
||||||
|
|
||||||
var electron = require('electron').remote; |
|
||||||
var authWindow = new electron.BrowserWindow({ |
|
||||||
title: 'Rambox - Login' |
|
||||||
,width: 400 |
|
||||||
,height: 600 |
|
||||||
,maximizable: false |
|
||||||
,minimizable: false |
|
||||||
,resizable: true |
|
||||||
,closable: true |
|
||||||
,center: true |
|
||||||
,autoHideMenuBar: true |
|
||||||
,skipTaskbar: true |
|
||||||
,fullscreenable: false |
|
||||||
,parent: require('electron').remote.getCurrentWindow() |
|
||||||
,webPreferences: { |
|
||||||
partition: 'persist:rambox' |
|
||||||
} |
|
||||||
}); |
|
||||||
|
|
||||||
authWindow.on('closed', function() { |
|
||||||
authWindow = null; |
|
||||||
}); |
|
||||||
|
|
||||||
authWindow.loadURL(me.authService.requestAuthCode()); |
|
||||||
|
|
||||||
authWindow.webContents.on('did-start-loading', function(e) { |
|
||||||
authWindow.webContents.session.webRequest.onBeforeSendHeaders((details, callback) => { |
|
||||||
Rambox.app.config.googleURLs.forEach((loginURL) => { |
|
||||||
if ( details.url.indexOf(loginURL) > -1 ) details.requestHeaders['User-Agent'] = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0' }) |
|
||||||
callback({ cancel: false, requestHeaders: details.requestHeaders }); |
|
||||||
}); |
|
||||||
}); |
|
||||||
|
|
||||||
authWindow.webContents.on('did-navigate', function(e, url) { |
|
||||||
me.authService.requestAccessCode(url, me.onLogin.bind(me), authWindow); |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
,logout: function() { |
|
||||||
var me = this; |
|
||||||
|
|
||||||
localStorage.removeItem('profile'); |
|
||||||
localStorage.removeItem('id_token'); |
|
||||||
localStorage.removeItem('refresh_token'); |
|
||||||
localStorage.removeItem('access_token'); |
|
||||||
|
|
||||||
// Set cookies to help Tooltip.io messages segmentation
|
|
||||||
Ext.util.Cookies.set('auth0', false); |
|
||||||
} |
|
||||||
}); |
|
@ -1,5 +0,0 @@ |
|||||||
var auth0Cfg = { |
|
||||||
clientID: '' |
|
||||||
,clientSecret: '' |
|
||||||
,domain: '' |
|
||||||
}; |
|
@ -1,146 +0,0 @@ |
|||||||
html, body { |
|
||||||
width: 100%; |
|
||||||
height: 100%; |
|
||||||
margin: 0; |
|
||||||
overflow: hidden; |
|
||||||
} |
|
||||||
|
|
||||||
.screen-selector { |
|
||||||
background-color: #fff; |
|
||||||
width: 100%; |
|
||||||
height: 100%; |
|
||||||
border-radius: 5px; |
|
||||||
border: solid 1px #cdcdcd; |
|
||||||
box-sizing: border-box; |
|
||||||
} |
|
||||||
|
|
||||||
.screen-selector ul.type { |
|
||||||
display: inline-block; |
|
||||||
padding: 0; |
|
||||||
margin: 0; |
|
||||||
border-bottom: solid 1px #cdcdcd; |
|
||||||
width: 100%; |
|
||||||
-webkit-app-region: drag; |
|
||||||
} |
|
||||||
|
|
||||||
.screen-selector ul.type li { |
|
||||||
display: inline-block; |
|
||||||
height: 40px; |
|
||||||
line-height: 40px; |
|
||||||
color: #65696c; |
|
||||||
border-bottom: 2px solid transparent; |
|
||||||
font-family: sans-serif; |
|
||||||
font-weight: bold; |
|
||||||
padding: 0 15px; |
|
||||||
cursor: pointer; |
|
||||||
-webkit-app-region: no-drag; |
|
||||||
} |
|
||||||
|
|
||||||
.screen-selector ul.type li.active, .screen-selector ul.type li:hover { |
|
||||||
color: #426ba3; |
|
||||||
border-color: #426ba3; |
|
||||||
} |
|
||||||
|
|
||||||
.screen-selector > .content { |
|
||||||
height: calc(100% - 92px); |
|
||||||
} |
|
||||||
|
|
||||||
.screen-selector ul.preview { |
|
||||||
display: flex; |
|
||||||
margin: 0; |
|
||||||
padding: 0; |
|
||||||
width: 100%; |
|
||||||
max-height: calc(100% - 45px); |
|
||||||
box-sizing: border-box; |
|
||||||
padding: 10px; |
|
||||||
overflow-y: auto; |
|
||||||
flex-wrap: wrap; |
|
||||||
list-style-type: none; |
|
||||||
} |
|
||||||
|
|
||||||
.screen-selector ul.preview li { |
|
||||||
display: inline-block; |
|
||||||
box-sizing: border-box; |
|
||||||
width: calc(33% - 1px); |
|
||||||
cursor: pointer; |
|
||||||
padding: 5px; |
|
||||||
} |
|
||||||
|
|
||||||
.screen-selector ul.preview li .content { |
|
||||||
display: flex; |
|
||||||
box-sizing: border-box; |
|
||||||
padding: 10px; |
|
||||||
border: solid 2px transparent; |
|
||||||
border-radius: 5px; |
|
||||||
height: 100%; |
|
||||||
flex-direction: column; |
|
||||||
} |
|
||||||
|
|
||||||
.screen-selector ul.preview li.active .content, |
|
||||||
.screen-selector ul.preview li:hover .content { |
|
||||||
border-color: #88abdb; |
|
||||||
} |
|
||||||
|
|
||||||
.screen-selector ul.preview li.active .content { |
|
||||||
color: #000; |
|
||||||
height: 100%; |
|
||||||
} |
|
||||||
|
|
||||||
.screen-selector ul.preview li .content .img-wrapper { |
|
||||||
display: flex; |
|
||||||
height: 100%; |
|
||||||
align-items: center; |
|
||||||
background: #f0f0f0; |
|
||||||
} |
|
||||||
|
|
||||||
.screen-selector ul.preview li .content img { |
|
||||||
display: inline-block; |
|
||||||
width: 100%; |
|
||||||
} |
|
||||||
|
|
||||||
.screen-selector ul.preview li .content span { |
|
||||||
display: inline-block; |
|
||||||
width: 100%; |
|
||||||
font-family: sans-serif; |
|
||||||
text-align: center; |
|
||||||
font-size: 14px; |
|
||||||
margin-top: 10px; |
|
||||||
color: #333; |
|
||||||
box-sizing: border-box; |
|
||||||
} |
|
||||||
|
|
||||||
.screen-selector .footer { |
|
||||||
display: inline-block; |
|
||||||
width: 100%; |
|
||||||
border-top: solid 1px #cdcdcd; |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
.screen-selector .footer button { |
|
||||||
float: right; |
|
||||||
margin-top: 10px; |
|
||||||
margin-right: 10px; |
|
||||||
border: none; |
|
||||||
border-radius: 5px; |
|
||||||
padding: 5px 10px; |
|
||||||
font-size: 14px; |
|
||||||
cursor: pointer; |
|
||||||
font-weight: bold; |
|
||||||
} |
|
||||||
|
|
||||||
.screen-selector .footer button#cancel { |
|
||||||
border: solid 1px #cdcdcd; |
|
||||||
background: #fff; |
|
||||||
color: #1c73e4; |
|
||||||
} |
|
||||||
|
|
||||||
.screen-selector .footer button#share { |
|
||||||
border: solid 1px #186ddd; |
|
||||||
background: #1c73e4; |
|
||||||
color: #fff; |
|
||||||
} |
|
||||||
|
|
||||||
.screen-selector .footer button#share[disabled] { |
|
||||||
background: #666; |
|
||||||
cursor: default; |
|
||||||
} |
|
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 62 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 6.9 KiB |
After Width: | Height: | Size: 4.6 KiB |
After Width: | Height: | Size: 9.7 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 8.6 KiB |
After Width: | Height: | Size: 3.9 KiB |
After Width: | Height: | Size: 2.9 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 3.4 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 2.4 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 2.8 KiB |
After Width: | Height: | Size: 8.5 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 6.3 KiB |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 4.6 KiB |
After Width: | Height: | Size: 4.7 KiB |
After Width: | Height: | Size: 4.1 KiB |
After Width: | Height: | Size: 3.9 KiB |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 6.2 KiB |
After Width: | Height: | Size: 700 B |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 6.6 KiB |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 5.1 KiB |
After Width: | Height: | Size: 4.2 KiB |
After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 4.8 KiB |
After Width: | Height: | Size: 5.5 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 2.5 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 5.6 KiB |
After Width: | Height: | Size: 9.1 KiB |
After Width: | Height: | Size: 4.7 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 5.0 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 3.2 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 5.3 KiB |
After Width: | Height: | Size: 4.2 KiB |
After Width: | Height: | Size: 6.4 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 2.8 KiB |
After Width: | Height: | Size: 8.5 KiB |
After Width: | Height: | Size: 8.5 KiB |
After Width: | Height: | Size: 3.9 KiB |
After Width: | Height: | Size: 9.4 KiB |
After Width: | Height: | Size: 6.0 KiB |
After Width: | Height: | Size: 2.9 KiB |
After Width: | Height: | Size: 2.8 KiB |
After Width: | Height: | Size: 5.8 KiB |
After Width: | Height: | Size: 5.4 KiB |
After Width: | Height: | Size: 6.8 KiB |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 61 KiB |
After Width: | Height: | Size: 4.0 KiB |