on xenial help sign in
password page rework
67b54b9Lukáš Tinkl
qml/Wizard/Pages/passcode-desktop.qml+4−4
@@ -102,13 +102,13 @@ LocalComponents.Page {
102 text: {
102 text: {
103 if (password) {
103 if (password) {
104 if (password2.length < password2Field.maximumLength)
104 if (password2.length < password2Field.maximumLength)
105− return i18n.tr("Passcode too short")
105+ return i18n.tr("Passcode too short");
106 else if (password == password2)
106 else if (password == password2)
107− return i18n.tr("Passcodes match")
107+ return i18n.tr("Passcodes match");
108 else if (password2)
108 else if (password2)
109− return i18n.tr("Passcodes do not match")
109+ return i18n.tr("Passcodes do not match");
110 }
110 }
111− return ""
111+ return "";
112 }
112 }
113 }
113 }
114 }
114 }
qml/Wizard/Pages/password-set.qml+53−112
@@ -15,9 +15,9 @@
15 */
15 */
16
16
17import QtQuick 2.4
17import QtQuick 2.4
18+import QtQuick.Layouts 1.1
18import Ubuntu.Components 1.3
19import Ubuntu.Components 1.3
19import ".." as LocalComponents
20import ".." as LocalComponents
20−import "../../Components" as UnityComponents
21
21
22/**
22/**
23 * See the main passwd-type page for an explanation of why we don't actually
23 * See the main passwd-type page for an explanation of why we don't actually
@@ -27,147 +27,88 @@ import "../../Components" as UnityComponents
27LocalComponents.Page {
27LocalComponents.Page {
28 id: passwdSetPage
28 id: passwdSetPage
29 objectName: "passwdSetPage"
29 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
33
32
34− property alias password: passwordField.text
33+ readonly property alias password: passwordField.text
35− property bool confirmPhase: false
34+ readonly property alias password2: password2Field.text
35+ readonly property bool passwordsMatching: password == password2 && password.trim().length > 7
36
36
37− // If we are entering this page, clear any saved password and get focus
37+ ColumnLayout {
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 {
77 id: column
38 id: column
78 anchors.fill: content
39 anchors.fill: content
79 anchors.leftMargin: leftMargin
40 anchors.leftMargin: leftMargin
80 anchors.rightMargin: rightMargin
41 anchors.rightMargin: rightMargin
42+ anchors.topMargin: customMargin
43+ spacing: units.gu(3)
81
44
82 Label {
45 Label {
83 id: infoLabel
46 id: infoLabel
84 objectName: "infoLabel"
47 objectName: "infoLabel"
85− property bool hasError: false
86 anchors {
48 anchors {
87 left: parent.left
49 left: parent.left
88 right: parent.right
50 right: parent.right
89− topMargin: units.gu(3)
90 }
51 }
91 wrapMode: Text.Wrap
52 wrapMode: Text.Wrap
53+ font.weight: Font.Light
92− color: hasError ? errorColor : textColor
54+ color: textColor
55+ text: i18n.tr("Enter at least 8 characters")
93 }
56 }
94
57
95− LocalComponents.WizardTextField {
58+ ColumnLayout {
96− id: passwordField
59+ id: innerLayout
97− objectName: "passwordField"
60+ Label {
98− anchors {
61+ text: i18n.tr("Choose password")
99− left: parent.left
62+ color: textColor
100− right: parent.right
101− top: infoLabel.bottom
102− topMargin: units.gu(1)
103 }
63 }
104− echoMode: TextInput.Password
64+ LocalComponents.WizardTextField {
105− onTextChanged: {
65+ Layout.fillWidth: true
106− if (confirmPhase) {
66+ id: passwordField
107− if (password.length == 0) {
67+ objectName: "passwordField"
108− setInfo();
68+ echoMode: TextInput.Password
109− } else if (password !== root.password) {
69+ onAccepted: password2Field.forceActiveFocus()
110− setError(i18n.tr("Passwords do not match"));
70+ }
111− } else {
71+
112− setInfo(i18n.tr("Passwords match"));
72+ Label {
113− }
73+ text: i18n.tr("Confirm password")
114− }
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
115 }
82 }
116 }
83 }
117
84
118 // password meter
85 // password meter
119 LocalComponents.PasswordMeter {
86 LocalComponents.PasswordMeter {
120 id: passMeter
87 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"
132 anchors {
88 anchors {
133− top: passMeter.bottom
134 left: parent.left
89 left: parent.left
135− right: parent.horizontalCenter
90+ right: parent.right
136− rightMargin: units.gu(1)
91+ top: innerLayout.bottom
137− topMargin: units.gu(4)
92+ topMargin: units.gu(1)
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− }
149 }
93 }
94+
95+ password: passwordField.text
96+ matching: passwordsMatching
150 }
97 }
151
98
152− Button {
99+ Item { // spacer
153− id: okButton
100+ Layout.fillHeight: true
154− objectName: "okButton"
101+ }
155− anchors {
102+ }
156− top: passMeter.bottom
103+
157− left: parent.horizontalCenter
104+ Component {
158− right: parent.right
105+ id: forwardButton
159− leftMargin: units.gu(1)
106+ LocalComponents.StackButton {
160− topMargin: units.gu(4)
161− }
162− text: i18n.tr("OK")
107+ text: i18n.tr("Next")
163− color: okColor
108+ enabled: passwordsMatching
164− enabled: confirmPhase ? password === root.password : password.length > 7 // TODO set more sensible restrictions for the length?
165 onClicked: {
109 onClicked: {
166− if (confirmPhase) {
110+ root.password = password;
167− pageStack.next();
111+ pageStack.next();
168− } else {
169− passwdSetPage.confirm();
170− }
171 }
112 }
172 }
113 }
173 }
114 }
qml/Wizard/PasswordMeter.qml+5−4
@@ -20,6 +20,7 @@ import Ubuntu.Components 1.3
20Item {
20Item {
21 property string password: ""
21 property string password: ""
22 readonly property int passwordScore: scorePassword(password)
22 readonly property int passwordScore: scorePassword(password)
23+ property bool matching: false
23
24
24 function scorePassword(pass) {
25 function scorePassword(pass) {
25 var score = 0;
26 var score = 0;
@@ -81,13 +82,13 @@ Item {
81 }
82 }
82 wrapMode: Text.Wrap
83 wrapMode: Text.Wrap
83 text: {
84 text: {
84− if (password.length < 8)
85+ if (matching)
85− return i18n.tr("Password too short")
86+ return i18n.tr("Passwords match");
86 else if (passwordScore > 80)
87 else if (passwordScore > 80)
87 return i18n.tr("Strong password");
88 return i18n.tr("Strong password");
88 else if (passwordScore > 60)
89 else if (passwordScore > 60)
89− return i18n.tr("Fair password")
90+ return i18n.tr("Fair password");
90− if (passwordScore >= 30)
91+ else if (passwordScore >= 30)
91 return i18n.tr("Weak password");
92 return i18n.tr("Weak password");
92
93
93 return i18n.tr("Very weak password");
94 return i18n.tr("Very weak password");