Skip to content

Commit

Permalink
Merge pull request #2 from rudramistry001/uat
Browse files Browse the repository at this point in the history
uat code merge to main
  • Loading branch information
rudramistry001 authored Mar 15, 2024
2 parents a0ee326 + f7c9f50 commit c730dae
Show file tree
Hide file tree
Showing 19 changed files with 1,218 additions and 710 deletions.
Binary file added login/assets/images/login_frame.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions login/assets/images/login_frame.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 81 additions & 1 deletion login/lib/api/apis.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// ignore_for_file: avoid_print

import 'dart:convert';
import 'dart:io';

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:http/http.dart';
import 'package:login/model/chat_user_model.dart';
import 'package:login/model/messages.dart';

Expand All @@ -23,6 +26,58 @@ class APIs {
//for returning current user
static User get user => auth.currentUser!;

// for accessing firebase messaging (Push Notification)
static FirebaseMessaging fMessaging = FirebaseMessaging.instance;

// for getting firebase messaging token
static Future<void> getFirebaseMessagingToken() async {
await fMessaging.getToken().then((t) {
if (t != null) {
me.PushToken = t;
print('Push Token: $t');
}
});

// for handling foreground messages
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
print('Got a message whilst in the foreground!');
print('Message data: ${message.data}');

if (message.notification != null) {
print('Message also contained a notification: ${message.notification}');
}
});
}

// for sending push notification
static Future<void> sendPushNotification(
ChatUser chatUser, String msg) async {
try {
final body = {
"to": chatUser.PushToken,
"notification": {
"title": me.Name, //our name should be send
"body": msg,
},
// "data": {
// "some_data": "User ID: ${me.id}",
// },
};

var res = await post(Uri.parse('https://fcm.googleapis.com/fcm/send'),
headers: {
HttpHeaders.contentTypeHeader: 'application/json',
HttpHeaders.authorizationHeader:
'key=AAAAJoFEO6I:APA91bElgw77iGQYJdEov_3ea5i3j6_vpjpPm7q4D4xahUmOPny_4W9g3Vus_FgrldMScGNcd7qn46lko8wTYsX-yZQsJhRrKaj5T_NV3TkJ8vLkMIxxkSKLuz2mwbNelOCo-t7ma-3N'
},
body: jsonEncode(body));
print('Response status: ${res.statusCode}');
print('Response body: ${res.body}');
} catch (e) {
print('\nsendPushNotificationE: $e');
}
}

//for checking if user exists or not??
static Future<bool> userExists() async {
return (await firestore.collection('Users').doc(user.uid).get()).exists;
Expand All @@ -33,6 +88,9 @@ class APIs {
await firestore.collection('Users').doc(user.uid).get().then((user) async {
if (user.exists) {
me = ChatUser.fromJson(user.data()!);
await getFirebaseMessagingToken();

APIs.updateActiveStatus(true);
} else {
await createUser().then((value) => getSelfInfo());
}
Expand Down Expand Up @@ -119,6 +177,27 @@ class APIs {
.snapshots();
}

// // for sending message
// static Future<void> sendMessage(
// ChatUser chatUser, String msg, Type type) async {
// //message sending time (also used as id)
// final time = DateTime.now().millisecondsSinceEpoch.toString();

// //message to send
// final Message message = Message(
// toId: chatUser.Id,
// msg: msg,
// read: '',
// type: type,
// fromId: user.uid,
// sent: time);

// final ref = firestore
// .collection('chats/${getConversationID(chatUser.Id)}/messages/');
// await ref.doc(time).set(message.toJson()).then((value) =>
// sendPushNotification(chatUser, type == Type.text ? msg : 'image'));
// }

// for sending message
static Future<void> sendMessage(
ChatUser chatUser,
Expand All @@ -139,7 +218,8 @@ class APIs {

final ref = firestore
.collection('chats/${getConversationID(chatUser.Id)}/messages/');
await ref.doc(time).set(message.toJson());
await ref.doc(time).set(message.toJson()).then((value) =>
sendPushNotification(chatUser, type == Type.text ? msg : 'image'));;
}

//update read status of message
Expand Down
222 changes: 157 additions & 65 deletions login/lib/auth/loginscreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:login/api/apis.dart';
import 'package:login/auth/firebase_auth_servies.dart';
import 'package:login/auth/signuppage.dart';
import 'package:login/main.dart';
import 'package:login/screens/homescreen.dart';

class LoginPage extends StatefulWidget {
Expand Down Expand Up @@ -34,75 +36,165 @@ class _LoginPageState extends State<LoginPage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Login Page'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextField(
controller: emailController,
keyboardType: TextInputType.emailAddress,
decoration: const InputDecoration(
labelText: 'Email',
border: OutlineInputBorder(),
backgroundColor: Colors.transparent,
title: Center(
child: Column(
children: [
Text(
"Login",
style: TextStyle(
fontSize: 22.sp,
fontWeight: FontWeight.w600,
color: Colors.white),
),
),
const SizedBox(height: 16.0),
TextField(
controller: passwordController,
obscureText: true,
decoration: const InputDecoration(
labelText: 'Password',
border: OutlineInputBorder(),
Text(
"Enter Email Password to continue",
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w300,
color: Colors.white),
),
),
const SizedBox(height: 32.0),
isSignIn
? const CircularProgressIndicator(
color: Colors.black,
)
: ElevatedButton(
onPressed: () {
print('Email: ${emailController.text}');
print('Password: ${passwordController.text}');
_signIn();
APIs.updateActiveStatus(true);
},
child: const Text('Login'),
),
InkWell(
onTap: () {
//
},
child: const Row(
mainAxisAlignment: MainAxisAlignment.center,
],
),
),
),
extendBodyBehindAppBar: true,
body: Container(
decoration: const BoxDecoration(
//gradient: LinearGradient(colors: Colors.white ),
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Color.fromRGBO(0, 248, 248, 1),
Color.fromRGBO(0, 57, 89, 1),
],
),
),
child: Stack(children: [
//for showing the robot background image
Align(
alignment: Alignment.topCenter,
child: Image.asset("assets/images/login_frame.png"),
),
Positioned(
bottom: 0,
child: Column(
children: [
Icon(Icons.account_circle),
Text("Sign in with Google "),
20.verticalSpace,
SizedBox(
width: mq.width * 1,
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
20.verticalSpace,
TextField(
controller: emailController,
keyboardType: TextInputType.emailAddress,
style: const TextStyle(
color:
Colors.white, // Change text color to blue
),
decoration: InputDecoration(
labelText: 'Email',
labelStyle: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w300,
color: Colors.white,
),
border: const OutlineInputBorder(),
),
),
15.verticalSpace,
TextField(
controller: passwordController,
obscureText: true,
style: const TextStyle(
color:
Colors.white, // Change text color to blue
),
decoration: InputDecoration(
labelText: 'Password',
labelStyle: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w300,
color: Colors.white,
),
border: const OutlineInputBorder(),
),
),
const SizedBox(height: 32.0),
isSignIn
? const CircularProgressIndicator(
color: Colors.black,
)
: ElevatedButton.icon(
icon: const Icon(Icons.login,
color: Colors.white),
onPressed: () {
print('Email: ${emailController.text}');
print(
'Password: ${passwordController.text}');
_signIn();

},
label: Text(
"Login",
style: TextStyle(
color: Colors.white,
fontSize: 20.sp,
),
),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color>(
Colors.blueAccent),
// Change the color here
),
),
InkWell(
onTap: () {
//
},
child: const Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.account_circle),
Text("Sign in with Google "),
],
),
),
const SizedBox(
height: 30,
),
Row(
children: [
const Text("New User?"),
TextButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
const SignUpPage()),
);
},
child: const Text("Sign up"))
],
),
],
),
),
],
),
)
],
),
),
const SizedBox(
height: 30,
),
Row(
children: [
const Text("New User?"),
TextButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const SignUpPage()),
);
},
child: const Text("Sign up"))
],
),
],
),
)),
]),
),
);
}
Expand Down
Loading

0 comments on commit c730dae

Please sign in to comment.