Skip to content

Commit c8f673f

Browse files
authored
Remove username and password repetition from sign up flow (#3730)
1 parent aedc232 commit c8f673f

7 files changed

Lines changed: 21 additions & 102 deletions

File tree

app/qml/account/MMAccountController.qml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,14 @@ Item {
152152
stackView.popOnePageOrClose()
153153
}
154154

155-
onSignUpClicked: function ( username, email, password, passwordConfirm, tocAccept, newsletterSubscribe ) {
155+
onSignUpClicked: function ( email, password, tocAccept, newsletterSubscribe ) {
156156
if ( __merginApi.serverType !== MM.MerginServerType.SAAS ) {
157157
return; //should not happen
158158
}
159159
else {
160160
stackView.pending = true
161-
__merginApi.registerUser( username,
162-
email,
161+
__merginApi.registerUser( email,
163162
password,
164-
passwordConfirm,
165163
tocAccept )
166164

167165
postRegisterData.wantNewsletter = newsletterSubscribe

app/qml/account/MMSignUpPage.qml

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ MMPage {
3333

3434
signal signInClicked
3535
signal signUpClicked(
36-
string username,
3736
string email,
3837
string password,
39-
string passwordConfirm,
4038
bool tocAccept,
4139
bool newsletterSubscribe
4240
)
@@ -66,15 +64,6 @@ MMPage {
6664
height: __style.margin20
6765
}
6866

69-
MMTextInput {
70-
id: username
71-
72-
width: parent.width
73-
74-
title: qsTr( "Username" )
75-
textField.inputMethodHints: Qt.ImhNoAutoUppercase
76-
}
77-
7867
MMTextInput {
7968
id: email
8069

@@ -92,14 +81,6 @@ MMPage {
9281
title: qsTr( "Password" )
9382
}
9483

95-
MMPasswordInput {
96-
id: passwordConfirm
97-
98-
width: parent.width
99-
100-
title: qsTr( "Confirm password" )
101-
}
102-
10384
MMCheckBox {
10485
id: tocCheck
10586

@@ -126,10 +107,8 @@ MMPage {
126107

127108
onClicked: {
128109
root.signUpClicked(
129-
username.text,
130110
email.text,
131111
password.text,
132-
passwordConfirm.text,
133112
tocCheck.checked,
134113
newsletterCheck.checked
135114
)
@@ -160,28 +139,18 @@ MMPage {
160139
function showErrorMessage( msg, field ) {
161140

162141
// clear previous error messages
163-
username.errorMsg = ""
164142
email.errorMsg = ""
165143
password.errorMsg = ""
166-
passwordConfirm.errorMsg = ""
167144
tocCheck.hasError = false
168145

169-
if( field === MM.RegistrationError.USERNAME ) {
170-
username.errorMsg = msg
171-
username.focus = true
172-
}
173-
else if( field === MM.RegistrationError.EMAIL ) {
146+
if( field === MM.RegistrationError.EMAIL ) {
174147
email.errorMsg = msg
175148
email.focus = true
176149
}
177150
else if( field === MM.RegistrationError.PASSWORD ) {
178151
password.errorMsg = msg
179152
password.focus = true
180153
}
181-
else if( field === MM.RegistrationError.CONFIRM_PASSWORD ) {
182-
passwordConfirm.errorMsg = msg
183-
passwordConfirm.focus = true
184-
}
185154
else if( field === MM.RegistrationError.TOC ) {
186155
tocCheck.hasError = true
187156
__notificationModel.addError( msg )

app/test/testmerginapi.cpp

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,26 +2426,24 @@ void TestMerginApi::testRegisterAndDelete()
24262426
QString password = mApi->userAuth()->password();
24272427

24282428
QString quiteRandom = CoreUtils::uuidWithoutBraces( QUuid::createUuid() ).right( 15 ).replace( "-", "" );
2429-
QString username = "test_" + quiteRandom;
2430-
QString email = username + "@nonexistant.email.com";
2429+
QString email = "test_" + quiteRandom + "@nonexistant.email.com";
24312430

2432-
qDebug() << "username:" << username;
2431+
qDebug() << "email:" << email;
24332432
// do not want to be authorized
24342433
mApi->clearAuth();
24352434

24362435
QSignalSpy spy( mApi, &MerginApi::registrationSucceeded );
24372436
QSignalSpy spy2( mApi, &MerginApi::registrationFailed );
2438-
mApi->registerUser( username, email, password, password, true );
2437+
mApi->registerUser( email, password, true );
24392438
bool success = spy.wait( TestUtils::LONG_REPLY );
24402439
if ( !success )
24412440
{
24422441
qDebug() << "Failed registration" << spy2.takeFirst();
24432442
QVERIFY( false );
24442443
}
24452444

2446-
24472445
QSignalSpy spyAuth( mApi->userAuth(), &MerginUserAuth::authChanged );
2448-
mApi->authorize( username, password );
2446+
mApi->authorize( email, password );
24492447
QVERIFY( spyAuth.wait( TestUtils::LONG_REPLY * 5 ) );
24502448

24512449
// now delete user
@@ -2466,11 +2464,11 @@ void TestMerginApi::testCreateWorkspace()
24662464
QString password = TestUtils::generatePassword();
24672465
QString email = TestUtils::generateEmail();
24682466

2469-
qDebug() << "REGISTERING NEW TEST USER:" << username;
2467+
qDebug() << "REGISTERING NEW TEST USER WITH EMAIL:" << email;
24702468

24712469
QSignalSpy spy( mApi, &MerginApi::registrationSucceeded );
24722470
QSignalSpy spy2( mApi, &MerginApi::registrationFailed );
2473-
mApi->registerUser( username, email, password, password, true );
2471+
mApi->registerUser( email, password, true );
24742472
bool success = spy.wait( TestUtils::LONG_REPLY );
24752473
if ( !success )
24762474
{
@@ -2479,7 +2477,7 @@ void TestMerginApi::testCreateWorkspace()
24792477
}
24802478

24812479
QSignalSpy authSpy( mApi, &MerginApi::authChanged );
2482-
mApi->authorize( username, password );
2480+
mApi->authorize( email, password );
24832481
QVERIFY( authSpy.wait( TestUtils::LONG_REPLY ) );
24842482
QVERIFY( !authSpy.isEmpty() );
24852483

@@ -2854,41 +2852,27 @@ void TestMerginApi::testServerError()
28542852

28552853
void TestMerginApi::testRegistration()
28562854
{
2857-
QString username = "?";
28582855
QString email = "broken@email";
28592856
QString password = "pwd";
2860-
QString confirm_password = password;
28612857

28622858
// do not want to be authorized
28632859
mApi->clearAuth();
28642860

2865-
// wrong username test
2866-
QSignalSpy spy( mApi, &MerginApi::registrationFailed );
2867-
mApi->registerUser( username, email, password, confirm_password, true );
2868-
QCOMPARE( spy.count(), 1 );
2869-
QCOMPARE( spy.takeFirst().at( 1 ).toInt(), RegistrationError::RegistrationErrorType::USERNAME );
2870-
28712861
// wrong email test
2872-
username = "username";
2873-
mApi->registerUser( username, email, password, confirm_password, true );
2862+
QSignalSpy spy( mApi, &MerginApi::registrationFailed );
2863+
mApi->registerUser( email, password, true );
28742864
QCOMPARE( spy.count(), 1 );
28752865
QCOMPARE( spy.takeFirst().at( 1 ).toInt(), RegistrationError::RegistrationErrorType::EMAIL );
28762866

28772867
// wrong password test
28782868
email = "username@email.com";
2879-
mApi->registerUser( username, email, password, confirm_password, true );
2869+
mApi->registerUser( email, password, true );
28802870
QCOMPARE( spy.count(), 1 );
28812871
QCOMPARE( spy.takeFirst().at( 1 ).toInt(), RegistrationError::RegistrationErrorType::PASSWORD );
28822872

2883-
// wrong confirm password test
2884-
password = "Lutra123:)";
2885-
mApi->registerUser( username, email, password, confirm_password, true );
2886-
QCOMPARE( spy.count(), 1 );
2887-
QCOMPARE( spy.takeFirst().at( 1 ).toInt(), RegistrationError::RegistrationErrorType::CONFIRM_PASSWORD );
2888-
28892873
// unchecked TOC test
2890-
confirm_password = "Lutra123:)";
2891-
mApi->registerUser( username, email, password, confirm_password, false );
2874+
password = "Lutra123:)";
2875+
mApi->registerUser( email, password, false );
28922876
QCOMPARE( spy.count(), 1 );
28932877
QCOMPARE( spy.takeFirst().at( 1 ).toInt(), RegistrationError::RegistrationErrorType::TOC );
28942878
}

core/merginapi.cpp

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -816,27 +816,11 @@ void MerginApi::authorize( const QString &login, const QString &password )
816816
CoreUtils::log( "auth", QStringLiteral( "Requesting authorization: " ) + url.toString() );
817817
}
818818

819-
void MerginApi::registerUser( const QString &username,
820-
const QString &email,
819+
void MerginApi::registerUser( const QString &email,
821820
const QString &password,
822-
const QString &confirmPassword,
823821
bool acceptedTOC )
824822
{
825823
// Some very basic checks, so we do not validate everything
826-
if ( username.isEmpty() || username.length() < 4 )
827-
{
828-
QString msg = tr( "Username must have at least 4 characters" );
829-
emit registrationFailed( msg, RegistrationError::RegistrationErrorType::USERNAME );
830-
return;
831-
}
832-
833-
if ( !CoreUtils::isValidName( username ) )
834-
{
835-
QString msg = tr( "Username contains invalid characters" );
836-
emit registrationFailed( msg, RegistrationError::RegistrationErrorType::USERNAME );
837-
return;
838-
}
839-
840824
if ( email.isEmpty() || !email.contains( '@' ) || !email.contains( '.' ) )
841825
{
842826
QString msg = tr( "Please enter a valid email" );
@@ -857,13 +841,6 @@ void MerginApi::registerUser( const QString &username,
857841

858842
}
859843

860-
if ( confirmPassword != password )
861-
{
862-
QString msg = tr( "Passwords do not match" );
863-
emit registrationFailed( msg, RegistrationError::RegistrationErrorType::CONFIRM_PASSWORD );
864-
return;
865-
}
866-
867844
if ( !acceptedTOC )
868845
{
869846
QString msg = tr( "Please accept Terms and Privacy Policy" );
@@ -880,14 +857,13 @@ void MerginApi::registerUser( const QString &username,
880857

881858
QJsonDocument jsonDoc;
882859
QJsonObject jsonObject;
883-
jsonObject.insert( QStringLiteral( "username" ), username );
884860
jsonObject.insert( QStringLiteral( "email" ), email );
885861
jsonObject.insert( QStringLiteral( "password" ), password );
886862
jsonObject.insert( QStringLiteral( "api_key" ), getApiKey( mApiRoot ) );
887863
jsonDoc.setObject( jsonObject );
888864
QByteArray json = jsonDoc.toJson( QJsonDocument::Compact );
889865
QNetworkReply *reply = mManager->post( request, json );
890-
connect( reply, &QNetworkReply::finished, this, [ = ]() { this->registrationFinished( username, password ); } );
866+
connect( reply, &QNetworkReply::finished, this, [ = ]() { this->registrationFinished( email, password ); } );
891867
CoreUtils::log( "auth", QStringLiteral( "Requesting registration: " ) + url.toString() );
892868
}
893869

@@ -1300,7 +1276,7 @@ void MerginApi::authorizeFinished()
13001276
r->deleteLater();
13011277
}
13021278

1303-
void MerginApi::registrationFinished( const QString &username, const QString &password )
1279+
void MerginApi::registrationFinished( const QString &login, const QString &password )
13041280
{
13051281
QNetworkReply *r = qobject_cast<QNetworkReply *>( sender() );
13061282
Q_ASSERT( r );
@@ -1311,8 +1287,8 @@ void MerginApi::registrationFinished( const QString &username, const QString &pa
13111287
QString msg = tr( "Registration successful" );
13121288
emit notifySuccess( msg );
13131289

1314-
if ( !username.isEmpty() && !password.isEmpty() ) // log in immediately
1315-
authorize( username, password );
1290+
if ( !login.isEmpty() && !password.isEmpty() ) // log in immediately
1291+
authorize( login, password );
13161292

13171293
emit registrationSucceeded();
13181294
}

core/merginapi.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,8 @@ class MerginApi: public QObject
324324
* \param acceptedTOC Whether user accepted Terms and Conditions
325325
*/
326326
Q_INVOKABLE void registerUser(
327-
const QString &username,
328327
const QString &email,
329328
const QString &password,
330-
const QString &confirmPassword,
331329
bool acceptedTOC
332330
);
333331

@@ -700,7 +698,7 @@ class MerginApi: public QObject
700698
void createProjectFinished();
701699
void deleteProjectFinished( bool informUser = true );
702700
void authorizeFinished();
703-
void registrationFinished( const QString &username = QStringLiteral(), const QString &password = QStringLiteral() );
701+
void registrationFinished( const QString &login = QStringLiteral(), const QString &password = QStringLiteral() );
704702
void postRegistrationFinished();
705703
void pingMerginReplyFinished();
706704
void deleteAccountFinished();

core/merginerrortypes.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ class RegistrationError
1919
enum RegistrationErrorType
2020
{
2121
OTHER = 0,
22-
USERNAME,
2322
EMAIL,
2423
PASSWORD,
25-
CONFIRM_PASSWORD,
2624
TOC
2725
};
2826
Q_ENUM( RegistrationErrorType )

gallery/qml/pages/OnboardingPage.qml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,6 @@ Page {
158158

159159
tocString: "Please read our Terms and Conditions"
160160

161-
onSignInClicked: console.log("Sign in clicked")
162-
onSignUpClicked: function(username, email, password, passwordConfirm, tocAccept, newsletterSubscribe) {
163-
console.log("Sign up clicked: " + username + ";" + email + ";" + password + ";" + passwordConfirm + ";" + tocAccept + ";" + newsletterSubscribe)
164-
}
165161
onBackClicked: stackview.pop()
166162
}
167163
}

0 commit comments

Comments
 (0)