SlideShare a Scribd company logo
1 of 13
Download to read offline
Creating an Uber Clone - Part XXXIV
App Id
© Codename One 2017 all rights reserved
facebook.addActionListener(e -> {
final Login fb = FacebookConnect.getInstance();
if(UberClone.isDriverMode()) {
fb.setClientId("value for driver app");
fb.setClientSecret("value for driver app");
} else {
fb.setClientId("value for user app");
fb.setClientSecret("value for user app");
}
fb.setRedirectURI("https://www.codenameone.com/");
fb.setCallback(new LoginCallback() {
@Override
public void loginFailed(String errorMessage) {
ToastBar.showErrorMessage("Login failed: " + errorMessage);
}
@Override
public void loginSuccessful() {
String token = fb.getAccessToken().getToken();
new EnterPasswordForm(null, token, null).show();
}
});
fb.doLogin();
});
FacebookOrGoogleLoginForm
facebook.addActionListener(e -> {
final Login fb = FacebookConnect.getInstance();
if(UberClone.isDriverMode()) {
fb.setClientId("value for driver app");
fb.setClientSecret("value for driver app");
} else {
fb.setClientId("value for user app");
fb.setClientSecret("value for user app");
}
fb.setRedirectURI("https://www.codenameone.com/");
fb.setCallback(new LoginCallback() {
@Override
public void loginFailed(String errorMessage) {
ToastBar.showErrorMessage("Login failed: " + errorMessage);
}
@Override
public void loginSuccessful() {
String token = fb.getAccessToken().getToken();
new EnterPasswordForm(null, token, null).show();
}
});
fb.doLogin();
});
FacebookOrGoogleLoginForm
facebook.addActionListener(e -> {
final Login fb = FacebookConnect.getInstance();
if(UberClone.isDriverMode()) {
fb.setClientId("value for driver app");
fb.setClientSecret("value for driver app");
} else {
fb.setClientId("value for user app");
fb.setClientSecret("value for user app");
}
fb.setRedirectURI("https://www.codenameone.com/");
fb.setCallback(new LoginCallback() {
@Override
public void loginFailed(String errorMessage) {
ToastBar.showErrorMessage("Login failed: " + errorMessage);
}
@Override
public void loginSuccessful() {
String token = fb.getAccessToken().getToken();
new EnterPasswordForm(null, token, null).show();
}
});
fb.doLogin();
});
FacebookOrGoogleLoginForm
facebook.addActionListener(e -> {
final Login fb = FacebookConnect.getInstance();
if(UberClone.isDriverMode()) {
fb.setClientId("value for driver app");
fb.setClientSecret("value for driver app");
} else {
fb.setClientId("value for user app");
fb.setClientSecret("value for user app");
}
fb.setRedirectURI("https://www.codenameone.com/");
fb.setCallback(new LoginCallback() {
@Override
public void loginFailed(String errorMessage) {
ToastBar.showErrorMessage("Login failed: " + errorMessage);
}
@Override
public void loginSuccessful() {
String token = fb.getAccessToken().getToken();
new EnterPasswordForm(null, token, null).show();
}
});
fb.doLogin();
});
FacebookOrGoogleLoginForm
public EnterPasswordForm(String phoneNumber, String facebookId, String googleId) {
super(new BorderLayout());
Form previous = getCurrentForm();
InfiniteProgress ip = new InfiniteProgress();
Dialog dlg = ip.showInifiniteBlocking();
boolean exists = UserService.userExists(phoneNumber, facebookId, googleId);
// same code as before snipped...
fab.addActionListener(e -> {
Dialog ipDlg = new InfiniteProgress().showInifiniteBlocking();
if(exists) {
UserService.login(phoneNumber, facebookId, googleId, password.getText(), (value) -> {
MapForm.get().show();
}, (sender, err, errorCode, errorMessage) -> {
ipDlg.dispose();
error.setText("Login error");
error.setVisible(true);
revalidate();
});
} else {
if(UserService.addNewUser(new User().
phone.set(phoneNumber).
facebookId.set(facebookId).
googleId.set(googleId).
password.set(password.getText()).
driver.set(UberClone.isDriverMode()))) {
MapForm.get().show();
} else {
EnterPasswordForm
public EnterPasswordForm(String phoneNumber, String facebookId, String googleId) {
super(new BorderLayout());
Form previous = getCurrentForm();
InfiniteProgress ip = new InfiniteProgress();
Dialog dlg = ip.showInifiniteBlocking();
boolean exists = UserService.userExists(phoneNumber, facebookId, googleId);
// same code as before snipped...
fab.addActionListener(e -> {
Dialog ipDlg = new InfiniteProgress().showInifiniteBlocking();
if(exists) {
UserService.login(phoneNumber, facebookId, googleId, password.getText(), (value) -> {
MapForm.get().show();
}, (sender, err, errorCode, errorMessage) -> {
ipDlg.dispose();
error.setText("Login error");
error.setVisible(true);
revalidate();
});
} else {
if(UserService.addNewUser(new User().
phone.set(phoneNumber).
facebookId.set(facebookId).
googleId.set(googleId).
password.set(password.getText()).
driver.set(UberClone.isDriverMode()))) {
MapForm.get().show();
} else {
EnterPasswordForm
public EnterPasswordForm(String phoneNumber, String facebookId, String googleId) {
super(new BorderLayout());
Form previous = getCurrentForm();
InfiniteProgress ip = new InfiniteProgress();
Dialog dlg = ip.showInifiniteBlocking();
boolean exists = UserService.userExists(phoneNumber, facebookId, googleId);
// same code as before snipped...
fab.addActionListener(e -> {
Dialog ipDlg = new InfiniteProgress().showInifiniteBlocking();
if(exists) {
UserService.login(phoneNumber, facebookId, googleId, password.getText(), (value) -> {
MapForm.get().show();
}, (sender, err, errorCode, errorMessage) -> {
ipDlg.dispose();
error.setText("Login error");
error.setVisible(true);
revalidate();
});
} else {
if(UserService.addNewUser(new User().
phone.set(phoneNumber).
facebookId.set(facebookId).
googleId.set(googleId).
password.set(password.getText()).
driver.set(UberClone.isDriverMode()))) {
MapForm.get().show();
} else {
EnterPasswordForm
public EnterPasswordForm(String phoneNumber, String facebookId, String googleId) {
super(new BorderLayout());
Form previous = getCurrentForm();
InfiniteProgress ip = new InfiniteProgress();
Dialog dlg = ip.showInifiniteBlocking();
boolean exists = UserService.userExists(phoneNumber, facebookId, googleId);
// same code as before snipped...
fab.addActionListener(e -> {
Dialog ipDlg = new InfiniteProgress().showInifiniteBlocking();
if(exists) {
UserService.login(phoneNumber, facebookId, googleId, password.getText(), (value) -> {
MapForm.get().show();
}, (sender, err, errorCode, errorMessage) -> {
ipDlg.dispose();
error.setText("Login error");
error.setVisible(true);
revalidate();
});
} else {
if(UserService.addNewUser(new User().
phone.set(phoneNumber).
facebookId.set(facebookId).
googleId.set(googleId).
password.set(password.getText()).
driver.set(UberClone.isDriverMode()))) {
MapForm.get().show();
} else {
EnterPasswordForm
public static boolean userExists(String phoneNumber, String facebookId, String googleId) {
if(phoneNumber != null) {
return userExistsPhone(phoneNumber);
}
if(facebookId != null) {
return userExistsFacebook(facebookId);
}
return userExistsGoogle(googleId);
}
public static boolean userExistsPhone(String phoneNumber) {
return userExistsImpl("user/exists", phoneNumber);
}
public static boolean userExistsFacebook(String phoneNumber) {
return userExistsImpl("user/existsFacebook", phoneNumber);
}
public static boolean userExistsGoogle(String phoneNumber) {
return userExistsImpl("user/existsGoogle", phoneNumber);
}
private static boolean userExistsImpl(String url, String val) {
Response<byte[]> b = Rest.get(SERVER_URL + url).
acceptJson().
queryParam("v", val).getAsBytes();
if(b.getResponseCode() == 200) {
// the t from true
return b.getResponseData()[0] == (byte)'t';
}
return false;
UserService
public static boolean userExists(String phoneNumber, String facebookId, String googleId) {
if(phoneNumber != null) {
return userExistsPhone(phoneNumber);
}
if(facebookId != null) {
return userExistsFacebook(facebookId);
}
return userExistsGoogle(googleId);
}
public static boolean userExistsPhone(String phoneNumber) {
return userExistsImpl("user/exists", phoneNumber);
}
public static boolean userExistsFacebook(String phoneNumber) {
return userExistsImpl("user/existsFacebook", phoneNumber);
}
public static boolean userExistsGoogle(String phoneNumber) {
return userExistsImpl("user/existsGoogle", phoneNumber);
}
private static boolean userExistsImpl(String url, String val) {
Response<byte[]> b = Rest.get(SERVER_URL + url).
acceptJson().
queryParam("v", val).getAsBytes();
if(b.getResponseCode() == 200) {
// the t from true
return b.getResponseData()[0] == (byte)'t';
}
return false;
UserService
return userExistsImpl("user/existsFacebook", phoneNumber);
}
public static boolean userExistsGoogle(String phoneNumber) {
return userExistsImpl("user/existsGoogle", phoneNumber);
}
private static boolean userExistsImpl(String url, String val) {
Response<byte[]> b = Rest.get(SERVER_URL + url).
acceptJson().
queryParam("v", val).getAsBytes();
if(b.getResponseCode() == 200) {
// the t from true
return b.getResponseData()[0] == (byte)'t';
}
return false;
}
public static void login(String phoneNumber, String facebookId, String googleId, String password,
final SuccessCallback<User> onSuccess, final FailureCallback<Object> onError) {
Rest.get(SERVER_URL + "user/login").
acceptJson().
queryParam("password", password).
queryParam("phone", phoneNumber).
queryParam("facebookId", facebookId).
queryParam("googleId", googleId).
getAsJsonMapAsync(new Callback<Response<Map>>() {
// this code was unchanged
});
}
UserService

More Related Content

Similar to Creating an Uber Clone - Part XXXIV.pdf

Creating a Facebook Clone - Part XLVI - Transcript.pdf
Creating a Facebook Clone - Part XLVI - Transcript.pdfCreating a Facebook Clone - Part XLVI - Transcript.pdf
Creating a Facebook Clone - Part XLVI - Transcript.pdfShaiAlmog1
 
Creating a Facebook Clone - Part XXVIII - Transcript.pdf
Creating a Facebook Clone - Part XXVIII - Transcript.pdfCreating a Facebook Clone - Part XXVIII - Transcript.pdf
Creating a Facebook Clone - Part XXVIII - Transcript.pdfShaiAlmog1
 
Creating a Facebook Clone - Part XLVI.pdf
Creating a Facebook Clone - Part XLVI.pdfCreating a Facebook Clone - Part XLVI.pdf
Creating a Facebook Clone - Part XLVI.pdfShaiAlmog1
 
Creating a Facebook Clone - Part XLV.pdf
Creating a Facebook Clone - Part XLV.pdfCreating a Facebook Clone - Part XLV.pdf
Creating a Facebook Clone - Part XLV.pdfShaiAlmog1
 
Creating an Uber Clone - Part XIV.pdf
Creating an Uber Clone - Part XIV.pdfCreating an Uber Clone - Part XIV.pdf
Creating an Uber Clone - Part XIV.pdfShaiAlmog1
 
Android Testing
Android TestingAndroid Testing
Android TestingEvan Lin
 
Creating a Whatsapp Clone - Part XIV - Transcript.pdf
Creating a Whatsapp Clone - Part XIV - Transcript.pdfCreating a Whatsapp Clone - Part XIV - Transcript.pdf
Creating a Whatsapp Clone - Part XIV - Transcript.pdfShaiAlmog1
 
Testando API's de forma unitária mocando as dependências
Testando API's de forma unitária mocando as dependênciasTestando API's de forma unitária mocando as dependências
Testando API's de forma unitária mocando as dependênciasMarcelo Aymone
 
WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015Fernando Daciuk
 
Symfony CoP: Form component
Symfony CoP: Form componentSymfony CoP: Form component
Symfony CoP: Form componentSamuel ROZE
 
Creating a Facebook Clone - Part XXVIII.pdf
Creating a Facebook Clone - Part XXVIII.pdfCreating a Facebook Clone - Part XXVIII.pdf
Creating a Facebook Clone - Part XXVIII.pdfShaiAlmog1
 
Creating a Facebook Clone - Part X - Transcript.pdf
Creating a Facebook Clone - Part X - Transcript.pdfCreating a Facebook Clone - Part X - Transcript.pdf
Creating a Facebook Clone - Part X - Transcript.pdfShaiAlmog1
 
Data Binding: Is It the Next Big Thing?
Data Binding: Is It the Next Big Thing?Data Binding: Is It the Next Big Thing?
Data Binding: Is It the Next Big Thing?GlobalLogic Ukraine
 
Cnam azure 2014 mobile services
Cnam azure 2014   mobile servicesCnam azure 2014   mobile services
Cnam azure 2014 mobile servicesAymeric Weinbach
 
codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docx
codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docxcodeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docx
codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docxmonicafrancis71118
 
Adapting to Tablets and Desktops - Part 1.pdf
Adapting to Tablets and Desktops - Part 1.pdfAdapting to Tablets and Desktops - Part 1.pdf
Adapting to Tablets and Desktops - Part 1.pdfShaiAlmog1
 

Similar to Creating an Uber Clone - Part XXXIV.pdf (20)

Creating a Facebook Clone - Part XLVI - Transcript.pdf
Creating a Facebook Clone - Part XLVI - Transcript.pdfCreating a Facebook Clone - Part XLVI - Transcript.pdf
Creating a Facebook Clone - Part XLVI - Transcript.pdf
 
Creating a Facebook Clone - Part XXVIII - Transcript.pdf
Creating a Facebook Clone - Part XXVIII - Transcript.pdfCreating a Facebook Clone - Part XXVIII - Transcript.pdf
Creating a Facebook Clone - Part XXVIII - Transcript.pdf
 
Creating a Facebook Clone - Part XLVI.pdf
Creating a Facebook Clone - Part XLVI.pdfCreating a Facebook Clone - Part XLVI.pdf
Creating a Facebook Clone - Part XLVI.pdf
 
Creating a Facebook Clone - Part XLV.pdf
Creating a Facebook Clone - Part XLV.pdfCreating a Facebook Clone - Part XLV.pdf
Creating a Facebook Clone - Part XLV.pdf
 
Creating an Uber Clone - Part XIV.pdf
Creating an Uber Clone - Part XIV.pdfCreating an Uber Clone - Part XIV.pdf
Creating an Uber Clone - Part XIV.pdf
 
Android Testing
Android TestingAndroid Testing
Android Testing
 
Creating a Whatsapp Clone - Part XIV - Transcript.pdf
Creating a Whatsapp Clone - Part XIV - Transcript.pdfCreating a Whatsapp Clone - Part XIV - Transcript.pdf
Creating a Whatsapp Clone - Part XIV - Transcript.pdf
 
Testando API's de forma unitária mocando as dependências
Testando API's de forma unitária mocando as dependênciasTestando API's de forma unitária mocando as dependências
Testando API's de forma unitária mocando as dependências
 
WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015
 
Clean Javascript
Clean JavascriptClean Javascript
Clean Javascript
 
Symfony CoP: Form component
Symfony CoP: Form componentSymfony CoP: Form component
Symfony CoP: Form component
 
Creating a Facebook Clone - Part XXVIII.pdf
Creating a Facebook Clone - Part XXVIII.pdfCreating a Facebook Clone - Part XXVIII.pdf
Creating a Facebook Clone - Part XXVIII.pdf
 
Creating a Facebook Clone - Part X - Transcript.pdf
Creating a Facebook Clone - Part X - Transcript.pdfCreating a Facebook Clone - Part X - Transcript.pdf
Creating a Facebook Clone - Part X - Transcript.pdf
 
Data Binding: Is It the Next Big Thing?
Data Binding: Is It the Next Big Thing?Data Binding: Is It the Next Big Thing?
Data Binding: Is It the Next Big Thing?
 
Road to Async Nirvana
Road to Async NirvanaRoad to Async Nirvana
Road to Async Nirvana
 
Cnam azure 2014 mobile services
Cnam azure 2014   mobile servicesCnam azure 2014   mobile services
Cnam azure 2014 mobile services
 
Symfony tips and tricks
Symfony tips and tricksSymfony tips and tricks
Symfony tips and tricks
 
codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docx
codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docxcodeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docx
codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docx
 
Adapting to Tablets and Desktops - Part 1.pdf
Adapting to Tablets and Desktops - Part 1.pdfAdapting to Tablets and Desktops - Part 1.pdf
Adapting to Tablets and Desktops - Part 1.pdf
 
Vaadin7
Vaadin7Vaadin7
Vaadin7
 

More from ShaiAlmog1

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...ShaiAlmog1
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfShaiAlmog1
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfShaiAlmog1
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfShaiAlmog1
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfShaiAlmog1
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfShaiAlmog1
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfShaiAlmog1
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfShaiAlmog1
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfShaiAlmog1
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfShaiAlmog1
 
create-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfcreate-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfShaiAlmog1
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfShaiAlmog1
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfCreating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfShaiAlmog1
 

More from ShaiAlmog1 (20)

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdf
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdf
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdf
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdf
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdf
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdf
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdf
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdf
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdf
 
create-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfcreate-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdf
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdf
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdf
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdf
 
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdf
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdf
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfCreating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdf
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdf
 

Recently uploaded

Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data SciencePaolo Missier
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTopCSSGallery
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGDSC PJATK
 
Vector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxVector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxjbellis
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform EngineeringMarcus Vechiato
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc
 
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxCyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxMasterG
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimaginedpanagenda
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxFIDO Alliance
 
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdfFrisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdfAnubhavMangla3
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsLeah Henrickson
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityVictorSzoltysek
 
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)Paige Cruz
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...ScyllaDB
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...ScyllaDB
 
CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)Wonjun Hwang
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024Lorenzo Miniero
 

Recently uploaded (20)

Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development Companies
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Vector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxVector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptx
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxCyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdfFrisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
 
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 

Creating an Uber Clone - Part XXXIV.pdf

  • 1. Creating an Uber Clone - Part XXXIV
  • 2. App Id © Codename One 2017 all rights reserved
  • 3. facebook.addActionListener(e -> { final Login fb = FacebookConnect.getInstance(); if(UberClone.isDriverMode()) { fb.setClientId("value for driver app"); fb.setClientSecret("value for driver app"); } else { fb.setClientId("value for user app"); fb.setClientSecret("value for user app"); } fb.setRedirectURI("https://www.codenameone.com/"); fb.setCallback(new LoginCallback() { @Override public void loginFailed(String errorMessage) { ToastBar.showErrorMessage("Login failed: " + errorMessage); } @Override public void loginSuccessful() { String token = fb.getAccessToken().getToken(); new EnterPasswordForm(null, token, null).show(); } }); fb.doLogin(); }); FacebookOrGoogleLoginForm
  • 4. facebook.addActionListener(e -> { final Login fb = FacebookConnect.getInstance(); if(UberClone.isDriverMode()) { fb.setClientId("value for driver app"); fb.setClientSecret("value for driver app"); } else { fb.setClientId("value for user app"); fb.setClientSecret("value for user app"); } fb.setRedirectURI("https://www.codenameone.com/"); fb.setCallback(new LoginCallback() { @Override public void loginFailed(String errorMessage) { ToastBar.showErrorMessage("Login failed: " + errorMessage); } @Override public void loginSuccessful() { String token = fb.getAccessToken().getToken(); new EnterPasswordForm(null, token, null).show(); } }); fb.doLogin(); }); FacebookOrGoogleLoginForm
  • 5. facebook.addActionListener(e -> { final Login fb = FacebookConnect.getInstance(); if(UberClone.isDriverMode()) { fb.setClientId("value for driver app"); fb.setClientSecret("value for driver app"); } else { fb.setClientId("value for user app"); fb.setClientSecret("value for user app"); } fb.setRedirectURI("https://www.codenameone.com/"); fb.setCallback(new LoginCallback() { @Override public void loginFailed(String errorMessage) { ToastBar.showErrorMessage("Login failed: " + errorMessage); } @Override public void loginSuccessful() { String token = fb.getAccessToken().getToken(); new EnterPasswordForm(null, token, null).show(); } }); fb.doLogin(); }); FacebookOrGoogleLoginForm
  • 6. facebook.addActionListener(e -> { final Login fb = FacebookConnect.getInstance(); if(UberClone.isDriverMode()) { fb.setClientId("value for driver app"); fb.setClientSecret("value for driver app"); } else { fb.setClientId("value for user app"); fb.setClientSecret("value for user app"); } fb.setRedirectURI("https://www.codenameone.com/"); fb.setCallback(new LoginCallback() { @Override public void loginFailed(String errorMessage) { ToastBar.showErrorMessage("Login failed: " + errorMessage); } @Override public void loginSuccessful() { String token = fb.getAccessToken().getToken(); new EnterPasswordForm(null, token, null).show(); } }); fb.doLogin(); }); FacebookOrGoogleLoginForm
  • 7. public EnterPasswordForm(String phoneNumber, String facebookId, String googleId) { super(new BorderLayout()); Form previous = getCurrentForm(); InfiniteProgress ip = new InfiniteProgress(); Dialog dlg = ip.showInifiniteBlocking(); boolean exists = UserService.userExists(phoneNumber, facebookId, googleId); // same code as before snipped... fab.addActionListener(e -> { Dialog ipDlg = new InfiniteProgress().showInifiniteBlocking(); if(exists) { UserService.login(phoneNumber, facebookId, googleId, password.getText(), (value) -> { MapForm.get().show(); }, (sender, err, errorCode, errorMessage) -> { ipDlg.dispose(); error.setText("Login error"); error.setVisible(true); revalidate(); }); } else { if(UserService.addNewUser(new User(). phone.set(phoneNumber). facebookId.set(facebookId). googleId.set(googleId). password.set(password.getText()). driver.set(UberClone.isDriverMode()))) { MapForm.get().show(); } else { EnterPasswordForm
  • 8. public EnterPasswordForm(String phoneNumber, String facebookId, String googleId) { super(new BorderLayout()); Form previous = getCurrentForm(); InfiniteProgress ip = new InfiniteProgress(); Dialog dlg = ip.showInifiniteBlocking(); boolean exists = UserService.userExists(phoneNumber, facebookId, googleId); // same code as before snipped... fab.addActionListener(e -> { Dialog ipDlg = new InfiniteProgress().showInifiniteBlocking(); if(exists) { UserService.login(phoneNumber, facebookId, googleId, password.getText(), (value) -> { MapForm.get().show(); }, (sender, err, errorCode, errorMessage) -> { ipDlg.dispose(); error.setText("Login error"); error.setVisible(true); revalidate(); }); } else { if(UserService.addNewUser(new User(). phone.set(phoneNumber). facebookId.set(facebookId). googleId.set(googleId). password.set(password.getText()). driver.set(UberClone.isDriverMode()))) { MapForm.get().show(); } else { EnterPasswordForm
  • 9. public EnterPasswordForm(String phoneNumber, String facebookId, String googleId) { super(new BorderLayout()); Form previous = getCurrentForm(); InfiniteProgress ip = new InfiniteProgress(); Dialog dlg = ip.showInifiniteBlocking(); boolean exists = UserService.userExists(phoneNumber, facebookId, googleId); // same code as before snipped... fab.addActionListener(e -> { Dialog ipDlg = new InfiniteProgress().showInifiniteBlocking(); if(exists) { UserService.login(phoneNumber, facebookId, googleId, password.getText(), (value) -> { MapForm.get().show(); }, (sender, err, errorCode, errorMessage) -> { ipDlg.dispose(); error.setText("Login error"); error.setVisible(true); revalidate(); }); } else { if(UserService.addNewUser(new User(). phone.set(phoneNumber). facebookId.set(facebookId). googleId.set(googleId). password.set(password.getText()). driver.set(UberClone.isDriverMode()))) { MapForm.get().show(); } else { EnterPasswordForm
  • 10. public EnterPasswordForm(String phoneNumber, String facebookId, String googleId) { super(new BorderLayout()); Form previous = getCurrentForm(); InfiniteProgress ip = new InfiniteProgress(); Dialog dlg = ip.showInifiniteBlocking(); boolean exists = UserService.userExists(phoneNumber, facebookId, googleId); // same code as before snipped... fab.addActionListener(e -> { Dialog ipDlg = new InfiniteProgress().showInifiniteBlocking(); if(exists) { UserService.login(phoneNumber, facebookId, googleId, password.getText(), (value) -> { MapForm.get().show(); }, (sender, err, errorCode, errorMessage) -> { ipDlg.dispose(); error.setText("Login error"); error.setVisible(true); revalidate(); }); } else { if(UserService.addNewUser(new User(). phone.set(phoneNumber). facebookId.set(facebookId). googleId.set(googleId). password.set(password.getText()). driver.set(UberClone.isDriverMode()))) { MapForm.get().show(); } else { EnterPasswordForm
  • 11. public static boolean userExists(String phoneNumber, String facebookId, String googleId) { if(phoneNumber != null) { return userExistsPhone(phoneNumber); } if(facebookId != null) { return userExistsFacebook(facebookId); } return userExistsGoogle(googleId); } public static boolean userExistsPhone(String phoneNumber) { return userExistsImpl("user/exists", phoneNumber); } public static boolean userExistsFacebook(String phoneNumber) { return userExistsImpl("user/existsFacebook", phoneNumber); } public static boolean userExistsGoogle(String phoneNumber) { return userExistsImpl("user/existsGoogle", phoneNumber); } private static boolean userExistsImpl(String url, String val) { Response<byte[]> b = Rest.get(SERVER_URL + url). acceptJson(). queryParam("v", val).getAsBytes(); if(b.getResponseCode() == 200) { // the t from true return b.getResponseData()[0] == (byte)'t'; } return false; UserService
  • 12. public static boolean userExists(String phoneNumber, String facebookId, String googleId) { if(phoneNumber != null) { return userExistsPhone(phoneNumber); } if(facebookId != null) { return userExistsFacebook(facebookId); } return userExistsGoogle(googleId); } public static boolean userExistsPhone(String phoneNumber) { return userExistsImpl("user/exists", phoneNumber); } public static boolean userExistsFacebook(String phoneNumber) { return userExistsImpl("user/existsFacebook", phoneNumber); } public static boolean userExistsGoogle(String phoneNumber) { return userExistsImpl("user/existsGoogle", phoneNumber); } private static boolean userExistsImpl(String url, String val) { Response<byte[]> b = Rest.get(SERVER_URL + url). acceptJson(). queryParam("v", val).getAsBytes(); if(b.getResponseCode() == 200) { // the t from true return b.getResponseData()[0] == (byte)'t'; } return false; UserService
  • 13. return userExistsImpl("user/existsFacebook", phoneNumber); } public static boolean userExistsGoogle(String phoneNumber) { return userExistsImpl("user/existsGoogle", phoneNumber); } private static boolean userExistsImpl(String url, String val) { Response<byte[]> b = Rest.get(SERVER_URL + url). acceptJson(). queryParam("v", val).getAsBytes(); if(b.getResponseCode() == 200) { // the t from true return b.getResponseData()[0] == (byte)'t'; } return false; } public static void login(String phoneNumber, String facebookId, String googleId, String password, final SuccessCallback<User> onSuccess, final FailureCallback<Object> onError) { Rest.get(SERVER_URL + "user/login"). acceptJson(). queryParam("password", password). queryParam("phone", phoneNumber). queryParam("facebookId", facebookId). queryParam("googleId", googleId). getAsJsonMapAsync(new Callback<Response<Map>>() { // this code was unchanged }); } UserService