Skip to content

Commit

Permalink
Add sign up arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Thesmader committed Apr 26, 2020
1 parent df01545 commit 92f6097
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 25 deletions.
6 changes: 6 additions & 0 deletions gogrocy/lib/core/models/sign_up_arguments.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class SignUpArguments{
String mobile;
String countryCode;

SignUpArguments(this.mobile, this.countryCode);
}
18 changes: 11 additions & 7 deletions gogrocy/lib/core/services/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import 'package:gogrocy/service_locator.dart';
import 'package:http/http.dart' as http;

const String baseUrl = "https://gogrocy.in/api/";
const String TOKEN='eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpYXQiOjE1ODY5NzYxMjEsImlzcyI6Imh0dHBzOlwvXC9nb2dyb2N5LmluXC8iLCJuYmYiOjE1ODY5NzYxMzEsImRhdGEiOnsidXNlcl9pZCI6Ijg1IiwidXNlcl9yb2xlIjoiMSJ9fQ.3jwji_K1l07ttdUUjn4UJbJfuAbrC0msqk7jeftpSzDR7u2d8RCiGWz3ritX3hQIa0MGUe2fIaidErX-xtTQdA';
const String TOKEN =
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpYXQiOjE1ODY5NzYxMjEsImlzcyI6Imh0dHBzOlwvXC9nb2dyb2N5LmluXC8iLCJuYmYiOjE1ODY5NzYxMzEsImRhdGEiOnsidXNlcl9pZCI6Ijg1IiwidXNlcl9yb2xlIjoiMSJ9fQ.3jwji_K1l07ttdUUjn4UJbJfuAbrC0msqk7jeftpSzDR7u2d8RCiGWz3ritX3hQIa0MGUe2fIaidErX-xtTQdA';

const String allProducts = baseUrl + "getProducts";
const String singleProduct = baseUrl + "getProduct";
Expand All @@ -20,7 +21,7 @@ const String login = baseUrl + "login";
const String signUp = baseUrl + "signup";
const String verifyUser = baseUrl + "verifyUser";
const String addAddress = baseUrl + "add_address";
const String cartList=baseUrl+'getCartItems';
const String cartList = baseUrl + 'getCartItems';

class Apis {
final SharedPrefsService _sharedPrefsService = locator<SharedPrefsService>();
Expand Down Expand Up @@ -49,6 +50,7 @@ class Apis {
"country": "India",
};
print(body);
print("ADDDRESSSSSS " + jwt);
http.Response result = await http.post(addAddress,
headers: {HttpHeaders.authorizationHeader: "Bearer $jwt"}, body: body);
print(result.body);
Expand Down Expand Up @@ -84,6 +86,7 @@ class Apis {
mobile: mobile, countryCode: countryCode, password: password);
print("login via sign up success");
if (user.jwt != null) {
print("LOGIN " + user.jwt);
await verifyUserApi(user.jwt);
await addAddressApi(
name: name,
Expand Down Expand Up @@ -122,6 +125,7 @@ class Apis {
return user;
}
}

Future<List<Product>> getAllProducts() async {
var client = new http.Client();
bool connectionState = await checkStatus();
Expand All @@ -144,8 +148,8 @@ class Apis {
var client = new http.Client();
bool connectionState = await checkStatus();
if (connectionState) //TODO: Add a proper else return
{
var response = await client.post(cartList,headers: {
{
var response = await client.post(cartList, headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer $TOKEN',
Expand All @@ -172,10 +176,10 @@ class Apis {
Future<bool> verifyUserApi(String jwt) async {
http.Response result = await http.post(verifyUser,
headers: {HttpHeaders.authorizationHeader: "Bearer $jwt"});
if ((json.decode(result.body))["success"]){
if ((json.decode(result.body))["success"]) {
print("VERIFIED USER");
return true;}
else
return true;
} else
return false;
}
}
6 changes: 2 additions & 4 deletions gogrocy/lib/core/services/authentication_service.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart';
import 'package:gogrocy/core/models/sign_up_arguments.dart';
import 'package:gogrocy/core/services/navigation_service.dart';
import 'package:gogrocy/core/services/shared_prefs.dart';
import 'package:gogrocy/service_locator.dart';
Expand All @@ -17,10 +18,7 @@ class AuthenticationService {
print('Verification Complete');
await signInWithNumber(context, credential);
print("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
_navigationService.navigateTo('awesome', arguments:{
"phoneNumber": phoneNumber,
"countryCode": countryCode
});
_navigationService.navigateTo('awesome', arguments: SignUpArguments(phoneNumber, countryCode));
};

final PhoneVerificationFailed verificationFailed =
Expand Down
6 changes: 3 additions & 3 deletions gogrocy/lib/core/services/shared_prefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ class SharedPrefsService {
}

Future<bool> hasUser() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getBool("loggedIn")??false;
}
setCartPrice(String s) async{
final SharedPreferences prefs = await SharedPreferences.getInstance();
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString("cart", s);
}

Future<String> getCartPrice() async{
final SharedPreferences prefs = await SharedPreferences.getInstance();
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getString('cart');
}

Expand Down
11 changes: 3 additions & 8 deletions gogrocy/lib/core/viewModels/login_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:gogrocy/core/enums/viewstate.dart';
import 'package:gogrocy/core/models/sign_up_arguments.dart';
import 'package:gogrocy/core/models/user.dart';
import 'package:gogrocy/core/services/api.dart';
import 'package:gogrocy/core/services/authentication_service.dart';
Expand Down Expand Up @@ -49,10 +50,7 @@ class LoginModel extends BaseModel {
if (result is bool) {
if (result) {
print('login success with phone number');
navigationService.navigateTo('awesome', arguments: {
"phoneNumber": phoneNumber,
"countryCode": countryCode
});
navigationService.navigateTo('awesome', arguments: SignUpArguments(phoneNumber, countryCode));
} else {
print('login unsuccessful with phone number');
}
Expand All @@ -76,10 +74,7 @@ class LoginModel extends BaseModel {
if (result is bool) {
if (result) {
print('login success with otp');
navigationService.navigateTo('awesome', arguments: {
"phoneNumber": phoneNumber,
"countryCode": countryCode
});
navigationService.navigateTo('awesome', arguments: SignUpArguments(phoneNumber, countryCode));
} else {
print('login unsuccessful with otp');
Scaffold.of(context).showSnackBar(
Expand Down
9 changes: 6 additions & 3 deletions gogrocy/lib/ui/router.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:gogrocy/core/models/sign_up_arguments.dart';
import 'package:gogrocy/ui/views/signup_view.dart';
import 'package:gogrocy/ui/views/home/home.dart';
import 'package:gogrocy/ui/views/landing_page.dart';
import 'package:gogrocy/ui/views/login_view.dart';

Expand All @@ -24,11 +24,14 @@ Route<dynamic> generateRoute(RouteSettings settings) {
),
);
case 'awesome':
Map<String,String> args = settings.arguments;
SignUpArguments args = settings.arguments;
return PageRouteBuilder(
pageBuilder: (BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation) {
return SignUpView(mobile: args["phoneNumber"], countryCode: args["countryCode"],);
return SignUpView(
mobile: args.mobile,
countryCode: args.countryCode,
);
},
transitionsBuilder: (BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation, Widget child) =>
Expand Down

0 comments on commit 92f6097

Please sign in to comment.