Skip to content
Snippets Groups Projects
Commit f20e3606 authored by Loïck Bonniot's avatar Loïck Bonniot
Browse files

[gui] Add authentication screen

parent 5987d422
No related branches found
No related tags found
Loading
Pipeline #
<RCC>
<qresource prefix="/">
<file>userform/userform.ui</file>
<file>authform/authform.ui</file>
</qresource>
</RCC>
package authform
import (
"dfss/dfssc/user"
"dfss/gui/config"
"github.com/visualfc/goqt/ui"
)
type Widget struct {
W *ui.QWidget
}
func NewWidget(conf *config.Config, onAuth func()) *Widget {
file := ui.NewFileWithName(":/authform/authform.ui")
loader := ui.NewUiLoader()
form := loader.Load(file)
tokenField := ui.NewLineEditFromDriver(form.FindChild("tokenField"))
feedbackLabel := ui.NewLabelFromDriver(form.FindChild("feedbackLabel"))
authButton := ui.NewPushButtonFromDriver(form.FindChild("authButton"))
home := config.GetHomeDir()
authButton.OnClicked(func() {
form.SetDisabled(true)
err := user.Authenticate(
home+config.CAFile,
home+config.CertFile,
conf.Platform,
conf.Email,
tokenField.Text(),
)
form.SetDisabled(false)
if err != nil {
feedbackLabel.SetText(err.Error())
tokenField.SetFocus()
tokenField.SelectAll()
} else {
onAuth()
}
})
return &Widget{
W: form,
}
}
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CalculatorForm</class>
<widget class="QWidget" name="CalculatorForm">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>592</width>
<height>340</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Calculator Builder</string>
</property>
<layout class="QGridLayout">
<property name="margin">
<number>9</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="authLabel">
<property name="minimumSize">
<size>
<width>0</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>100</height>
</size>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:20pt;&quot;&gt;Authentication&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Please check your mails and copy/paste the authentication token to continue.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="formAlignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="horizontalSpacing">
<number>30</number>
</property>
<property name="verticalSpacing">
<number>10</number>
</property>
<property name="leftMargin">
<number>50</number>
</property>
<property name="rightMargin">
<number>50</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="tokenLabel">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Token&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="tokenField"/>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="authButton">
<property name="text">
<string>Authenticate</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="feedbackLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -24,6 +24,7 @@ const ConfigFile = "config.json"
// Config is the structure that will be persisted in the configuration file
type Config struct {
Email string
Platform string
// Virtual-only fields
......
......@@ -2,6 +2,7 @@ package main
import (
"dfss"
"dfss/gui/authform"
"dfss/gui/config"
"dfss/gui/userform"
"github.com/visualfc/goqt/ui"
......@@ -11,16 +12,34 @@ const WIDTH = 650
const HEIGHT = 350
func main() {
// Load configuration
conf := config.Load()
// Start first window
ui.Run(func() {
form := userform.NewWidget(&conf)
layout := ui.NewVBoxLayout()
layout.AddWidget(form.W)
var newuser *userform.Widget
var newauth *authform.Widget
newauth = authform.NewWidget(&conf, func() {
layout.RemoveWidget(newauth.W)
newauth.W.Hide()
})
newuser = userform.NewWidget(&conf, func(pwd string) {
layout.RemoveWidget(newuser.W)
newuser.W.Hide()
layout.AddWidget(newauth.W)
})
if conf.Authenticated {
// TODO
} else if conf.Registered {
layout.AddWidget(newauth.W)
} else {
layout.AddWidget(newuser.W)
}
w := ui.NewWidget()
w.SetLayout(layout)
......
......@@ -12,7 +12,7 @@ type Widget struct {
W *ui.QWidget
}
func NewWidget(conf *config.Config) *Widget {
func NewWidget(conf *config.Config, onRegistered func(pw string)) *Widget {
file := ui.NewFileWithName(":/userform/userform.ui")
loader := ui.NewUiLoader()
form := loader.Load(file)
......@@ -52,7 +52,9 @@ func NewWidget(conf *config.Config) *Widget {
if err != nil {
feedbackLabel.SetText(err.Error())
} else {
conf.Email = emailField.Text()
conf.Platform = hostField.Text()
onRegistered(passwordField.Text())
config.Save(*conf)
}
form.SetDisabled(false)
......
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