OAuth and bugfixes
This commit is contained in:
parent
e58a1f69dc
commit
d43c18bb76
65 changed files with 1681 additions and 1494 deletions
|
@ -43,10 +43,11 @@ Dialog {
|
|||
standardButtons: Dialog.Yes | Dialog.No
|
||||
modal: true
|
||||
onAccepted: {
|
||||
username.visible=true;
|
||||
password.visible=true;
|
||||
// username.visible=true;
|
||||
// password.visible=true;
|
||||
ruleButton.visible=false;
|
||||
confirmation.visible=true
|
||||
// confirmation.visible=true
|
||||
accountPage.state="oauth"
|
||||
}
|
||||
onRejected: {close()}
|
||||
ScrollView{
|
||||
|
|
|
@ -35,7 +35,6 @@ import QtQuick.Controls 2.12
|
|||
import QtQuick.Layouts 1.12
|
||||
import QtQml.Models 2.15
|
||||
import "qrc:/js/service.js" as Service
|
||||
import "qrc:/js/layout.js" as Layoutjs
|
||||
import "qrc:/js/helper.js" as Helperjs
|
||||
import "qrc:/qml/configqml"
|
||||
import "qrc:/qml/genericqml"
|
||||
|
@ -47,18 +46,56 @@ Page{
|
|||
property var users:[]
|
||||
property var userdata: ({})
|
||||
property string imagestoredir: ""
|
||||
|
||||
property var appdata: ({})
|
||||
|
||||
function setServericon(server){
|
||||
if ((server!=null) && (server!="")){
|
||||
try {Helperjs.friendicaWebRequest(server+"/api/statusnet/config",accountPage, function (obj){
|
||||
var serverdata = JSON.parse(obj);
|
||||
servericon.visible=true;
|
||||
servericon.source=serverdata.site.logo})
|
||||
} catch(e){print(e)}
|
||||
xhr.setUrl(server);
|
||||
xhr.setApi("/api/statusnet/config");
|
||||
xhr.clearParams();
|
||||
xhr.get();
|
||||
}
|
||||
}
|
||||
|
||||
function verify(userconfig){
|
||||
Helperjs.friendicaRequest(userconfig,"/api/v1/accounts/verify_credentials",root,function(obj){
|
||||
accountBusy.running=false;
|
||||
try{var credentials=JSON.parse(obj);
|
||||
if (credentials.hasOwnProperty('error')){
|
||||
Helperjs.showMessage(qsTr("Error"),qsTr("Wrong password or 2FA enabled!"),root)
|
||||
}
|
||||
else{
|
||||
if (users.length==0){Service.setDefaultOptions(db);}
|
||||
if (userconfig.APIVersion!=""){userconfig.password=""}
|
||||
if (imagestoredir==""){imagestoredir=filesystem.homePath+"/"+credentials.username+"/";
|
||||
userconfig.imagestore=imagestoredir}
|
||||
if(userconfig.imagestore == filesystem.homePath+"/"+username.text+"/")
|
||||
{filesystem.makePath(filesystem.homePath+"/"+username.text);}
|
||||
filesystem.Directory=imagestoredir;
|
||||
filesystem.makeDir("contacts");
|
||||
filesystem.makeDir("albums");
|
||||
userconfig.accountId=credentials.id;
|
||||
userconfig.username=credentials.username;
|
||||
Service.storeConfig(db,userconfig);
|
||||
Service.readConfig(db,function(userconfig){
|
||||
Helperjs.readData(db,"config","",function(storedUsers){
|
||||
storedUsers.sort(function(obj1, obj2) {
|
||||
return obj1.isActive - obj2.isActive;
|
||||
});
|
||||
accountPage.users=storedUsers});
|
||||
//reset values
|
||||
login=userconfig;
|
||||
news=[];
|
||||
contactlist=[];
|
||||
rootstack.currentIndex=0;
|
||||
newstypeSignal("refresh");
|
||||
},"isActive",0);
|
||||
Helperjs.showMessage(qsTr("Success"),qsTr("Name")+": "+credentials.display_name+"\nScreen Name: "+credentials.username,root)
|
||||
rootstackView.pop()
|
||||
}
|
||||
}catch(e){Helperjs.showMessage(qsTr("Error"),qsTr("Wrong password or 2FA enabled!"),root)};
|
||||
})}
|
||||
|
||||
MButton{
|
||||
id:userButton
|
||||
text:qsTr("User")
|
||||
|
@ -82,6 +119,8 @@ Page{
|
|||
imagestore.text=obj.imagestore;
|
||||
imagestoredir=obj.imagestore;
|
||||
if( obj.isActive==0){userButton.font.bold='true'} else {userButton.font.bold='false'}
|
||||
if(obj.password!=''){accountPage.state='password'}
|
||||
else if (obj.token!=''){accountPage.state='oauth'}
|
||||
},'username','"+ accountPage.users[i].username+"')}}"
|
||||
}
|
||||
var menuString="import QtQuick.Controls 2.12;import 'qrc:/js/service.js' as Service;"+
|
||||
|
@ -96,11 +135,18 @@ Page{
|
|||
width:2.5*root.fontFactor*osSettings.bigFontSize; height: 2.5*root.fontFactor*osSettings.bigFontSize
|
||||
visible: false
|
||||
source:""
|
||||
property var serverconfig:({})
|
||||
MouseArea{
|
||||
anchors.fill:parent
|
||||
onClicked:{
|
||||
Service.showServerConfig(servername.text, accountPage, function(configString){
|
||||
var serverconfigObject=Qt.createQmlObject(configString,accountPage,"serverconfigOutput");})
|
||||
let serverConfigString="import QtQuick 2.0; import QtQuick.Dialogs 1.2; MessageDialog{ visible: true; title:'Server';standardButtons: StandardButton.Ok;text: 'Name: "+
|
||||
servericon.serverconfig.site.name+"\nLanguage: "+servericon.serverconfig.site.language+
|
||||
"\nEmail: "+servericon.serverconfig.site.email+"\nTimezone: "+servericon.serverconfig.site.timezone+"\nClosed: "+servericon.serverconfig.site.closed+
|
||||
"\nText limit: "+servericon.serverconfig.site.textlimit+"\nShort Url length: "+servericon.serverconfig.site.shorturllength+
|
||||
"\nFriendica version: "+servericon.serverconfig.site.friendica.FRIENDICA_VERSION+
|
||||
"\nDB Update version: "+servericon.serverconfig.site.friendica.DB_UPDATE_VERSION+"'}";
|
||||
|
||||
var serverconfigObject=Qt.createQmlObject(serverConfigString,accountPage,"serverconfigOutput");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -180,22 +226,23 @@ Page{
|
|||
}
|
||||
|
||||
ListModel{id:serverModel
|
||||
ListElement{text:"https://anonsys.net"}
|
||||
ListElement{text:"https://asaps-sm.lafayettegroup.com"}
|
||||
ListElement{text:"https://f.freinetz.ch"}
|
||||
ListElement{text:"https://friendica.chilemasto.casa"}
|
||||
ListElement{text:"https://friendica.eskimo.com"}
|
||||
ListElement{text:"https://friendica.me"}
|
||||
ListElement{text:"https://friendica.opensocial.space"}
|
||||
ListElement{text:"https://friendica.utzer.de"}
|
||||
ListElement{text:"https://friendica.vrije-mens.org"}
|
||||
ListElement{text:"https://friendicarg.nsupdate.info.de"}
|
||||
ListElement{text:"https://friends.nogafam.es"}
|
||||
ListElement{text:"https://libranet.de"}
|
||||
ListElement{text:"https://loma.ml"}
|
||||
ListElement{text:"https://social.trom.tf"}
|
||||
ListElement{text:"https://motley.club"}
|
||||
ListElement{text:"https://nerdica.net"}
|
||||
ListElement{text:"https://noovi.org"}
|
||||
ListElement{text:"https://nsfw.wnymathguy.com"}
|
||||
ListElement{text:"https://opensocial.at"}
|
||||
ListElement{text:"https://poliverso.org"}
|
||||
ListElement{text:"https://social.isurf.ca"}
|
||||
ListElement{text:"https://social.trom.tf"}
|
||||
ListElement{text:"https://squeet.me"}
|
||||
ListElement{text:"https://venera.social"}
|
||||
}
|
||||
|
@ -208,16 +255,10 @@ Page{
|
|||
text: qsTr("Instance rules")
|
||||
font.pointSize: osSettings.bigFontSize
|
||||
onClicked:{
|
||||
Helperjs.friendicaWebRequest(servername.text+"/api/v1/instance/rules",root,function(rules){
|
||||
let rulestext="";
|
||||
let rulesarray=JSON.parse(rules)
|
||||
for (let rule in rulesarray){
|
||||
rulestext=rulestext+rulesarray[rule].text+"\n"
|
||||
}
|
||||
var component = Qt.createComponent("qrc:/qml/configqml/AcceptRules.qml");
|
||||
var rulesdialog = component.createObject(root,{"rules": rulestext});
|
||||
rulesdialog.open()
|
||||
})
|
||||
xhr.setUrl(servername.text);
|
||||
xhr.setApi("/api/v1/instance/rules");
|
||||
xhr.clearParams();
|
||||
xhr.get();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -237,7 +278,6 @@ Page{
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
TextField {
|
||||
id: password
|
||||
x: root.fontFactor*osSettings.bigFontSize; y: 9*root.fontFactor*osSettings.bigFontSize; width: root.width-9*mm; //height: 5*mm;
|
||||
|
@ -298,62 +338,119 @@ Page{
|
|||
running: false
|
||||
}
|
||||
|
||||
MButton {
|
||||
id:confirmationOAuth
|
||||
x: root.fontFactor*osSettings.bigFontSize; y: 16*root.fontFactor*osSettings.bigFontSize
|
||||
text: qsTr("Connect")
|
||||
font.pointSize: osSettings.bigFontSize
|
||||
visible: (osSettings.osType=="Android")?userButton.text!= qsTr("User"):true
|
||||
onClicked:{
|
||||
if (servername.text==""){Helperjs.showMessage(qsTr("Error"), qsTr("No server given!"),root)}
|
||||
else{
|
||||
xhr.setUrl(servername.text);
|
||||
xhr.setApi("/api/v1/apps");
|
||||
xhr.clearParams();
|
||||
if (osSettings.osType=="Android"){
|
||||
xhr.setParam("client_name","Friendiqa-Android");
|
||||
} else {
|
||||
xhr.setParam("client_name","Friendiqa-"+filesystem.hostname);
|
||||
}
|
||||
xhr.setParam("redirect_uris","http://127.0.0.1:1337/");
|
||||
xhr.setParam("scopes","read write follow push");
|
||||
xhr.setParam("website","https://friendiqa.ma-nic.de");
|
||||
xhr.post();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Connections{
|
||||
target: xhr
|
||||
function onSuccess(text,api){
|
||||
if(api=="/api/v1/instance/rules"){
|
||||
let rulestext="";
|
||||
let rulesarray=JSON.parse(text)
|
||||
for (let rule in rulesarray){
|
||||
rulestext=rulestext+rulesarray[rule].text+"\n"
|
||||
}
|
||||
var component = Qt.createComponent("qrc:/qml/configqml/AcceptRules.qml");
|
||||
var rulesdialog = component.createObject(root,{"rules": rulestext});
|
||||
rulesdialog.open();
|
||||
}
|
||||
else if(api=="/api/statusnet/config"){
|
||||
try{let serverdata = JSON.parse(text);
|
||||
servericon.visible=true;
|
||||
servericon.source=serverdata.site.logo;
|
||||
servericon.serverconfig=serverdata;
|
||||
}
|
||||
catch(e){print(e)}
|
||||
}
|
||||
|
||||
else if (api=="/api/v1/apps"){
|
||||
let app=JSON.parse(text);
|
||||
accountPage.appdata=app;
|
||||
oauth2.setClientId(app.client_id);
|
||||
oauth2.setClientSecret(app.client_secret);
|
||||
oauth2.setServer(servername.text);
|
||||
oauth2.grant();
|
||||
}
|
||||
}
|
||||
function onError(text,api){
|
||||
print(api + " Error "+ text)
|
||||
}
|
||||
}
|
||||
|
||||
Connections{
|
||||
target: oauth2
|
||||
function onSuccess(text){
|
||||
var userconfig={server: servername.displayText, username:"", password:"", imagestore: imagestoredir,interval:"",token: text,client:Qt.btoa(JSON.stringify(appdata))}
|
||||
verify(userconfig)
|
||||
}
|
||||
function onError(text){
|
||||
Helperjs.showMessage(qsTr("Error"), qsTr("Couldn't connect to server"),root)
|
||||
print ("oauth2 onerror "+text)
|
||||
}
|
||||
}
|
||||
|
||||
MButton {
|
||||
id:confirmation
|
||||
x: root.fontFactor*osSettings.bigFontSize; y: 16*root.fontFactor*osSettings.bigFontSize
|
||||
text: qsTr("Confirm")
|
||||
font.pointSize: osSettings.bigFontSize
|
||||
visible: (osSettings.osType=="Android")?userButton.text!= qsTr("User"):true
|
||||
visible: false// (osSettings.osType=="Android")?userButton.text!= qsTr("User"):true
|
||||
onClicked:{
|
||||
accountBusy.running=true;//servername.displayText
|
||||
var userconfig={server: servername.displayText, username: username.text, password:Qt.btoa(password.text), imagestore:imagestoredir,interval: ""};
|
||||
accountBusy.running=true;
|
||||
var userconfig={server: servername.displayText, username: username.text, password:Qt.btoa(password.text), imagestore:imagestoredir,interval:""};
|
||||
var errormessage="";
|
||||
if (servername.text==""){errormessage=qsTr("No server given! ")}
|
||||
else if (username.text==""){errormessage+=qsTr("No nickname given! ")}
|
||||
else if (password.text=="") {errormessage+=qsTr("No password given! ")}
|
||||
else if (imagestoredir=="") {errormessage+=qsTr("No image directory given!")}
|
||||
|
||||
else {errormessage=""}
|
||||
if (errormessage=="") {
|
||||
Helperjs.friendicaRequest(userconfig,"/api/account/verify_credentials.json?skip_status=true",root,function(obj){
|
||||
accountBusy.running=false;
|
||||
try{var credentials=JSON.parse(obj);
|
||||
if (credentials.hasOwnProperty('error')){
|
||||
Helperjs.showMessage(qsTr("Error"),qsTr("Wrong password or 2FA enabled!"),root)
|
||||
}
|
||||
else{
|
||||
if (users.length==0){Service.setDefaultOptions(db);}
|
||||
if(userconfig.imagestore == filesystem.homePath+"/"+username.text+"/")
|
||||
{
|
||||
filesystem.makePath(filesystem.homePath+"/"+username.text);
|
||||
}
|
||||
filesystem.Directory=imagestoredir
|
||||
filesystem.makeDir("contacts");
|
||||
filesystem.makeDir("albums");
|
||||
userconfig.accountId=credentials.id
|
||||
Service.storeConfig(db,userconfig);
|
||||
Service.readConfig(db,function(userconfig){
|
||||
Helperjs.readData(db,"config","",function(storedUsers){
|
||||
storedUsers.sort(function(obj1, obj2) {
|
||||
return obj1.isActive - obj2.isActive;
|
||||
});
|
||||
accountPage.users=storedUsers});
|
||||
//reset values
|
||||
login=userconfig;
|
||||
news=[];
|
||||
contactlist=[];
|
||||
rootstack.currentIndex=0;
|
||||
newstypeSignal("refresh");
|
||||
},"isActive",0);
|
||||
Helperjs.showMessage(qsTr("Success"),qsTr("Name")+": "+credentials.name+"\nScreen Name: "+credentials.screen_name,root)
|
||||
rootstackView.pop()
|
||||
}
|
||||
}catch(e){Helperjs.showMessage(qsTr("Error"),qsTr("Wrong password or 2FA enabled!"),root)};
|
||||
|
||||
})}
|
||||
else {Helperjs.showMessage(qsTr("Error"), errormessage,root)}
|
||||
if (errormessage=="") {verify(userconfig)}
|
||||
else {Helperjs.showMessage(qsTr("Error"), errormessage,root)}
|
||||
}}
|
||||
|
||||
MButton {
|
||||
id: setDefault
|
||||
x: 10*root.fontFactor*osSettings.bigFontSize; y: 16*root.fontFactor*osSettings.bigFontSize
|
||||
text: qsTr("Set as default")
|
||||
font.pointSize: osSettings.bigFontSize
|
||||
visible: false
|
||||
onClicked:{
|
||||
accountBusy.running=true;
|
||||
let users=updatenews.getAccounts("username",username.text)
|
||||
Service.storeConfig(db,users[0]);
|
||||
Service.readConfig(db,function(userconfig){
|
||||
//reset values
|
||||
login=userconfig;
|
||||
news=[];
|
||||
contactlist=[];
|
||||
rootstack.currentIndex=0;
|
||||
newstypeSignal("refresh");
|
||||
},"isActive",0);
|
||||
Helperjs.showMessage(qsTr("Success"),"Screen Name: "+users[0].username,root)
|
||||
rootstackView.pop()
|
||||
}}
|
||||
|
||||
Row{
|
||||
spacing:0.5*mm
|
||||
|
@ -368,6 +465,19 @@ Page{
|
|||
font.pointSize: osSettings.bigFontSize
|
||||
onClicked:{
|
||||
var userconfig={server: servername.text, username: username.text, password: Qt.btoa(password.text)};
|
||||
|
||||
Service.readConfig(db,function(user){
|
||||
if(userdata.token!=""){xhr.setUrl(servername.text);
|
||||
xhr.setApi("/oauth/revoke");
|
||||
xhr.clearParams();
|
||||
xhr.setParam("client_id",user.client.client_id);
|
||||
xhr.setParam("client_secret",user.client.client_secret);
|
||||
xhr.setParam("token",user.token);
|
||||
xhr.post();
|
||||
}
|
||||
},"username",username.text);
|
||||
|
||||
|
||||
Service.deleteConfig(db,userconfig,function(){
|
||||
filesystem.Directory=imagestore.text+"contacts";
|
||||
filesystem.rmDir();
|
||||
|
@ -379,15 +489,13 @@ Page{
|
|||
username.text="";
|
||||
password.text="";
|
||||
imagestore.text="";
|
||||
//maxNews.value=0;
|
||||
//newsTypeField.text="Conversations";
|
||||
//messageIntervalSlider.value=30;
|
||||
userButton.text=qsTr("User");
|
||||
Helperjs.readData(db,"config","",function(storedUsers){
|
||||
storedUsers.sort(function(obj1, obj2) {
|
||||
return obj1.isActive - obj2.isActive;
|
||||
})
|
||||
accountPage.users=storedUsers;})
|
||||
accountPage.state="new_oauth"
|
||||
})
|
||||
}}
|
||||
|
||||
|
@ -404,6 +512,7 @@ Page{
|
|||
password.text=""
|
||||
imagestore.text=""
|
||||
userButton.text=qsTr("User")
|
||||
accountPage.state="new_oauth"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -425,7 +534,31 @@ Page{
|
|||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
states: [
|
||||
State {
|
||||
name: "new_oauth"
|
||||
PropertyChanges { target: username; visible: false }
|
||||
PropertyChanges { target: password; visible: false}
|
||||
PropertyChanges { target: ruleButton; visible: true}
|
||||
},
|
||||
State {
|
||||
name:"oauth"
|
||||
PropertyChanges {target: username; visible: true}
|
||||
PropertyChanges { target: password; visible: false}
|
||||
PropertyChanges {target: confirmationOAuth; visible: true}
|
||||
PropertyChanges {target: setDefault; visible: true}
|
||||
PropertyChanges { target: confirmation; visible: false}
|
||||
},
|
||||
State{
|
||||
name:"password"
|
||||
PropertyChanges { target: username; visible: true }
|
||||
PropertyChanges { target: password; visible: true}
|
||||
PropertyChanges { target: confirmation; visible: true}
|
||||
PropertyChanges {target: confirmationOAuth; visible: false}
|
||||
}
|
||||
]
|
||||
|
||||
Component.onCompleted: { //print("filesystem.osType " +filesystem.osType)
|
||||
try{Helperjs.readData(db,"config","",function(storedUsers){
|
||||
storedUsers.sort(function(obj1, obj2) {
|
||||
return obj1.isActive - obj2.isActive;
|
||||
|
@ -441,6 +574,9 @@ Page{
|
|||
imagestore.text=obj.imagestore;
|
||||
imagestoredir=obj.imagestore;
|
||||
if( obj.isActive==0){userButton.font.bold='true'} else {userButton.font.bold='false'}
|
||||
if(obj.password!=""){accountPage.state="password"}
|
||||
else if (obj.token!=""){accountPage.state="oauth"}
|
||||
else {accountPage.state="new_oauth"}
|
||||
},"isActive",0)
|
||||
})}
|
||||
catch (e){//print("onCompleted" +users.count +e)
|
||||
|
|
|
@ -43,14 +43,13 @@ Page{
|
|||
font.pointSize: osSettings.systemFontSize
|
||||
color:Material.primaryTextColor
|
||||
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
|
||||
text: "<b>Friendiqa v0.6.7 </b><br>Licensed under GPL 3 with the exception of OpenSSL <br> "+
|
||||
text: "<b>Friendiqa v0.6.8 </b><br>Licensed under GPL 3 with the exception of OpenSSL <br> "+
|
||||
"Website <a href='https://friendiqa.ma-nic.de'>https://friendiqa.ma-nic.de</a><br>"+
|
||||
"Sourcecode: <a href='https://git.friendi.ca/LubuWest/Friendiqa'>https://git.friendi.ca/LubuWest/Friendiqa</a><br>"+
|
||||
"Privacy Policy: <a href='https://git.friendi.ca/lubuwest/Friendiqa/src/branch/master/PrivacyPolicy.md'>http://git.friendi.ca/lubuwest/Friendiqa/src/branch/master/PrivacyPolicy.md</a><br>"+
|
||||
"Code by <a href='https://freunde.ma-nic.de/profile/pankraz'>Marco</a><br>"+
|
||||
"Qt Framework <a href='https://www.qt.io'>www.qt.io</a><br>"+
|
||||
"Icons by <a href='http://fontawesome.io'>FontAwesome</a><br>"+
|
||||
"Folder Icon by <a href='https://github.com/KDE/breeze-icons'>KDE Breeze Icons</a><br>"+
|
||||
"AndroidNative by <a href='https://github.com/benlau/androidnative.pri'>Ben Lau</a><br>"+
|
||||
"This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit (<a href='http://www.openssl.org/'>http://www.openssl.org/</a>)"
|
||||
onLinkActivated:{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue