Skip to content

Commit

Permalink
Login works sans cat1
Browse files Browse the repository at this point in the history
  • Loading branch information
Thesmader committed Apr 25, 2020
1 parent cc80275 commit 0da8a98
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
39 changes: 17 additions & 22 deletions gogrocy/lib/core/services/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const String userStatus = baseUrl + "checkMobile";
const String login = baseUrl + "login";
const String signUp = baseUrl + "signup";
const String verifyUser = baseUrl + "verifyUser";
const String addAddress = baseUrl + "";
const String addAddress = baseUrl + "add_address";

class Apis {
final SharedPrefsService _sharedPrefsService = locator<SharedPrefsService>();
Expand All @@ -42,17 +42,18 @@ class Apis {
"contact": contact,
"city": city,
"zip": pinCode,
"state":"Odisha",
"country":"India",
"state": "Odisha",
"country": "India",
};
http.Response result = await http.post(addAddress,
headers: {HttpHeaders.authorizationHeader: "Bearer $jwt"}, body: body);
print(result.body);
if ((json.decode(result.body))["success"]) {
print("Add Address success");
return true;
} else
print("add address fail");
return false;
return false;
}

Future<SignUpModel> signUpApi(
Expand All @@ -77,25 +78,19 @@ class Apis {
print("signUpModel success");
var user = await loginApi(
mobile: mobile, countryCode: countryCode, password: password);
if (user.success) {
print("login via sign up success");
if(user.jwt!=null){
assert(await verifyUserApi(user.jwt), "verify user failed");
assert(
await addAddressApi(
name: name,
locality: locality,
city: city,
contact: mobile,
pinCode: zip,
jwt: user.jwt),
"add address failed");
}else{
print("JWT FAIL: ACCOUNT NOT VALIDATED");
}
print("login via sign up success");
if (user.jwt != null) {
await verifyUserApi(user.jwt);
await addAddressApi(
name: name,
locality: locality,
city: city,
contact: mobile,
pinCode: zip,
jwt: user.jwt,
);
} else {
print("login via sign up fail");
print(user.message);
print("JWT FAIL: ACCOUNT NOT VALIDATED");
}
return signUpModel;
} else {
Expand Down
2 changes: 2 additions & 0 deletions gogrocy/lib/core/services/authentication_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class AuthenticationService {
codeSent: phoneCodeSent,
codeAutoRetrievalTimeout: retrievalTimeout);
FirebaseUser currentUser = await firebaseInstance.currentUser();
print(currentUser.uid + " " + currentUser.phoneNumber);
return currentUser != null;
} catch (e) {
print(e.message);
Expand All @@ -54,6 +55,7 @@ class AuthenticationService {
(await firebaseInstance.signInWithCredential(credential)).user;
FirebaseUser currentUser = await firebaseInstance.currentUser();
assert(user.uid == currentUser.uid);
return currentUser != null;
} catch (exception) {
print(exception.message);
}
Expand Down
2 changes: 1 addition & 1 deletion gogrocy/lib/core/viewModels/login_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class LoginModel extends BaseModel {

var result = await authenticationService.signInWithOtp(
authenticationService.verificationId, otp);
//var finalNumber = countryCode + " " + phoneNumber;

setState(ViewState.Idle);

Expand Down Expand Up @@ -112,6 +111,7 @@ class LoginModel extends BaseModel {
print('Login With Password successful');
FireStoreService.addUser(
phoneNumber: phoneNumber, countryCode: countryCode);
_sharedPrefsService.setLoggedIn(true);
navigationService.navigateTo('home');
} else {
print(user.message);
Expand Down

0 comments on commit 0da8a98

Please sign in to comment.