Browse Source

Set username on signup

Vishnu Mohandas 4 years ago
parent
commit
e92e1f51de

+ 9 - 0
lib/core/configuration.dart

@@ -20,6 +20,7 @@ class Configuration {
   static const endpointKey = "endpoint";
   static const userIDKey = "user_id";
   static const emailKey = "email";
+  static const nameKey = "name";
   static const tokenKey = "token";
   static const hasOptedForE2EKey = "has_opted_for_e2e_encryption";
   static const foldersToBackUpKey = "folders_to_back_up";
@@ -128,6 +129,14 @@ class Configuration {
     await _preferences.setString(emailKey, email);
   }
 
+  String getName() {
+    return _preferences.getString(nameKey);
+  }
+
+  Future<void> setName(String name) async {
+    await _preferences.setString(nameKey, name);
+  }
+
   int getUserID() {
     return _preferences.getInt(userIDKey);
   }

+ 7 - 4
lib/services/user_service.dart

@@ -1,7 +1,6 @@
 import 'package:dio/dio.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/widgets.dart';
-import 'package:flutter_sodium/flutter_sodium.dart';
 import 'package:logging/logging.dart';
 import 'package:photos/core/configuration.dart';
 import 'package:photos/core/event_bus.dart';
@@ -108,14 +107,18 @@ class UserService {
     });
   }
 
-  Future<void> setupKey(BuildContext context, String passphrase) async {
+  Future<void> setupAttributes(BuildContext context, String passphrase) async {
     final dialog = createProgressDialog(context, "Please wait...");
     await dialog.show();
     final result = await _config.generateKey(passphrase);
+    final name = _config.getName();
     await _dio
         .put(
-      _config.getHttpEndpoint() + "/users/key-attributes",
-      data: result.keyAttributes.toMap(),
+      _config.getHttpEndpoint() + "/users/attributes",
+      data: {
+        "name": name,
+        "keyAttributes": result.keyAttributes.toMap(),
+      },
       options: Options(
         headers: {
           "X-Auth-Token": _config.getToken(),

+ 17 - 4
lib/ui/email_entry_page.dart

@@ -15,12 +15,14 @@ class EmailEntryPage extends StatefulWidget {
 }
 
 class _EmailEntryPageState extends State<EmailEntryPage> {
+  final _config = Configuration.instance;
   TextEditingController _emailController;
+  TextEditingController _nameController;
 
   @override
   void initState() {
-    _emailController =
-        TextEditingController(text: Configuration.instance.getEmail());
+    _emailController = TextEditingController(text: _config.getEmail());
+    _nameController = TextEditingController(text: _config.getName());
     super.initState();
   }
 
@@ -46,13 +48,23 @@ class _EmailEntryPageState extends State<EmailEntryPage> {
               height: 200,
             ),
             Padding(padding: EdgeInsets.all(12)),
+            TextFormField(
+              decoration: InputDecoration(
+                hintText: 'Full Name',
+                contentPadding: EdgeInsets.all(20),
+              ),
+              controller: _nameController,
+              autofocus: true,
+              autocorrect: false,
+              keyboardType: TextInputType.name,
+            ),
+            Padding(padding: EdgeInsets.all(12)),
             TextFormField(
               decoration: InputDecoration(
                 hintText: 'you@email.com',
                 contentPadding: EdgeInsets.all(20),
               ),
               controller: _emailController,
-              autofocus: true,
               autocorrect: false,
               keyboardType: TextInputType.emailAddress,
             ),
@@ -67,7 +79,8 @@ class _EmailEntryPageState extends State<EmailEntryPage> {
                       "Please enter a valid email address.");
                   return;
                 }
-                Configuration.instance.setEmail(email);
+                _config.setEmail(email);
+                _config.setName(_nameController.text);
                 UserService.instance.getOtt(context, email);
               }),
             ),

+ 1 - 1
lib/ui/passphrase_entry_page.dart

@@ -139,7 +139,7 @@ class _PassphraseEntryPageState extends State<PassphraseEntryPage> {
           child: Text("Confirm"),
           onPressed: () {
             Navigator.of(context).pop();
-            UserService.instance.setupKey(context, _passphraseController1.text);
+            UserService.instance.setupAttributes(context, _passphraseController1.text);
           },
         ),
       ],