Просмотр исходного кода

sign up and log in authentification done

David Sokol Zelazko 3 лет назад
Родитель
Сommit
8d689885cc

+ 1 - 1
app/ios/Podfile

@@ -1,5 +1,5 @@
 # Uncomment this line to define a global platform for your project
-# platform :ios, '9.0'
+platform :ios, '10.0'
 
 # CocoaPods analytics sends network stats synchronously affecting flutter build latency.
 ENV['COCOAPODS_DISABLE_STATS'] = 'true'

+ 33 - 1
app/ios/Podfile.lock

@@ -1,9 +1,21 @@
 PODS:
+  - Firebase/Auth (8.15.0):
+    - Firebase/CoreOnly
+    - FirebaseAuth (~> 8.15.0)
   - Firebase/CoreOnly (8.15.0):
     - FirebaseCore (= 8.15.0)
+  - firebase_auth (3.3.17):
+    - Firebase/Auth (= 8.15.0)
+    - firebase_core
+    - Flutter
   - firebase_core (1.15.0):
     - Firebase/CoreOnly (= 8.15.0)
     - Flutter
+  - FirebaseAuth (8.15.0):
+    - FirebaseCore (~> 8.0)
+    - GoogleUtilities/AppDelegateSwizzler (~> 7.7)
+    - GoogleUtilities/Environment (~> 7.7)
+    - GTMSessionFetcher/Core (~> 1.5)
   - FirebaseCore (8.15.0):
     - FirebaseCoreDiagnostics (~> 8.0)
     - GoogleUtilities/Environment (~> 7.7)
@@ -18,10 +30,22 @@ PODS:
     - GoogleUtilities/Environment (~> 7.7)
     - nanopb (< 2.30910.0, >= 2.30908.0)
     - PromisesObjC (< 3.0, >= 1.2)
+  - GoogleUtilities/AppDelegateSwizzler (7.7.0):
+    - GoogleUtilities/Environment
+    - GoogleUtilities/Logger
+    - GoogleUtilities/Network
   - GoogleUtilities/Environment (7.7.0):
     - PromisesObjC (< 3.0, >= 1.2)
   - GoogleUtilities/Logger (7.7.0):
     - GoogleUtilities/Environment
+  - GoogleUtilities/Network (7.7.0):
+    - GoogleUtilities/Logger
+    - "GoogleUtilities/NSData+zlib"
+    - GoogleUtilities/Reachability
+  - "GoogleUtilities/NSData+zlib (7.7.0)"
+  - GoogleUtilities/Reachability (7.7.0):
+    - GoogleUtilities/Logger
+  - GTMSessionFetcher/Core (1.7.2)
   - nanopb (2.30908.0):
     - nanopb/decode (= 2.30908.0)
     - nanopb/encode (= 2.30908.0)
@@ -30,20 +54,25 @@ PODS:
   - PromisesObjC (2.1.0)
 
 DEPENDENCIES:
+  - firebase_auth (from `.symlinks/plugins/firebase_auth/ios`)
   - firebase_core (from `.symlinks/plugins/firebase_core/ios`)
   - Flutter (from `Flutter`)
 
 SPEC REPOS:
   trunk:
     - Firebase
+    - FirebaseAuth
     - FirebaseCore
     - FirebaseCoreDiagnostics
     - GoogleDataTransport
     - GoogleUtilities
+    - GTMSessionFetcher
     - nanopb
     - PromisesObjC
 
 EXTERNAL SOURCES:
+  firebase_auth:
+    :path: ".symlinks/plugins/firebase_auth/ios"
   firebase_core:
     :path: ".symlinks/plugins/firebase_core/ios"
   Flutter:
@@ -51,15 +80,18 @@ EXTERNAL SOURCES:
 
 SPEC CHECKSUMS:
   Firebase: 5f8193dff4b5b7c5d5ef72ae54bb76c08e2b841d
+  firebase_auth: 99f8d104a93f4424a4b3b2c4cc5b7596f8181eb7
   firebase_core: fa19947d8db1c0a62d8872c45039b3113829cd2e
+  FirebaseAuth: 3e73bf8abf4fbb40f8b421f361f4cc48ee57388c
   FirebaseCore: 5743c5785c074a794d35f2fff7ecc254a91e08b1
   FirebaseCoreDiagnostics: 92e07a649aeb66352b319d43bdd2ee3942af84cb
   Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
   GoogleDataTransport: 5fffe35792f8b96ec8d6775f5eccd83c998d5a3b
   GoogleUtilities: e0913149f6b0625b553d70dae12b49fc62914fd1
+  GTMSessionFetcher: 5595ec75acf5be50814f81e9189490412bad82ba
   nanopb: a0ba3315591a9ae0a16a309ee504766e90db0c96
   PromisesObjC: 99b6f43f9e1044bd87a95a60beff28c2c44ddb72
 
-PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c
+PODFILE CHECKSUM: fe0e1ee7f3d1f7d00b11b474b62dd62134535aea
 
 COCOAPODS: 1.11.3

+ 28 - 0
app/lib/Services/AuthServiec.dart

@@ -0,0 +1,28 @@
+import 'package:firebase_auth/firebase_auth.dart';
+
+class AuthenticationServices {
+  final FirebaseAuth _auth = FirebaseAuth.instance;
+
+  //Register a user
+  Future createNewUser(String name, String email, String password) async {
+    try {
+      UserCredential result = await _auth.createUserWithEmailAndPassword(
+          email: email, password: password);
+      User? user = result.user;
+      return user;
+    } catch (e) {
+      print(e.toString());
+    }
+  }
+
+  //LogIn with user
+  Future loginUser(String email, String password) async {
+    try {
+      UserCredential result = await _auth.signInWithEmailAndPassword(
+          email: email, password: password);
+      return result.user;
+    } catch(e) {
+      print(e.toString());
+    }
+  }
+}

+ 0 - 0
app/lib/test.dart → app/lib/Services/DatabaseManager.dart


+ 220 - 146
app/lib/SignupPage.dart

@@ -1,4 +1,20 @@
 import 'package:flutter/material.dart';
