Bläddra i källkod

Sign up: Add field for 'hear us from' info (#376)

Neeraj Gupta 1 år sedan
förälder
incheckning
d02e02a326
3 ändrade filer med 69 tillägg och 5 borttagningar
  1. 3 1
      lib/l10n/arb/app_en.arb
  2. 17 4
      lib/services/user_service.dart
  3. 49 0
      lib/ui/account/email_entry_page.dart

+ 3 - 1
lib/l10n/arb/app_en.arb

@@ -402,5 +402,7 @@
   "signOutFromOtherDevices": "Sign out from other devices",
   "signOutOtherBody": "If you think someone might know your password, you can force all other devices using your account to sign out.",
   "signOutOtherDevices": "Sign out other devices",
-  "doNotSignOut": "Do not sign out"
+  "doNotSignOut": "Do not sign out",
+  "hearUsWhereTitle": "How did you hear about Ente? (optional)",
+  "hearUsExplanation": "We don't track app installs. It'd help if you told us where you found us!"
 }

+ 17 - 4
lib/services/user_service.dart

@@ -45,6 +45,7 @@ import "package:uuid/uuid.dart";
 class UserService {
   static const keyHasEnabledTwoFactor = "has_enabled_two_factor";
   static const keyUserDetails = "user_details";
+  static const kReferralSource = "referral_source";
   static const kCanDisableEmailMFA = "can_disable_email_mfa";
   static const kIsEmailMFAEnabled = "is_email_mfa_enabled";
   final SRP6GroupParameters kDefaultSrpGroup = SRP6StandardGroups.rfc5054_4096;
@@ -270,13 +271,17 @@ class UserService {
   }) async {
     final dialog = createProgressDialog(context, context.l10n.pleaseWait);
     await dialog.show();
+    final verifyData = {
+      "email": _config.getEmail(),
+      "ott": ott,
+    };
+    if (!_config.isLoggedIn()) {
+      verifyData["source"] = 'auth:' + _getRefSource();
+    }
     try {
       final response = await _dio.post(
         _config.getHttpEndpoint() + "/users/verify-email",
-        data: {
-          "email": _config.getEmail(),
-          "ott": ott,
-        },
+        data: verifyData,
       );
       await dialog.hide();
       if (response.statusCode == 200) {
@@ -890,4 +895,12 @@ class UserService {
       rethrow;
     }
   }
+
+  Future<void> setRefSource(String refSource) async {
+    await _preferences.setString(kReferralSource, refSource);
+  }
+
+  String _getRefSource() {
+    return _preferences.getString(kReferralSource) ?? "";
+  }
 }

+ 49 - 0
lib/ui/account/email_entry_page.dart

@@ -3,8 +3,10 @@ import 'package:ente_auth/core/configuration.dart';
 import 'package:ente_auth/ente_theme_data.dart';
 import 'package:ente_auth/l10n/l10n.dart';
 import 'package:ente_auth/services/user_service.dart';
+import 'package:ente_auth/theme/ente_theme.dart';
 import 'package:ente_auth/ui/common/dynamic_fab.dart';
 import 'package:ente_auth/ui/common/web_page.dart';
+import 'package:ente_auth/utils/toast_util.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/services.dart';
 import 'package:password_strength/password_strength.dart';
@@ -30,6 +32,7 @@ class _EmailEntryPageState extends State<EmailEntryPage> {
   String? _email;
   String? _password;
   String _cnfPassword = '';
+  String _referralSource = '';
   double _passwordStrength = 0.0;
   bool _emailIsValid = false;
   bool _hasAgreedToTOS = true;
@@ -104,6 +107,7 @@ class _EmailEntryPageState extends State<EmailEntryPage> {
         onPressedFunction: () {
           _config.setVolatilePassword(_passwordController1.text);
           UserService.instance.setEmail(_email!);
+          UserService.instance.setRefSource(_referralSource);
           UserService.instance
               .sendOtt(context, _email!, isCreateAccountScreen: true);
           FocusScope.of(context).unfocus();
@@ -325,6 +329,51 @@ class _EmailEntryPageState extends State<EmailEntryPage> {
                   ),
                 ),
                 const SizedBox(height: 4),
+                Padding(
+                  padding:
+                      const EdgeInsets.symmetric(vertical: 0, horizontal: 20),
+                  child: Text(
+                    context.l10n.hearUsWhereTitle,
+                    style: getEnteTextTheme(context).smallFaint,
+                  ),
+                ),
+                const SizedBox(height: 4),
+                Padding(
+                  padding: const EdgeInsets.fromLTRB(20, 0, 20, 0),
+                  child: TextFormField(
+                    style: Theme.of(context).textTheme.titleMedium,
+                    decoration: InputDecoration(
+                      fillColor: null,
+                      filled: true,
+                      contentPadding: const EdgeInsets.symmetric(
+                        horizontal: 16,
+                        vertical: 14,
+                      ),
+                      border: UnderlineInputBorder(
+                        borderSide: BorderSide.none,
+                        borderRadius: BorderRadius.circular(6),
+                      ),
+                      suffixIcon: InkWell(
+                        onTap: () {
+                          showToast(
+                            context,
+                            context.l10n.hearUsExplanation,
+                          );
+                        },
+                        child: Icon(
+                          Icons.info_outline_rounded,
+                          color: getEnteColorScheme(context).strokeMuted,
+                        ),
+                      ),
+                    ),
+                    onChanged: (value) {
+                      _referralSource = value.trim();
+                    },
+                    autocorrect: false,
+                    keyboardType: TextInputType.text,
+                    textInputAction: TextInputAction.next,
+                  ),
+                ),
                 const Divider(thickness: 1),
                 const SizedBox(height: 12),
                 _getAgreement(),