on xenial help sign in
password page rework
commit67b54b9682e0afcab3be31ecc28f4a68ac37b863 authorLukáš Tinkl <lukas.tinkl@canonical.com> dateThu 10 Mar 2016, 16:11 (11 years ago) parent0e90bf1
3 files changed+62−120
qml/Wizard/Pages/passcode-desktop.qml+4−4 qml/Wizard/Pages/password-set.qml+53−112 qml/Wizard/PasswordMeter.qml+5−4
qml/Wizard/Pages/passcode-desktop.qml+4−4
@@ -102,13 +102,13 @@ LocalComponents.Page {
102102 text: {
103103 if (password) {
104104 if (password2.length < password2Field.maximumLength)
105− return i18n.tr("Passcode too short")
105+ return i18n.tr("Passcode too short");
106106 else if (password == password2)
107− return i18n.tr("Passcodes match")
107+ return i18n.tr("Passcodes match");
108108 else if (password2)
109− return i18n.tr("Passcodes do not match")
109+ return i18n.tr("Passcodes do not match");
110110 }
111− return ""
111+ return "";
112112 }
113113 }
114114 }
qml/Wizard/Pages/password-set.qml+53−112
@@ -15,9 +15,9 @@
1515 */
1616
1717import QtQuick 2.4
18+import QtQuick.Layouts 1.1
1819import Ubuntu.Components 1.3
1920import ".." as LocalComponents
20−import "../../Components" as UnityComponents
2121
2222/**
2323 * See the main passwd-type page for an explanation of why we don't actually
@@ -27,147 +27,88 @@ import "../../Components" as UnityComponents
2727LocalComponents.Page {
2828 id: passwdSetPage
2929 objectName: "passwdSetPage"
30− customTitle: true
31− buttonBarVisible: false
32− title: confirmPhase ? i18n.tr("Confirm Password") : i18n.tr("Choose Password")
30+ title: i18n.tr("Lock Screen Password")
31+ forwardButtonSourceComponent: forwardButton
3332
34− property alias password: passwordField.text
35− property bool confirmPhase: false
33+ readonly property alias password: passwordField.text
34+ readonly property alias password2: password2Field.text
35+ readonly property bool passwordsMatching: password == password2 && password.trim().length > 7
3636
37− // If we are entering this page, clear any saved password and get focus
38− onEnabledChanged: if (enabled) password = ""
39−
40− Component.onCompleted: {
41− setInfo();
42− passwordField.forceActiveFocus();
43− }
44−
45− function confirm() {
46− root.password = password;
47− confirmTimer.start();
48− }
49−
50− Timer {
51− id: confirmTimer
52− interval: UbuntuAnimation.SnapDuration
53− onTriggered: {
54− confirmPhase = true;
55− password = "";
56− passwordField.forceActiveFocus();
57− }
58− }
59−
60− function setError(text) {
61− if (!!text) {
62− infoLabel.hasError = true;
63− infoLabel.text = text;
64− }
65− }
66−
67− function setInfo(text) {
68− infoLabel.hasError = false;
69− if (!!text) {
70− infoLabel.text = text;
71− } else {
72− infoLabel.text = i18n.tr("Enter at least 8 characters");
73− }
74− }
75−
76− Item {
37+ ColumnLayout {
7738 id: column
7839 anchors.fill: content
7940 anchors.leftMargin: leftMargin
8041 anchors.rightMargin: rightMargin
42+ anchors.topMargin: customMargin
43+ spacing: units.gu(3)
8144
8245 Label {
8346 id: infoLabel
8447 objectName: "infoLabel"
85− property bool hasError: false
8648 anchors {
8749 left: parent.left
8850 right: parent.right
89− topMargin: units.gu(3)
9051 }
9152 wrapMode: Text.Wrap
92− color: hasError ? errorColor : textColor
53+ font.weight: Font.Light
54+ color: textColor
55+ text: i18n.tr("Enter at least 8 characters")
9356 }
9457
95− LocalComponents.WizardTextField {
96− id: passwordField
97− objectName: "passwordField"
98− anchors {
99− left: parent.left
100− right: parent.right
101− top: infoLabel.bottom
102− topMargin: units.gu(1)
58+ ColumnLayout {
59+ id: innerLayout
60+ Label {
61+ text: i18n.tr("Choose password")
62+ color: textColor
10363 }
104− echoMode: TextInput.Password
105− onTextChanged: {
106− if (confirmPhase) {
107− if (password.length == 0) {
108− setInfo();
109− } else if (password !== root.password) {
110− setError(i18n.tr("Passwords do not match"));
111− } else {
112− setInfo(i18n.tr("Passwords match"));
113− }
114− }
64+ LocalComponents.WizardTextField {
65+ Layout.fillWidth: true
66+ id: passwordField
67+ objectName: "passwordField"
68+ echoMode: TextInput.Password
69+ onAccepted: password2Field.forceActiveFocus()
70+ }
71+
72+ Label {
73+ text: i18n.tr("Confirm password")
74+ color: textColor
75+ anchors.topMargin: units.gu(1)
76+ }
77+ LocalComponents.WizardTextField {
78+ Layout.fillWidth: true
79+ id: password2Field
80+ objectName: "password2Field"
81+ echoMode: TextInput.Password
11582 }
11683 }
11784
11885 // password meter
11986 LocalComponents.PasswordMeter {
12087 id: passMeter
121− anchors.left: parent.left
122− anchors.right: parent.right
123− anchors.top: passwordField.bottom
124− anchors.topMargin: units.gu(1)
125− password: passwordField.text
126− }
127−
128− // buttons
129− Button {
130− id: cancelButton
131− objectName: "cancelButton"
13288 anchors {
133− top: passMeter.bottom
13489 left: parent.left
135− right: parent.horizontalCenter
136− rightMargin: units.gu(1)
137− topMargin: units.gu(4)
138− }
139− text: i18n.tr("Cancel")
140− onClicked: {
141− if (confirmPhase) {
142− confirmPhase = false;
143− password = "";
144− setInfo();
145− passwordField.forceActiveFocus();
146− } else {
147− pageStack.prev();
148− }
90+ right: parent.right
91+ top: innerLayout.bottom
92+ topMargin: units.gu(1)
14993 }
94+
95+ password: passwordField.text
96+ matching: passwordsMatching
15097 }
15198
152− Button {
153− id: okButton
154− objectName: "okButton"
155− anchors {
156− top: passMeter.bottom
157− left: parent.horizontalCenter
158− right: parent.right
159− leftMargin: units.gu(1)
160− topMargin: units.gu(4)
161− }
162− text: i18n.tr("OK")
163− color: okColor
164− enabled: confirmPhase ? password === root.password : password.length > 7 // TODO set more sensible restrictions for the length?
99+ Item { // spacer
100+ Layout.fillHeight: true
101+ }
102+ }
103+
104+ Component {
105+ id: forwardButton
106+ LocalComponents.StackButton {
107+ text: i18n.tr("Next")
108+ enabled: passwordsMatching
165109 onClicked: {
166− if (confirmPhase) {
167− pageStack.next();
168− } else {
169− passwdSetPage.confirm();
170− }
110+ root.password = password;
111+ pageStack.next();
171112 }
172113 }
173114 }
qml/Wizard/PasswordMeter.qml+5−4
@@ -20,6 +20,7 @@ import Ubuntu.Components 1.3
2020Item {
2121 property string password: ""
2222 readonly property int passwordScore: scorePassword(password)
23+ property bool matching: false
2324
2425 function scorePassword(pass) {
2526 var score = 0;
@@ -81,13 +82,13 @@ Item {
8182 }
8283 wrapMode: Text.Wrap
8384 text: {
84− if (password.length < 8)
85− return i18n.tr("Password too short")
85+ if (matching)
86+ return i18n.tr("Passwords match");
8687 else if (passwordScore > 80)
8788 return i18n.tr("Strong password");
8889 else if (passwordScore > 60)
89− return i18n.tr("Fair password")
90− if (passwordScore >= 30)
90+ return i18n.tr("Fair password");
91+ else if (passwordScore >= 30)
9192 return i18n.tr("Weak password");
9293
9394 return i18n.tr("Very weak password");