+import 'package:physigo/Services/AuthServiec.dart';
+
+//Fields..
+TextEditingController _name = TextEditingController();
+TextEditingController _surname = TextEditingController();
+TextEditingController _mail = TextEditingController();
+TextEditingController _phoneNumber = TextEditingController();
+TextEditingController _address = TextEditingController();
+TextEditingController _username = TextEditingController();
+TextEditingController _passwd = TextEditingController();
+TextEditingController _passwd2 = TextEditingController();
+
+bool anonymous = false;
+String? _dateString;
+
+final AuthenticationServices _auth = AuthenticationServices();
 
 class SignupPage extends StatefulWidget {
   const SignupPage({Key? key}) : super(key: key);
@@ -9,14 +25,26 @@ class SignupPage extends StatefulWidget {
 
 class _SignupPageState extends State<SignupPage> {
   int _pageIndex = 0;
-  List<Widget> forms = [SignupForm1(title: '',), SignupForm2(title: '',), SignupForm3(title: '',)];
+
+  List<Widget> forms = [
+    SignupForm1(
+      title: '',
+    ),
+    SignupForm2(
+      title: '',
+    ),
+    SignupForm3(
+      title: '',
+    )
+  ];
 
   void _updatePageIndex(int newPageIndex) {
-    if(newPageIndex == -1) {
+    if (newPageIndex == -1) {
       Navigator.pushNamed(context, '/');
     } else if (newPageIndex == 3) {
       //autentification
-      newPageIndex = 2;
+      //Navigator.pop(context);
+      newPageIndex == 2;
     } else {
       setState(() {
         _pageIndex = newPageIndex;
@@ -30,15 +58,15 @@ class _SignupPageState extends State<SignupPage> {
       floatingActionButton: Row(
         mainAxisAlignment: MainAxisAlignment.end,
         children: [
-          FloatingActionButton(child: Icon(Icons.navigate_before_outlined),
-              onPressed: () => _updatePageIndex(_pageIndex - 1)
-          ),
+          FloatingActionButton(
+              child: Icon(Icons.navigate_before_outlined),
+              onPressed: () => _updatePageIndex(_pageIndex - 1)),
           SizedBox(
             width: 25,
           ),
-
-          FloatingActionButton(child: Icon(Icons.navigate_next_outlined),
-              onPressed: () => _updatePageIndex(_pageIndex +1 ))
+          FloatingActionButton(
+              child: Icon(Icons.navigate_next_outlined),
+              onPressed: () => _updatePageIndex(_pageIndex + 1))
         ],
       ),
       body: Center(child: forms[_pageIndex]),
@@ -57,7 +85,6 @@ class SignupForm1 extends StatefulWidget {
 
 class _SignupForm1 extends State<SignupForm1> {
   DateTime? _dateTime;
-  String? _dateString;
 
   @override
   Widget build(BuildContext context) {
@@ -67,58 +94,58 @@ class _SignupForm1 extends State<SignupForm1> {
       ),
       body: Center(
           child: SizedBox(
-            width: 300,
-            child: Column(children: <Widget>[
-              const SizedBox(height: 30),
-              Text(
-                'Personal Information',
-                style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
-              ),
-              const SizedBox(height: 30),
-              Image.asset(
-                'assets/user.png',
-                width: 150,
-              ),
-              const SizedBox(height: 30),
-              TextField(
-                decoration: InputDecoration(
-                  hintText: 'Name',
-                ),
-              ),
-              const SizedBox(height: 10),
-              TextField(
-                decoration: InputDecoration(
-                  hintText: 'Surname',
-                ),
-              ),
-
-              const SizedBox(height: 10),
-              Row(children: <Widget>[
-                Text(_dateString == null
-                    ? 'Select birthday date :'
-                    : _dateString.toString()),
-                const SizedBox(width: 49),
-                ElevatedButton(
-                  onPressed: () {
-                    showDatePicker(
+        width: 300,
+        child: Column(children: <Widget>[
+          const SizedBox(height: 30),
+          Text(
+            'Personal Information',
+            style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
+          ),
+          const SizedBox(height: 30),
+          Image.asset(
+            'assets/user.png',
+            width: 150,
+          ),
+          const SizedBox(height: 30),
+          TextFormField(
+            controller: _name,
+            decoration: InputDecoration(
+              hintText: 'Name',
+            ),
+          ),
+          const SizedBox(height: 10),
+          TextFormField(
+            controller: _surname,
+            decoration: InputDecoration(
+              hintText: 'Surname',
+            ),
+          ),
+          const SizedBox(height: 10),
+          Row(children: <Widget>[
+            Text(_dateString == null
+                ? 'Select birthday date :'
+                : _dateString.toString()),
+            const SizedBox(width: 49),
+            ElevatedButton(
+              onPressed: () {
+                showDatePicker(
                         context: context,
                         initialDate: DateTime.now(),
                         firstDate: DateTime(1900),
-                        lastDate: DateTime(2222))
-                        .then((date) {
-                      setState(() {
-                        _dateTime = date!;
-                        _dateString = "${date.day}/${date.month}/${date.year}";
-                      });
-                    });
-                  },
-                  child: const Text('Select date'),
-                ),
-              ]),
-              const SizedBox(height: 10),
-
-            ]),
-          )),
+                        lastDate: DateTime.now())
+                    .then((date) {
+                  setState(() {
+                    _dateTime = date!;
+                    _dateString = "${date.day}/${date.month}/${date.year}";
+                  });
+                });
+              },
+              child: const Text('Select date'),
+            ),
+          ]),
+          const SizedBox(height: 10),
+        ]),
+      )),
     );
   }
 }
@@ -133,7 +160,6 @@ class SignupForm2 extends StatefulWidget {
 }
 
 class _SignupForm2 extends State<SignupForm2> {
-  bool isChecked = false;
   @override
   Widget build(BuildContext context) {
     return Scaffold(
@@ -142,58 +168,57 @@ class _SignupForm2 extends State<SignupForm2> {
       ),
       body: Center(
           child: SizedBox(
-            width: 300,
-            child: Column(children: <Widget>[
-              const SizedBox(height: 30),
-              Text(
-                'Contact Details',
-                style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
-              ),
-              const SizedBox(height: 30),
-              Image.asset(
-                'assets/communicate.png',
-                width: 150,
-              ),
-              const SizedBox(height: 30),
-              TextField(
-                decoration: InputDecoration(
-                  hintText: 'Mail',
-                ),
-              ),
-              const SizedBox(height: 10),
-              TextField(
-                decoration: InputDecoration(
-                  hintText: 'Phone Number',
-                ),
-              ),
-              const SizedBox(height: 10),
-              TextField(
-                decoration: InputDecoration(
-                  hintText: 'Home Adress..',
-                ),
-              ),
-              const SizedBox(height: 10),
-              Row(children: <Widget>[
-                Text('Anonymous'),
-                Checkbox(
-
-                  checkColor: Colors.white,
-                  value: isChecked,
-                  onChanged: (bool? value) {
-                    setState(() {
-                      isChecked = value!;
-                    });
-                  },),
-              ]),
-
-              const SizedBox(height: 10),
-
-
-            ]),
-          )),
+        width: 300,
+        child: Column(children: <Widget>[
+          const SizedBox(height: 30),
+          Text(
+            'Contact Details',
+            style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
+          ),
+          const SizedBox(height: 30),
+          Image.asset(
+            'assets/communicate.png',
+            width: 150,
+          ),
+          const SizedBox(height: 30),
+          TextFormField(
+            controller: _mail,
+            decoration: InputDecoration(
+              hintText: 'Mail',
+            ),
+          ),
+          const SizedBox(height: 10),
+          TextFormField(
+            controller: _phoneNumber,
+            decoration: InputDecoration(
+              hintText: 'Phone Number',
+            ),
+          ),
+          const SizedBox(height: 10),
+          TextFormField(
+            controller: _address,
+            decoration: InputDecoration(
+              hintText: 'Home Adress..',
+            ),
+          ),
+          const SizedBox(height: 10),
+          Row(children: <Widget>[
+            Text('Anonymous'),
+            Checkbox(
+              checkColor: Colors.white,
+              value: anonymous,
+              onChanged: (bool? value) {
+                setState(() {
+                  anonymous = value!;
+                });
+              },
+            ),
+          ]),
+          const SizedBox(height: 10),
+        ]),
+      )),
     );
   }
-
 }
 
 class SignupForm3 extends StatefulWidget {
@@ -206,7 +231,6 @@ class SignupForm3 extends StatefulWidget {
 }
 
 class _SignupForm3 extends State<SignupForm3> {
-
   @override
   Widget build(BuildContext context) {
     return Scaffold(
@@ -215,41 +239,91 @@ class _SignupForm3 extends State<SignupForm3> {
       ),
       body: Center(
           child: SizedBox(
-            width: 300,
-            child: Column(children: <Widget>[
-              const SizedBox(height: 30),
-              Text(
-                'User details',
-                style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
-              ),
-              const SizedBox(height: 30),
-              Image.asset(
-                'assets/id-card.png',
-                width: 150,
-              ),
-              const SizedBox(height: 30),
-              TextField(
-                decoration: InputDecoration(
-                  hintText: 'Username',
-                ),
-              ),
-              const SizedBox(height: 10),
-              TextField(
-                decoration: InputDecoration(
-                  hintText: 'Password',
-                ),
-              ),
-              const SizedBox(height: 10),
-              TextField(
-                decoration: InputDecoration(
-                  hintText: 'Repeat password',
-                ),
-              ),
-              const SizedBox(height: 10),
-
-            ]),
-          )),
+        width: 300,
+        child: Column(children: <Widget>[
+          const SizedBox(height: 30),
+          Text(
+            'User details',
+            style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
+          ),
+          const SizedBox(height: 30),
+          Image.asset(
+            'assets/id-card.png',
+            width: 150,
+          ),
+          const SizedBox(height: 30),
+          TextFormField(
+            controller: _username,
+            decoration: InputDecoration(
+              hintText: 'Username',
+            ),
+          ),
+          const SizedBox(height: 10),
+          TextFormField(
+            controller: _passwd,
+            decoration: InputDecoration(
+              hintText: 'Password',
+            ),
+          ),
+          const SizedBox(height: 10),
+          TextFormField(
+            controller: _passwd2,
+            decoration: InputDecoration(
+              hintText: 'Repeat password',
+            ),
+          ),
+          const SizedBox(height: 15),
+          ElevatedButton(
+              onPressed: () {
+                try {
+                  if (_passwd.text == _passwd2.text) {
+                    createUser();
+                    Navigator.pop(context);
+                  } else {
+                    print("passwd is not the same");
+                  }
+                } catch (e) {
+                  print(e.toString());
+                }
+              },
+              child: const Text('Finish Register'))
+        ]),
+      )),
     );
   }
 
-}
+  void createUser() async {
+    dynamic result =
+        await _auth.createNewUser(_name.text, _mail.text, _passwd.text);
+    if (result == null) {
+      print('mail not valid');
+    } else {
+      //print(result.toString());
+      //[51.787378° N, 19.449455° E]
+
+      print('*****  address: ' + _address.text +
+          ' anonymous: ' + anonymous.toString() +
+          ' birthdate: ' + _dateString.toString() +
+          ' createDate: ' + DateTime.now().toString()+
+          ' last_challenge_data: ' + 'null'+
+          ' mail: ' + _mail.text +
+          ' name: ' + _name.text +
+          ' passwd: ' + '??? ' +
+          ' phone_number: ' + _phoneNumber.text+
+          ' shared_id: ' + _username.text +
+          ' surname: ' + _surname.text +
+          ' totalpoints: 0 ' +
+          ' update_date: ' + DateTime.now().toString()+
+          ' weeklyplace: ' + 'null');
+
+      _name.clear();
+      _surname.clear();
+      _mail.clear();
+      _phoneNumber.clear();
+      _address.clear();
+      _username.clear();
+      _passwd.clear();
+      _passwd2.clear();
+    }
+  }
+}

+ 23 - 3
app/lib/logIn.dart

@@ -1,5 +1,7 @@
 import 'package:flutter/material.dart';
 
+import 'Services/AuthServiec.dart';
+
 class LogIn extends StatefulWidget {
   const LogIn({Key? key, required this.title}) : super(key: key);
   final String title;
@@ -10,6 +12,10 @@ class LogIn extends StatefulWidget {
 }
 
 class _LogIn extends State<LogIn> {
+  TextEditingController _email = TextEditingController();
+  TextEditingController _passwd = TextEditingController();
+  final AuthenticationServices _auth = AuthenticationServices();
+
 
   @override
   Widget build(BuildContext context) {
@@ -32,13 +38,15 @@ class _LogIn extends State<LogIn> {
                 width: 150,
               ),
               const SizedBox(height: 30),
-              TextField(
+              TextFormField(
+                controller: _email,
                 decoration: InputDecoration(
                   hintText: 'Mail or mobile phone',
                 ),
               ),
               const SizedBox(height: 10),
-              TextField(
+              TextFormField(
+                controller: _passwd,
                 decoration: InputDecoration(
                   hintText: 'Password',
                 ),
@@ -46,7 +54,7 @@ class _LogIn extends State<LogIn> {
               const SizedBox(height: 10),
               ElevatedButton(
                 onPressed: () {
-
+                  signInUser();
                 },
                 child: const Text('Log In'),
               ),
@@ -56,4 +64,16 @@ class _LogIn extends State<LogIn> {
           )),
     );
   }
+
+  void signInUser() async {
+    dynamic authResult = await _auth.loginUser(_email.text, _passwd.text);
+    if (authResult==null) {
+      print("log in error");
+    } else {
+      _email.clear();
+      _passwd.clear();
+      print("Succesful login ");
+      Navigator.pushNamed(context, '/mainPage');
+    }
+  }
 }

+ 3 - 1
app/lib/main.dart

@@ -5,6 +5,7 @@ import 'firebase_options.dart';
 import 'push_notifications_initializer.dart';
 import 'package:physigo/logIn.dart';
 import 'package:physigo/SignupPage.dart';
+import 'package:physigo/mainPage.dart';
 import 'package:physigo/welcomeScreen.dart';
 
 void main() async {
@@ -32,7 +33,8 @@ class PhysiGo extends StatelessWidget {
         '/register': (context) => SignupPage(),
         //'/register2': (context) => RegisterScreen2(title: ''),
         //'/register3': (context) => RegisterScreen3(title: ''),
-        '/login': (context) => LogIn(title: '')
+        '/login': (context) => LogIn(title: ''),
+        '/mainPage': (context) => MainPage()
       },
       //home: const MyHomePage(title: 'Flutter Demo Home Page'),
     );

+ 23 - 0
app/lib/mainPage.dart

@@ -0,0 +1,23 @@
+import 'package:flutter/material.dart';
+
+class MainPage extends StatefulWidget {
+  const MainPage({Key? key}) : super(key: key);
+  @override
+  State<MainPage> createState() => _MainPage();
+}
+class _MainPage extends State<MainPage> {
+
+
+  @override
+  Widget build(BuildContext context) {
+    return Scaffold(
+      floatingActionButton: FloatingActionButton(
+        onPressed: () {
+
+        },
+        child: Icon(Icons.add),
+      ),
+      body: Center(child: Text("hello")),
+    );
+  }
+}

+ 21 - 0
app/pubspec.lock

@@ -92,6 +92,27 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "1.2.0"
+  firebase_auth:
+    dependency: "direct main"
+    description:
+      name: firebase_auth
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "3.3.17"
+  firebase_auth_platform_interface:
+    dependency: transitive
+    description:
+      name: firebase_auth_platform_interface
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "6.2.5"
+  firebase_auth_web:
+    dependency: transitive
+    description:
+      name: firebase_auth_web
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "3.3.14"
   firebase_core:
     dependency: "direct main"
     description:

+ 2 - 0
app/pubspec.yaml

@@ -31,6 +31,7 @@ dependencies:
     sdk: flutter
 
 
+
   # The following adds the Cupertino Icons font to your application.
   # Use with the CupertinoIcons class for iOS style icons.
   cupertino_icons: ^1.0.2
@@ -44,6 +45,7 @@ dependencies:
   cloud_firestore: ^3.1.15
   firebase_messaging: ^11.4.0
   awesome_notifications: ^0.6.21
+  firebase_auth: ^3.3.17
 
 dev_dependencies:
   flutter_test: