Verified Commit 55d60549 authored by Haelwenn's avatar Haelwenn

LoginPage.qml: Reflow

parent f48af6b3
......@@ -27,21 +27,46 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import QtQuick 2.0
import QtWebKit 3.0
import Sailfish.Silica 1.0
import "../lib/API.js" as Logic
Page {
id: loginPage
// The effective value will be restricted by ApplicationWindow.allowedOrientations
allowedOrientations: Orientation.All
function instance_login() {
Logic.api = new Logic.MastodonAPI(
{"instance": instance.text, "api_user_token": ""}
)
Logic.api.registerApplication(
"Kyclos", 'http://localhost/harbour-kyclos',
// redirect uri, we will need this later on
["read", "write", "follow"], //scopes
"https://git.pleroma.social/pleroma/harbour-kyclos",
//website on the login screen
function (data) {
var conf = JSON.parse(data);
conf.instance = instance.text;
conf.login = false;
Logic.conf = conf;
var url = Logic.api.generateAuthLink(
Logic.conf["client_id"],
Logic.conf["redirect_uri"],
"code", // oauth method
["read", "write", "follow"] //scopes
)
webView.url = url;
webView.visible = true;
}
)
}
SilicaFlickable {
anchors.fill: parent
......@@ -52,20 +77,8 @@ Page {
Column {
id: column
width: parent.width
PageHeader { title: qsTr("Login") }
SectionHeader {
text: qsTr("Instance")
}
IconButton {
id: login
onClicked: {}
icon.source: "image://theme/icon-m-enter-accept" + "?" + (pressed
? Theme.highlightColor
: Theme.primaryColor)
}
SectionHeader { text: qsTr("Instance") }
TextField {
id: instance
......@@ -74,40 +87,26 @@ Page {
text: "https://"
placeholderText: "https://social.example.org"
width: parent.width
validator: RegExpValidator { regExp: /^(http|https):\/\/[^ "]+$/ }
EnterKey.enabled: instance.acceptableInput;
validator: RegExpValidator {
regExp: /^(http|https):\/\/[^ "]+$/
}
EnterKey.enabled: instance.acceptableInput
EnterKey.iconSource: "image://theme/icon-m-enter-next"
EnterKey.onClicked: {
Logic.api = new Logic.MastodonAPI({ instance: instance.text, api_user_token: "" });
Logic.api.registerApplication("Kyclos",
'http://localhost/harbour-kyclos', // redirect uri, we will need this later on
["read", "write", "follow"], //scopes
"https://git.pleroma.social/pleroma/harbour-kyclos", //website on the login screen
function(data) {
var conf = JSON.parse(data)
conf.instance = instance.text;
conf.login = false;
/*conf['login'] = false;
conf['mastodon_client_id'] = data['mastodon_client_id'];
conf['mastodon_client_secret'] = data['mastodon_client_secret'];
conf['mastodon_client_redirect_uri'] = data['mastodon_client_redirect_uri'];
delete Logic.conf;*/
Logic.conf = conf;
// we got our application
instance_login()
}
}
// our user to it!
var url = Logic.api.generateAuthLink(Logic.conf["client_id"],
Logic.conf["redirect_uri"],
"code", // oauth method
["read", "write", "follow"] //scopes
);
webView.url = url
webView.visible = true
IconButton {
id: login
anchors {
right: parent.right
}
);
onClicked: {
instance_login()
}
icon.source: "image://theme/icon-m-enter-next" + "?"
+ (pressed ? Theme.highlightColor : Theme.primaryColor)
}
}
}
......@@ -122,16 +121,17 @@ Page {
bottom: parent.bottom
}
opacity: 0
opacity: 1
onLoadingChanged: {
if (
(url+"").substr(0, 37) === 'http://localhost/harbour-kyclos?code=' ||
(url+"").substr(0, 38) === 'https://localhost/harbour-kyclos?code='
(url + "").substr(0, 37) === 'http://localhost/harbour-kyclos?code=' ||
(url + "").substr(0, 38) === 'https://localhost/harbour-kyclos?code='
) {
visible = false;
/* found on https://html-online.com/articles/get-url-parameters-javascript/ */
var vars = {};
(url+"").replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) { vars[key] = value;}); /* found on https://html-online.com/articles/get-url-parameters-javascript/ */
(url + "").replace(/[?&]+([^=&]+)=([^&]*)/gi, function (m, key, value) {vars[key] = value});
var authCode = vars["code"];
......@@ -140,33 +140,18 @@ Page {
Logic.conf["client_secret"],
Logic.conf["redirect_uri"],
authCode,
function(data) {
function (data) {
// AAAND DATA CONTAINS OUR TOKEN!
data = JSON.parse(data)
Logic.conf["api_user_token"] = data.access_token
data = JSON.parse(data);
Logic.conf["api_user_token"] = data.access_token;
Logic.conf["login"] = true;
Logic.api.setConfig("api_user_token", Logic.conf["api_user_token"])
pageStack.replace(Qt.resolvedUrl("MainPage.qml"), {})
Logic.api.setConfig("api_user_token", Logic.conf["api_user_token"]);
pageStack.replace(Qt.resolvedUrl("MainPage.qml"), { });
}
)
}
switch (loadRequest.status)
{
case WebView.LoadSucceededStatus:
opacity = 1
break
case WebView.LoadFailedStatus:
//opacity = 0
break
default:
//opacity = 0
break
}
}
FadeAnimation on opacity {}
PullDownMenu {
MenuItem {
text: qsTr("Reload")
......@@ -175,4 +160,3 @@ Page {
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment