Commit ba93953b authored by Loïck Bonniot's avatar Loïck Bonniot

[gui] Add register form

parent cff37ca5
Pipeline #395 passed with stage
......@@ -23,16 +23,16 @@ clean:
# prepare_gui builds a new container from the goqt image, adding DFSS dependencies for faster builds.
# call it once or after dependency addition.
prepare_gui: nocache
docker run --name dfss-builder -v ${PWD}:/go/src/dfss -w /go/src/dfss lesterpig/goqt \
cp -r ../github.com/visualfc/goqt/bin . && \
./build/deps.sh
docker run --name dfss-builder -v ${PWD}:/go/src/dfss -w /go/src/dfss lesterpig/goqt /bin/bash -c \
"cp -r ../github.com/visualfc/goqt/bin . ; ./build/deps.sh"
docker commit dfss-builder dfss:builder
docker rm dfss-builder
# gui builds the gui component of the dfss project into a docker container, outputing the result in bin/ directory.
gui: nocache
docker run --rm -v ${PWD}:/go/src/dfss -w /go/src/dfss/gui lesterpig/goqt \
../bin/goqt_rcc -go main -o application.qrc.go application.qrc && \
docker run --rm -v ${PWD}:/go/src/dfss -w /go/src/dfss/gui dfss:builder \
../bin/goqt_rcc -go main -o application.qrc.go application.qrc
docker run --rm -v ${PWD}:/go/src/dfss -w /go/src/dfss/gui dfss:builder \
go build -ldflags "-r ." -o ../bin/gui
# Release internals
......
<RCC>
<qresource prefix="/">
</qresource>
<qresource prefix="/">
<file>userform/userform.ui</file>
</qresource>
</RCC>
package main
import "github.com/visualfc/goqt/ui"
import (
"dfss"
"dfss/gui/userform"
"github.com/visualfc/goqt/ui"
)
const WIDTH = 650
const HEIGHT = 350
func main() {
ui.Run(func() {
widget := ui.NewWidget()
label := ui.NewLabel()
label.SetText("Welcome on dat fresh DFSS Client!")
text := ui.NewTextEdit()
text.SetText("Edit me!")
button := ui.NewPushButton()
button.SetText("Click me!")
button.OnClicked(func() {
button.SetText("Clicked!")
})
vbox := ui.NewVBoxLayout()
vbox.SetAlignment(ui.Qt_AlignCenter)
vbox.AddWidget(label)
vbox.AddWidget(text)
vbox.AddWidget(button)
form := userform.NewWidget()
widget.SetWindowTitle("DFSS Client")
widget.SetLayout(vbox)
widget.SetMinimumWidth(400)
widget.SetMinimumHeight(400)
layout := ui.NewVBoxLayout()
layout.AddWidget(form.W)
widget.Show()
w := ui.NewWidget()
w.SetLayout(layout)
w.SetWindowTitle("DFSS Client v" + dfss.Version)
w.SetFixedSizeWithWidthHeight(WIDTH, HEIGHT)
w.Show()
})
}
package userform
import (
"io/ioutil"
"os"
osuser "os/user"
"path/filepath"
"dfss/dfssc/user"
"github.com/visualfc/goqt/ui"
)
type Widget struct {
W *ui.QWidget
}
func NewWidget() *Widget {
file := ui.NewFileWithName(":/userform/userform.ui")
loader := ui.NewUiLoader()
form := loader.Load(file)
emailField := ui.NewLineEditFromDriver(form.FindChild("emailField"))
hostField := ui.NewLineEditFromDriver(form.FindChild("hostField"))
passwordField := ui.NewLineEditFromDriver(form.FindChild("passwordField"))
passwordField.SetEchoMode(ui.QLineEdit_Password)
feedbackLabel := ui.NewLabelFromDriver(form.FindChild("feedbackLabel"))
registerButton := ui.NewPushButtonFromDriver(form.FindChild("registerButton"))
home := getHomeDir()
fileDialog := ui.NewFileDialogWithParentCaptionDirectoryFilter(nil, "Select the CA file for the platform", home, "Root Certificates (*.pem);;Any (*.*)")
// Events
registerButton.OnClicked(func() {
form.SetDisabled(true)
feedbackLabel.SetText("Registration in progress...")
fileDialog.Open()
})
fileDialog.OnFileSelected(func(ca string) {
fileDialog.Hide()
caDest := home + "ca.pem"
_ = copyCA(ca, caDest)
err := user.Register(
home+"ca.pem",
home+"cert.pem",
home+"key.pem",
hostField.Text(),
passwordField.Text(),
"", "", "", emailField.Text(), 2048,
)
if err != nil {
feedbackLabel.SetText(err.Error())
} else {
feedbackLabel.SetText("Registration done! Please check your mails.")
}
form.SetDisabled(false)
})
fileDialog.OnRejected(func() {
form.SetDisabled(false)
feedbackLabel.SetText("Registration aborted.")
})
return &Widget{W: form}
}
func getHomeDir() string {
u, err := osuser.Current()
if err != nil {
return ""
}
dfssPath := filepath.Join(u.HomeDir, ".dfss")
if err := os.MkdirAll(dfssPath, os.ModeDir|0700); err != nil {
return ""
}
return dfssPath + string(filepath.Separator)
}
func copyCA(from string, to string) error {
if from == to {
return nil
}
file, err := ioutil.ReadFile(from)
if err != nil {
return err
}
return ioutil.WriteFile(to, file, 0600)
}
<?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>408</width>
<height>316</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">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>30</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="leftMargin">
<number>30</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>30</number>
</property>
<item>
<widget class="QLabel" name="welcomeLabel">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:20pt; font-weight:600;&quot;&gt;Welcome on DFSS Client!&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-size:14pt;&quot;&gt;Please tell us some information to start.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</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="emailLabel">
<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;Email&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::AutoText</enum>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="emailField">
<property name="placeholderText">
<string>Used to identify yourself, mandatory</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="hostLabel">
<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;Platform&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="hostField">
<property name="placeholderText">
<string>Platform hostname, mandatory</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="passwordLabel">
<property name="text">
<string>Password</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="passwordField">
<property name="inputMask">
<string/>
</property>
<property name="frame">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>Used to encrypt your private key, optional</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="registerButton">
<property name="text">
<string>Register</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="feedbackLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
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