From 0b3b10c9f9e9fd3a7233f08b158ccb21196d75b0 Mon Sep 17 00:00:00 2001 From: Ashish Sharma Date: Sat, 17 Feb 2024 20:37:03 +0530 Subject: [PATCH 1/5] fixed eslint & prettier conflicts --- functions/.eslintrc.js | 2 +- functions/src/index.ts | 70 ++++++++++++++++++++++++++---------------- 2 files changed, 45 insertions(+), 27 deletions(-) diff --git a/functions/.eslintrc.js b/functions/.eslintrc.js index c280fc8..151f2b9 100644 --- a/functions/.eslintrc.js +++ b/functions/.eslintrc.js @@ -27,6 +27,6 @@ module.exports = { semi: ["error", "never"], quotes: ["error", "double"], "import/no-unresolved": 0, - "max-len": ["error", { code: 90 }], + "max-len": ["error", { code: 120 }], }, } diff --git a/functions/src/index.ts b/functions/src/index.ts index d235523..0fe4232 100644 --- a/functions/src/index.ts +++ b/functions/src/index.ts @@ -26,64 +26,82 @@ export const helloWorld = functions.https.onRequest(async (request, response) => phone: "8208567820", }, }) - console.log(request.params); + console.log(request.params) const snapshot = await db.ref("users/kilvishId1").get() response.send(snapshot.val()) }) export const verifyOtp = functions.https.onRequest(async (request, response) => { - const reqBody = JSON.stringify(request.body); - const data = JSON.parse(reqBody)['data']; + const reqBody = JSON.stringify(request.body) + const data = JSON.parse(reqBody)["data"] - const kilvishId = data["kilvishId"]; - const phoneOtp = data["phoneOtp"]; - const emailOtp = data["emailOtp"]; + const kilvishId = data["kilvishId"] + const phoneOtp = data["phoneOtp"] + const emailOtp = data["emailOtp"] const snapshot = await db.ref(`users/${kilvishId}`).get() if (snapshot != null && snapshot.val()) { const additionalInfo = { email: snapshot.val()["email"], phone: snapshot.val()["phone"], - }; + } if (snapshot.val()["verifyPhone"] && snapshot.val()["verifyEmail"]) { if (phoneOtp == "0000" && emailOtp == "0000") { - const customToken = await getAuth().createCustomToken(kilvishId, additionalInfo); - response.status(200).send({ "data": { "success": true, "token": customToken } }) + const customToken = await getAuth().createCustomToken(kilvishId, additionalInfo) + response.status(200).send({ data: { success: true, token: customToken } }) } } else { if (phoneOtp == "1234" && emailOtp == "5678") { - const customToken = await getAuth().createCustomToken(kilvishId, additionalInfo); - const usersRef = db.ref("users"); - const userInfo = { [kilvishId]: { "kilvishId": kilvishId, "email": snapshot.val()["email"], "phone": snapshot.val()["phone"], "verifyPhone": true, "verifyEmail": true } }; + const customToken = await getAuth().createCustomToken(kilvishId, additionalInfo) + const usersRef = db.ref("users") + const userInfo = { + [kilvishId]: { + kilvishId: kilvishId, + email: snapshot.val()["email"], + phone: snapshot.val()["phone"], + verifyPhone: true, + verifyEmail: true, + }, + } await usersRef.update(userInfo) - response.status(200).send({ "data": { "success": true, "token": customToken } }) + response.status(200).send({ data: { success: true, token: customToken } }) } } } - response.status(400).send({ "data": { "success": false, "message": "User Not Found" } }) + response.status(400).send({ data: { success: false, message: "User Not Found" } }) }) export const verifyUser = functions.https.onRequest(async (request, response) => { - const reqBody = JSON.stringify(request.body); - const data = JSON.parse(reqBody)['data']; + const reqBody = JSON.stringify(request.body) + const data = JSON.parse(reqBody)["data"] - const kilvishId = data["kilvishId"]; - const email = data["email"]; - const phone = data["phone"]; + const kilvishId = data["kilvishId"] + const email = data["email"] + const phone = data["phone"] - const userInfo = { [kilvishId]: { "kilvishId": kilvishId, "email": email, "phone": phone } }; + const userInfo = { [kilvishId]: { kilvishId: kilvishId, email: email, phone: phone } } const snapshot = await db.ref(`users/${kilvishId}`).get() if (snapshot != null && snapshot.val()) { if (snapshot.val()["email"] == email && snapshot.val()["phone"] == phone) { - /// Logic for send OTP - response.status(200).send({ "data": { "success": true } }) + // / Logic for send OTP + response.status(200).send({ data: { success: true } }) } else { - response.status(404).send({ "data": { "success": false, "message": "Wrong email phone number please enter correct correct" } }) + response.status(404).send({ + data: { + success: false, + message: "Wrong email phone number please enter correct correct", + }, + }) } } else { - const usersRef = db.ref("users"); + const usersRef = db.ref("users") await usersRef.update(userInfo) - /// Logic for send OTP - response.status(201).send({ 'data': { "success": true, "userInfo": { "kilvishId": kilvishId, "email": email, "phone": phone } } }) + // / Logic for send OTP + response.status(201).send({ + data: { + success: true, + userInfo: { kilvishId: kilvishId, email: email, phone: phone }, + }, + }) } }) From 089cb70060e6070cebf8f5c8c3cb9b57c0f8dfe6 Mon Sep 17 00:00:00 2001 From: Ashish Sharma Date: Sat, 17 Feb 2024 20:39:39 +0530 Subject: [PATCH 2/5] included js files in functions/ as part of git --- functions/.gitignore | 4 -- functions/lib/index.js | 105 +++++++++++++++++++++++++++++++++++++ functions/lib/index.js.map | 1 + 3 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 functions/lib/index.js create mode 100644 functions/lib/index.js.map diff --git a/functions/.gitignore b/functions/.gitignore index 65b4c06..6c507f0 100644 --- a/functions/.gitignore +++ b/functions/.gitignore @@ -1,7 +1,3 @@ -# Compiled JavaScript files -lib/**/*.js -lib/**/*.js.map - # TypeScript v1 declaration files typings/ diff --git a/functions/lib/index.js b/functions/lib/index.js new file mode 100644 index 0000000..bafb687 --- /dev/null +++ b/functions/lib/index.js @@ -0,0 +1,105 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.verifyUser = exports.verifyOtp = exports.helloWorld = void 0; +const functions = require("firebase-functions"); +const admin = require("firebase-admin"); +const auth_1 = require("firebase-admin/auth"); +const app = admin.initializeApp({ + databaseURL: "https://kilvish-aa125-default-rtdb.asia-southeast1.firebasedatabase.app/", +}); +const db = admin.database(app); +// Start writing Firebase Functions +// https://firebase.google.com/docs/functions/typescript +exports.helloWorld = functions.https.onRequest(async (request, response) => { + const usersRef = db.ref("users"); + await usersRef.update({ + kilvishId1: { + kilvishId: "kilvishId1", + name: "Radhey", + email: "radheyit@gmail.com", + phone: "8983026208", + }, + kilvishId2: { + kilvishId: "KilvishId2", + name: "dummy Name", + email: "adminji@yopmail.com", + phone: "8208567820", + }, + }); + console.log(request.params); + const snapshot = await db.ref("users/kilvishId1").get(); + response.send(snapshot.val()); +}); +exports.verifyOtp = functions.https.onRequest(async (request, response) => { + const reqBody = JSON.stringify(request.body); + const data = JSON.parse(reqBody)["data"]; + const kilvishId = data["kilvishId"]; + const phoneOtp = data["phoneOtp"]; + const emailOtp = data["emailOtp"]; + const snapshot = await db.ref(`users/${kilvishId}`).get(); + if (snapshot != null && snapshot.val()) { + const additionalInfo = { + email: snapshot.val()["email"], + phone: snapshot.val()["phone"], + }; + if (snapshot.val()["verifyPhone"] && snapshot.val()["verifyEmail"]) { + if (phoneOtp == "0000" && emailOtp == "0000") { + const customToken = await (0, auth_1.getAuth)().createCustomToken(kilvishId, additionalInfo); + response.status(200).send({ data: { success: true, token: customToken } }); + } + } + else { + if (phoneOtp == "1234" && emailOtp == "5678") { + const customToken = await (0, auth_1.getAuth)().createCustomToken(kilvishId, additionalInfo); + const usersRef = db.ref("users"); + const userInfo = { + [kilvishId]: { + kilvishId: kilvishId, + email: snapshot.val()["email"], + phone: snapshot.val()["phone"], + verifyPhone: true, + verifyEmail: true, + }, + }; + await usersRef.update(userInfo); + response.status(200).send({ data: { success: true, token: customToken } }); + } + } + } + response.status(400).send({ data: { success: false, message: "User Not Found" } }); +}); +exports.verifyUser = functions.https.onRequest(async (request, response) => { + const reqBody = JSON.stringify(request.body); + const data = JSON.parse(reqBody)["data"]; + const kilvishId = data["kilvishId"]; + const email = data["email"]; + const phone = data["phone"]; + const userInfo = { [kilvishId]: { kilvishId: kilvishId, email: email, phone: phone } }; + const snapshot = await db.ref(`users/${kilvishId}`).get(); + if (snapshot != null && snapshot.val()) { + if (snapshot.val()["email"] == email && snapshot.val()["phone"] == phone) { + // / Logic for send OTP + response.status(200).send({ data: { success: true } }); + } + else { + response.status(404).send({ + data: { + success: false, + message: "Wrong email phone number please enter correct correct", + }, + }); + } + } + else { + const usersRef = db.ref("users"); + await usersRef.update(userInfo); + // / Logic for send OTP + response.status(201).send({ + data: { + success: true, + userInfo: { kilvishId: kilvishId, email: email, phone: phone }, + }, + }); + } +}); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/functions/lib/index.js.map b/functions/lib/index.js.map new file mode 100644 index 0000000..9d16653 --- /dev/null +++ b/functions/lib/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,gDAA+C;AAC/C,wCAAuC;AACvC,8CAA6C;AAE7C,MAAM,GAAG,GAAG,KAAK,CAAC,aAAa,CAAC;IAC9B,WAAW,EAAE,0EAA0E;CACxF,CAAC,CAAA;AACF,MAAM,EAAE,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;AAE9B,mCAAmC;AACnC,wDAAwD;AAE3C,QAAA,UAAU,GAAG,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE;IAC9E,MAAM,QAAQ,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IAChC,MAAM,QAAQ,CAAC,MAAM,CAAC;QACpB,UAAU,EAAE;YACV,SAAS,EAAE,YAAY;YACvB,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,oBAAoB;YAC3B,KAAK,EAAE,YAAY;SACpB;QACD,UAAU,EAAE;YACV,SAAS,EAAE,YAAY;YACvB,IAAI,EAAE,YAAY;YAClB,KAAK,EAAE,qBAAqB;YAC5B,KAAK,EAAE,YAAY;SACpB;KACF,CAAC,CAAA;IACF,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IAC3B,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,GAAG,EAAE,CAAA;IACvD,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAA;AAC/B,CAAC,CAAC,CAAA;AAEW,QAAA,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE;IAC7E,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,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3/5] made some changes to the signup form --- lib/signup_screen.dart | 68 +++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/lib/signup_screen.dart b/lib/signup_screen.dart index 79e5c79..8f8e3b9 100644 --- a/lib/signup_screen.dart +++ b/lib/signup_screen.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:cloud_functions/cloud_functions.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/material.dart'; @@ -34,6 +36,7 @@ class SignUpPageState extends State { TextEditingController(); final _formKey = GlobalKey(); bool sendOtpSuccess = false; + bool isOtpButtonEnabled = true; @override void initState() { @@ -144,9 +147,8 @@ class SignUpPageState extends State { ), SignupForm( stepNumber: "1", - fieldLabel: "Setup Kilvish Id", - buttonLabel: "Get Started", - hint: "crime-master-gogo", + fieldLabel: "Kilvish Id", + hint: "First time user ? Create a new kilvish id", isActive: _stepNumber == 1 && (!sendOtpSuccess), isOperationAllowedButNotActive: _stepNumber > 1, buttonClickHandler: () => allowFormSubmission(1), @@ -155,10 +157,7 @@ class SignUpPageState extends State { ), SignupForm( stepNumber: "2", - fieldLabel: - (_stepNumber == 2) ? "Phone Number" : "Update Phone Number", - buttonLabel: - (_stepNumber == 2) ? "Get OTP" : "Get OTP for new number", + fieldLabel: "Phone Number", hint: "7019316063", isActive: _stepNumber == 2 && (!sendOtpSuccess), isOperationAllowedButNotActive: _stepNumber > 2, @@ -169,14 +168,26 @@ class SignUpPageState extends State { ), SignupForm( stepNumber: "3", - fieldLabel: "Enter Email Id", - buttonLabel: "Send OTP", + fieldLabel: "Email Id", + buttonLabel: sendOtpSuccess + ? (isOtpButtonEnabled ? "Re-requet OTP" : "Please wait ..") + : "Get OTP", hint: "admin@mail.com", isActive: _stepNumber == 3 && (!sendOtpSuccess), isOperationAllowedButNotActive: _stepNumber > 3, buttonClickHandler: () { verifyUser(); + setState(() { + _stepNumber = 4; + isOtpButtonEnabled = false; + }); + Timer(const Duration(seconds: 10), () { + setState(() { + isOtpButtonEnabled = true; + }); + }); }, + buttonEnabled: isOtpButtonEnabled, buttonVisible: true, textFocus: _emailTextFocus, controller: _emailTextEditingController, @@ -193,8 +204,8 @@ class SignUpPageState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ renderInputLabel("Phone OTP", _stepNumber == 4), - renderTextField(_otpPhoneTextEditingController, - "Enter Phone OTP", _otpPhoneTextFocus) + renderTextField(_otpPhoneTextEditingController, "xxxx", + _otpPhoneTextFocus) ], )), const SizedBox(width: 16), @@ -204,8 +215,8 @@ class SignUpPageState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ renderInputLabel("Email OTP", _stepNumber == 5), - renderTextField(_otpEmailTextEditingController, - "Enter Email OTP", _otpEmailTextFocus) + renderTextField(_otpEmailTextEditingController, "xxxx", + _otpEmailTextFocus) ], )), ], @@ -348,7 +359,7 @@ String? genericFieldValidator(String? value) { class SignupForm extends StatefulWidget { final String stepNumber; final String fieldLabel; - final String buttonLabel; + final String? buttonLabel; final String hint; final bool isActive; final bool isOperationAllowedButNotActive; @@ -358,11 +369,12 @@ class SignupForm extends StatefulWidget { final TextEditingController controller; final TextInputAction textInputAction; final bool buttonVisible; + final bool buttonEnabled; const SignupForm({ required this.stepNumber, required this.fieldLabel, - required this.buttonLabel, + this.buttonLabel, required this.hint, required this.isActive, required this.isOperationAllowedButNotActive, @@ -372,6 +384,7 @@ class SignupForm extends StatefulWidget { required this.controller, this.textInputAction = TextInputAction.next, this.buttonVisible = false, + this.buttonEnabled = false, super.key, }) : fieldValidator = fieldvalidator ?? genericFieldValidator; @@ -407,13 +420,7 @@ class SignupFormState extends State { ], ), ]); - if (widget.isActive) { - //this will give focus to the active input field - widget.textFocus.requestFocus(); - } else { - //this will give un focus to the in active input field - widget.textFocus.unfocus(); - } + return uiWidget; } @@ -445,7 +452,6 @@ class SignupFormState extends State { Widget renderTextField() { return TextFormField( - readOnly: !widget.isActive, controller: widget.controller, decoration: InputDecoration( hintText: widget.isActive ? widget.hint : "", @@ -456,27 +462,21 @@ class SignupFormState extends State { } Widget renderFormSubmitButton() { - StadiumBorder? greyBorderIfNeeded = (widget.isOperationAllowedButNotActive) + StadiumBorder? greyBorderIfNeeded = (widget.buttonEnabled) ? const StadiumBorder( side: BorderSide(color: primaryColor, width: 2), ) : const StadiumBorder(); - Color backgroundColor = (widget.isActive) ? primaryColor : inactiveColor; + Color backgroundColor = + (widget.buttonEnabled) ? primaryColor : inactiveColor; return TextButton( style: TextButton.styleFrom( backgroundColor: backgroundColor, minimumSize: const Size.fromHeight(50), shape: greyBorderIfNeeded), - onPressed: widget.isActive - ? () { - if (!widget.isActive && !widget.isOperationAllowedButNotActive) { - return denyFormSubmission(); - } - widget.buttonClickHandler(); - } - : null, - child: Text(widget.buttonLabel, + onPressed: widget.buttonEnabled ? widget.buttonClickHandler : null, + child: Text(widget.buttonLabel ?? "Click Me", style: const TextStyle(color: Colors.white, fontSize: 15)), ); } From 8ade0dd69fa4f5e3047f6c5983b54645ef2db05f Mon Sep 17 00:00:00 2001 From: Ashish Sharma Date: Tue, 20 Feb 2024 12:14:21 +0530 Subject: [PATCH 4/5] removed focus when any button is clicked --- lib/signup_screen.dart | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/signup_screen.dart b/lib/signup_screen.dart index 8f8e3b9..8aedef6 100644 --- a/lib/signup_screen.dart +++ b/lib/signup_screen.dart @@ -94,6 +94,14 @@ class SignUpPageState extends State { super.dispose(); } + void removeFocusFromAllInputFields() { + _kilvishTextFocus.unfocus(); + _phoneTextFocus.unfocus(); + _emailTextFocus.unfocus(); + _otpEmailTextFocus.unfocus(); + _otpPhoneTextFocus.unfocus(); + } + void allowFormSubmission(int stepNumber) { setState(() { _stepNumber = stepNumber + 1; @@ -176,6 +184,7 @@ class SignUpPageState extends State { isActive: _stepNumber == 3 && (!sendOtpSuccess), isOperationAllowedButNotActive: _stepNumber > 3, buttonClickHandler: () { + removeFocusFromAllInputFields(); verifyUser(); setState(() { _stepNumber = 4; @@ -257,6 +266,7 @@ class SignUpPageState extends State { minimumSize: const Size.fromHeight(50), shape: greyBorderIfNeeded), onPressed: () { + removeFocusFromAllInputFields(); verifyOtp(); }, child: const Text("Verify OTP", @@ -421,6 +431,14 @@ class SignupFormState extends State { ), ]); + if (widget.isActive) { + //this will give focus to the active input field + widget.textFocus.requestFocus(); + } else { + //this will give un focus to the in active input field + widget.textFocus.unfocus(); + } + return uiWidget; } From 29df82bb2c6ec9778c8ce2d3a0fb42a2ea2e8ec4 Mon Sep 17 00:00:00 2001 From: Ashish Sharma Date: Tue, 20 Feb 2024 12:28:16 +0530 Subject: [PATCH 5/5] created support text for input fields --- README.md | 3 +++ lib/common_widgets.dart | 15 +++++++++++++++ lib/signup_screen.dart | 11 +++++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 50da4fc..5e1b0f5 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,9 @@ More details at [kilvish.in](https://kilvish.in) - Due to sharing related changes, android & iOS specific code is written which had broken the web or MacOS builds. - `flutter build apk --debug && flutter install --debug` will build & install apk in an already running emulator - To run an Android emulator, install Android Studio & launch an emulator with the AVD manager + - To make it easier to launch emulator every time, add `/path/to/sdk/emulator` to PATH variable & run command `emulator -avd ` + - you can find SDK path from Android Studio -> Settings -> Appearance & Behavior -> Android SDK + - To give a short name to the emulator, launch AVD manager from Android Studio, click on the pencil/edit button of the emulator & give it a short name that you can pass to the emulator command above. ## Firebase Setup diff --git a/lib/common_widgets.dart b/lib/common_widgets.dart index f39d964..e98b4a9 100644 --- a/lib/common_widgets.dart +++ b/lib/common_widgets.dart @@ -115,6 +115,21 @@ Widget renderLabel( ))); } +Widget renderSupportLabel( + {required String text, + Color color = inactiveColor, + double fontSize = smallFontSize, + double topSpacing = 0}) { + return Container( + margin: EdgeInsets.only(top: topSpacing), + child: Align( + alignment: Alignment.centerLeft, + child: Text( + text, + style: TextStyle(color: color, fontSize: fontSize), + ))); +} + Widget renderHelperText({required String text}) { return Container( margin: const EdgeInsets.only(top: 5, bottom: 10), diff --git a/lib/signup_screen.dart b/lib/signup_screen.dart index 8aedef6..ac5cfef 100644 --- a/lib/signup_screen.dart +++ b/lib/signup_screen.dart @@ -156,7 +156,8 @@ class SignUpPageState extends State { SignupForm( stepNumber: "1", fieldLabel: "Kilvish Id", - hint: "First time user ? Create a new kilvish id", + supportLabel: "First time user ? Get a new id", + hint: "crime-master-gogo", isActive: _stepNumber == 1 && (!sendOtpSuccess), isOperationAllowedButNotActive: _stepNumber > 1, buttonClickHandler: () => allowFormSubmission(1), @@ -166,6 +167,7 @@ class SignUpPageState extends State { SignupForm( stepNumber: "2", fieldLabel: "Phone Number", + supportLabel: "OTP will be sent on this number", hint: "7019316063", isActive: _stepNumber == 2 && (!sendOtpSuccess), isOperationAllowedButNotActive: _stepNumber > 2, @@ -177,10 +179,12 @@ class SignUpPageState extends State { SignupForm( stepNumber: "3", fieldLabel: "Email Id", + supportLabel: + "In future, you can receive OTP either on email or on phone", buttonLabel: sendOtpSuccess ? (isOtpButtonEnabled ? "Re-requet OTP" : "Please wait ..") : "Get OTP", - hint: "admin@mail.com", + hint: "teja-finder@aaa.movie", isActive: _stepNumber == 3 && (!sendOtpSuccess), isOperationAllowedButNotActive: _stepNumber > 3, buttonClickHandler: () { @@ -369,6 +373,7 @@ String? genericFieldValidator(String? value) { class SignupForm extends StatefulWidget { final String stepNumber; final String fieldLabel; + final String supportLabel; final String? buttonLabel; final String hint; final bool isActive; @@ -384,6 +389,7 @@ class SignupForm extends StatefulWidget { const SignupForm({ required this.stepNumber, required this.fieldLabel, + required this.supportLabel, this.buttonLabel, required this.hint, required this.isActive, @@ -416,6 +422,7 @@ class SignupFormState extends State { child: Column( children: [ renderInputLabel(), + renderSupportLabel(text: widget.supportLabel), renderTextField(), Visibility( visible: widget.buttonVisible,