mirror of
https://github.com/RetroShare/RSNewWebUI.git
synced 2026-09-14 02:55:47 +05:00
- added the option to change the hard-coded server-port at login page
- re-enabled the return-key to start login at password-input - respect the host and port from the url, overrideable with Query-Arguments named after ui visible names: Username, Port, Server), so you can create bookmarks with overridden defaults - fixed the identity-images and timestamps
This commit is contained in:
parent
3a59df5e1e
commit
60b4fe65cd
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,6 @@
|
||||
.qmake.stash
|
||||
Makefile
|
||||
webui/*
|
||||
webui.pro.user
|
||||
build.sh
|
||||
libwebui.so*
|
||||
|
||||
@ -5,20 +5,24 @@ const displayErrorMessage = function(message) {
|
||||
m.render(document.getElementById('error'), message);
|
||||
};
|
||||
|
||||
const verifyLogin = async function(uname, passwd, port) {
|
||||
const verifyLogin = async function(uname, passwd, port, url) {
|
||||
const loginHeader = {
|
||||
Authorization: 'Basic ' + btoa(uname + ':' + passwd)
|
||||
};
|
||||
rs.setKeys('', '', port, false);
|
||||
rs.setKeys('', '', port, false, url);
|
||||
rs.rsJsonApiRequest(
|
||||
'/rsPeers/GetRetroshareInvite',
|
||||
{},
|
||||
(data, successful) => {
|
||||
if (successful) {
|
||||
rs.setKeys(uname, passwd, port);
|
||||
rs.setKeys(uname, passwd, port, true, url);
|
||||
m.route.set('/home');
|
||||
} else {
|
||||
} else if (data.status == 401) {
|
||||
displayErrorMessage('Incorrect login/password.');
|
||||
} else if (data.status == 0) {
|
||||
displayErrorMessage(['Retroshare-jsonapi not available.',m('br'),'Please fix host and/or port.']);
|
||||
} else {
|
||||
displayErrorMessage('Login failed: HTTP ' + data.status + ' ' + data.statusText);
|
||||
}
|
||||
},
|
||||
true,
|
||||
@ -26,10 +30,12 @@ const verifyLogin = async function(uname, passwd, port) {
|
||||
);
|
||||
};
|
||||
|
||||
const loginComponent = function() {
|
||||
let uname = '';
|
||||
function loginComponent() {
|
||||
var urlParams = new URLSearchParams(window.location.search);
|
||||
let uname = urlParams.get('Username')||'';
|
||||
let passwd = '';
|
||||
let port = 9092;
|
||||
let port = Number(urlParams.get('Port') || window.location.protocol=='file:' ? '9092': window.location.port );
|
||||
let server = urlParams.get('Server')|| window.location.protocol=='file:' ? '127.0.0.1' : window.location.hostname;
|
||||
return {
|
||||
view: () => {
|
||||
return m(
|
||||
@ -39,30 +45,39 @@ const loginComponent = function() {
|
||||
src: '../data/retroshare.svg',
|
||||
alt: 'retroshare_icon'
|
||||
}),
|
||||
m('input[autofocus]', {
|
||||
m('input' + (uname == '' ? '[autofocus]':''), {
|
||||
type: 'text',
|
||||
value: uname,
|
||||
placeholder: 'Username',
|
||||
onchange: e => (uname = e.target.value)
|
||||
}),
|
||||
m('input', {
|
||||
m('input'+ (uname != '' ? '[autofocus]':''), {
|
||||
type: 'password',
|
||||
placeholder: 'Password',
|
||||
onchange: e => (passwd = e.target.value)
|
||||
onchange: e => (passwd = e.target.value),
|
||||
onkeyup: e => {if (e.code=='Enter') loginBtn.click();}
|
||||
}),
|
||||
m('.extra', [
|
||||
'Port:',
|
||||
m('input', {
|
||||
type: 'number',
|
||||
value: port,
|
||||
oninput: e => {
|
||||
port = e.target.value;
|
||||
}
|
||||
oninput: e => (port = e.target.value)
|
||||
})
|
||||
]),
|
||||
m('.extra',[
|
||||
'Server:',
|
||||
m('input',{
|
||||
type: 'text',
|
||||
value: server,
|
||||
oninput: e => (server = e.target.value)
|
||||
})
|
||||
]),
|
||||
m(
|
||||
'button.submit-btn',
|
||||
{
|
||||
onclick: () => verifyLogin(uname, passwd, port)
|
||||
id: 'loginBtn',
|
||||
onclick: () => verifyLogin(uname, passwd, port, 'http://' + server+':')
|
||||
},
|
||||
'Login'
|
||||
),
|
||||
|
||||
@ -132,7 +132,7 @@ const Identity = () => {
|
||||
details = data.details;
|
||||
// Creating URI during fetch because `details` is uninitialized
|
||||
// during view run, due to request being async.
|
||||
avatarURI = 'data:image/png;base64,' + data.details.mAvatar.mData;
|
||||
avatarURI = data.details.mAvatar.mData.base64 == '' ? '' : 'data:image/png;base64,' + data.details.mAvatar.mData.base64;
|
||||
},
|
||||
),
|
||||
view: v =>
|
||||
@ -154,9 +154,9 @@ const Identity = () => {
|
||||
m('p', 'Owner node ID:'),
|
||||
m('p', details.mPgpId),
|
||||
m('p', 'Created on:'),
|
||||
m('p', new Date(details.mPublishTS * 1000).toLocaleString()),
|
||||
m('p', typeof details.mPublishTS =='object' ? new Date(details.mPublishTS.xint64 * 1000).toLocaleString():'undefiend'),
|
||||
m('p', 'Last used:'),
|
||||
m('p', new Date(details.mLastUsageTS * 1000).toDateString()),
|
||||
m('p', typeof details.mLastUsageTS =='object' ? new Date(details.mLastUsageTS.xint64 * 1000).toLocaleDateString():'undefiend'),
|
||||
]),
|
||||
m(
|
||||
'button',
|
||||
|
||||
@ -5,15 +5,17 @@ let loginKey = {
|
||||
username: '',
|
||||
passwd: '',
|
||||
isVerified: false,
|
||||
port: 9092
|
||||
port: 9092,
|
||||
url: API_URL
|
||||
};
|
||||
|
||||
// Make this as object property?
|
||||
function setKeys(username, password, port = 9092, verified = true) {
|
||||
function setKeys(username, password, port = 9092, verified = true, url = API_URL) {
|
||||
loginKey.username = username;
|
||||
loginKey.passwd = password;
|
||||
loginKey.port = port;
|
||||
loginKey.isVerified = verified;
|
||||
loginKey.url = url;
|
||||
}
|
||||
|
||||
function rsJsonApiRequest(
|
||||
@ -36,13 +38,14 @@ function rsJsonApiRequest(
|
||||
return m
|
||||
.request({
|
||||
method: 'POST',
|
||||
url: API_URL + loginKey.port + path,
|
||||
url: loginKey.url + loginKey.port + path,
|
||||
async,
|
||||
extract: xhr => {
|
||||
// Empty string is not valid json and fails on parse
|
||||
let response = xhr.responseText || '""';
|
||||
return {
|
||||
status: xhr.status,
|
||||
statusText: xhr.statusText,
|
||||
body: handleDeserialize(response)
|
||||
};
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user