Skip to content
Snippets Groups Projects
Unverified Commit a10c5ecd authored by Kali Kaneko's avatar Kali Kaneko
Browse files

[feat] login feedback

- Resolves: #334
parent 60a35bdd
No related branches found
No related tags found
No related merge requests found
......@@ -72,7 +72,7 @@ binaryName = demo-lib
auth = sip
providerURL = vpnlib.bitmask.net
apiURL = https://api.vpnlib.bitmask.net/
apiURL = https://api.vpnlib.bitmask.net:4430/
caURL = https://api.vpnlib.bitmask.net/ca.crt
infoURL = https://libraryvpn.org/
......
......@@ -4,6 +4,7 @@
<file>qml/AboutDialog.qml</file>
<file>qml/DonateDialog.qml</file>
<file>qml/LoginDialog.qml</file>
<file>qml/LoginOKDialog.qml</file>
<file>assets/icon/png/black/vpn_off.png</file>
<file>assets/icon/png/black/vpn_on.png</file>
......
import QtQuick 2.0
import QtQuick.Dialogs 1.2
import QtQuick.Controls 1.4
Dialog {
standardButtons: StandardButton.Ok
title: qsTr("Login Success")
text: qsTr("You are now logged in, connecting now")
visible: ctxSystray.loginConfirmationDialog == true
}
import QtQuick 2.0
import QtQuick.Dialogs 1.2
import QtQuick.Controls 1.4
Dialog {
standardButtons: StandardButton.Ok
title: qsTr("Login Successful")
Column {
anchors.fill: parent
Text {
text: qsTr("Login successful. You can now start the VPN.")
}
}
// TODO implement cleanNotifications on backend
function _loginOk() {
loginDone = true;
}
visible: false
onAccepted: _loginOk()
onRejected: _loginOk()
}
......@@ -10,6 +10,7 @@ ApplicationWindow {
visible: false
property var ctx
property var loginDone
Connections {
target: jsonModel
......@@ -23,6 +24,9 @@ ApplicationWindow {
console.debug(jsonModel.getJson())
login.visible = true
}
if (ctx.loginOk == 'true' && loginDone == false) {
loginOk.visible = true
}
if (ctx.errors ) {
if ( ctx.errors == "nohelpers" ) {
showInitFailure(qsTr("Could not find helpers. Check your installation"))
......@@ -44,6 +48,8 @@ ApplicationWindow {
}
Component.onCompleted: {
loginDone = false;
/* stupid as it sounds, windows doesn't like to have the systray icon
not being attached to an actual application window.
We can still use this quirk, and can use the AppWindow with deferred
......@@ -228,6 +234,11 @@ ApplicationWindow {
visible: false
}
LoginOKDialog{
id: loginOk
visible: false
}
MessageDialog {
id: errorStartingVPN
buttons: MessageDialog.Ok
......
......@@ -16,16 +16,19 @@ import (
func Login(username, password string) {
success, err := ctx.bm.DoLogin(username, password)
if err != nil {
// TODO
log.Printf("Error login: %v", err)
log.Printf("Error on login: %v", err)
ctx.Errors = "bad_auth_unknown"
} else if success {
// TODO: Notify success
log.Printf("Logged in as %s", username)
ctx.LoginOk = true
ctx.LoginDialog = false
} else {
// TODO: display login again with an err
log.Printf("Failed to login as %s", username)
ctx.LoginDialog = true
ctx.Errors = "bad_auth"
}
go ctx.updateStatus()
}
func SwitchOn() {
......
......@@ -38,6 +38,7 @@ type connectionCtx struct {
DonateDialog bool `json:"donateDialog"`
DonateURL string `json:"donateURL"`
LoginDialog bool `json:"loginDialog"`
LoginOk bool `json:"loginOk"`
Version string `json:"version"`
Errors string `json:"errors"`
Status status `json:"status"`
......
......@@ -20,6 +20,7 @@ type Bitmask interface {
Close()
Version() (string, error)
StartVPN(provider string) error
CanStartVPN() bool
StopVPN() error
ReloadFirewall() error
GetStatus() (string, error)
......
......@@ -131,7 +131,10 @@ func maybeStartVPN(b Bitmask, conf *config.Config) error {
return nil
}
err := b.StartVPN(config.Provider)
conf.SetUserStoppedVPN(false)
return err
if b.CanStartVPN() {
err := b.StartVPN(config.Provider)
conf.SetUserStoppedVPN(false)
return err
}
return nil
}
// Code generated by go generate; DO NOT EDIT.
// This file was generated by vendorize.py
// At 2020-08-13 22:38:42
// At 2020-08-15 20:39:01
package config
......@@ -15,7 +15,7 @@ const (
AskForDonations = "false"
HelpURL = "https://libraryvpn.org/"
TosURL = "https://libraryvpn.org/"
APIURL = "https://api.vpnlib.bitmask.net/"
APIURL = "https://api.vpnlib.bitmask.net:4430/"
GeolocationAPI = "https://getmyip.vpnlib.bitmask.net/"
)
......
......@@ -137,7 +137,7 @@ func (b *Bonafide) GetPemCertificate() ([]byte, error) {
log.Fatal("ERROR: bonafide did not initialize auth")
}
if b.auth.needsCredentials() && b.token == nil {
log.Println("BUG: expected token to be set, but is not there")
log.Println("Needs token, but token is empty")
return nil, errors.New("Needs to login, but it was not logged in. Please, restart the application and report it if it continues happening")
}
......
......@@ -16,6 +16,7 @@
package vpn
import (
"errors"
"fmt"
"io/ioutil"
"log"
......@@ -43,9 +44,23 @@ func (b *Bitmask) StartVPN(provider string) error {
}
}
if !b.CanStartVPN() {
return errors.New("BUG: cannot start vpn")
}
return b.startOpenVPN(proxy)
}
func (b *Bitmask) CanStartVPN() bool {
if !b.bonafide.NeedsCredentials() {
return true
}
_, err := b.getCert()
if err != nil {
return false
}
return true
}
func (b *Bitmask) startTransport() (proxy string, err error) {
proxy = "127.0.0.1:4430"
if b.shapes != nil {
......@@ -150,6 +165,7 @@ func (b *Bitmask) getCert() (certPath string, err error) {
certPath = b.getCertPemPath()
if _, err := os.Stat(certPath); os.IsNotExist(err) {
log.Println("Cert does not exist in ", certPath, "...fetching")
cert, err := b.bonafide.GetPemCertificate()
if err != nil {
return "", err
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment