Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package govoyage;
- import java.io.DataInputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import javax.microedition.io.Connector;
- import javax.microedition.io.HttpConnection;
- import javax.microedition.lcdui.Command;
- import javax.microedition.lcdui.CommandListener;
- import javax.microedition.lcdui.Display;
- import javax.microedition.lcdui.Displayable;
- import javax.microedition.lcdui.Form;
- import javax.microedition.lcdui.StringItem;
- import javax.microedition.lcdui.TextField;
- import javax.microedition.midlet.*;
- /**
- * @author khlifi
- */
- public class Midlet extends MIDlet implements CommandListener {
- Display disp = Display.getDisplay(this);
- Form AccueilForm = new Form("Welcome to GoVoyage");
- Command Connecte = new Command("Connecte", Command.OK, 0);
- Command Inscrire = new Command("Inscrire", Command.OK, 0);
- //Authentification stuff
- Form AuthentificationForm = new Form("Authentification");
- TextField name = new TextField("name :", null, 50, TextField.ANY);
- TextField password = new TextField("password :", null, 50, TextField.PASSWORD);
- Command cnx = new Command("connexion", Command.OK, 0);
- //Inscription stuff
- Form InscriptionForm = new Form("Authentification");
- TextField InscriptionName = new TextField("Nom Utlisateur :", null, 50, TextField.ANY);
- TextField InscriptionMail = new TextField("Adresse email :", null, 50, TextField.ANY);
- TextField InscriptionPassword = new TextField("Mot de passe :", null, 50, TextField.PASSWORD);
- TextField InscriptionPassword2 = new TextField("Rétapez Mot de passe :", null, 50, TextField.PASSWORD);
- Command inscrire = new Command("S'inscrire", Command.OK, 0);
- //Dashboard stuff
- /* Form InscriptionForm = new Form("Authentification");
- TextField InscriptionName = new TextField("Nom Utlisateur :", null, 50, TextField.ANY);
- TextField InscriptionMail = new TextField("Adresse email :", null, 50, TextField.ANY);
- TextField InscriptionPassword = new TextField("Mot de passe :", null, 50, TextField.PASSWORD);
- TextField InscriptionPassword2 = new TextField("Rétapez Mot de passe :", null, 50, TextField.PASSWORD);
- Command inscrire = new Command("S'inscrire", Command.OK, 0);*/
- HttpConnection hc = null;
- InputStream in = null;
- OutputStream out = null;
- public void startApp() {
- AccueilForm.addCommand(Connecte);
- AccueilForm.setCommandListener((CommandListener) this);
- AccueilForm.addCommand(Inscrire);
- disp.setCurrent(AccueilForm);
- }
- public void pauseApp() {
- }
- public void destroyApp(boolean unconditional) {
- }
- public void commandAction(Command c, Displayable d) {
- if (c == Connecte) {
- AuthentificationForm.append(name);
- AuthentificationForm.append(password);
- AuthentificationForm.addCommand(cnx);
- AuthentificationForm.setCommandListener((CommandListener) this);
- disp.setCurrent(AuthentificationForm);
- }
- if (c == Inscrire) {
- InscriptionForm.append(InscriptionName);
- InscriptionForm.append(InscriptionMail);
- InscriptionForm.append(InscriptionPassword);
- InscriptionForm.append(InscriptionPassword2);
- InscriptionForm.addCommand(inscrire);
- InscriptionForm.setCommandListener((CommandListener) this);
- disp.setCurrent(InscriptionForm);
- }
- if (c == cnx) {
- Authentification();
- }
- if (c == inscrire) {
- Inscription();
- }
- }
- public void Authentification() {
- try {
- String message = "username=" + name.getString().trim() + "&password=" + password.getString().trim();
- String url = "http://localhost/GoVoyage/web/app_dev.php/loginJME";
- hc = (HttpConnection) Connector.open(url);
- hc.setRequestMethod(HttpConnection.POST);
- hc.setRequestProperty("Content-Type",
- "application/x-www-form-urlencoded");
- hc.setRequestProperty("Content-Length",
- Integer.toString(message.length()));
- out = hc.openOutputStream();
- out.write(message.getBytes());
- in = hc.openInputStream();
- int length = (int) hc.getLength();
- byte[] data = new byte[length];
- in.read(data);
- String response = new String(data);
- StringItem stringItem = new StringItem(null, response);
- AuthentificationForm.append(stringItem);
- AuthentificationForm.setTitle("Done.");
- } catch (IOException ioe) {
- StringItem stringItem = new StringItem(null, ioe.toString());
- AuthentificationForm.append(stringItem);
- AuthentificationForm.setTitle("Done.");
- } finally {
- try {
- if (out != null) {
- out.close();
- }
- if (in != null) {
- in.close();
- }
- if (hc != null) {
- hc.close();
- }
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
- }
- public void Inscription() {
- try {
- String message = "fos_user_registration_form[username]=" + InscriptionName.getString().trim() + "&fos_user_registration_form[plainPassword][first]=" + InscriptionPassword.getString().trim() + "&fos_user_registration_form[plainPassword][second]=" + InscriptionPassword.getString().trim() + "&fos_user_registration_form[email]=" + InscriptionMail.getString().trim();
- String url = "http://localhost/GoVoyage/web/app_dev.php/register/";
- hc = (HttpConnection) Connector.open(url);
- hc.setRequestMethod(HttpConnection.POST);
- hc.setRequestProperty("Content-Type",
- "application/x-www-form-urlencoded");
- hc.setRequestProperty("Content-Length",
- Integer.toString(message.length()));
- out = hc.openOutputStream();
- out.write(message.getBytes());
- in = hc.openInputStream();
- int length = (int) hc.getLength();
- byte[] data = new byte[length];
- in.read(data);
- String response = new String(data);
- StringItem stringItem = new StringItem(null, response);
- AuthentificationForm.append(stringItem);
- AuthentificationForm.setTitle("Done.");
- } catch (IOException ioe) {
- StringItem stringItem = new StringItem(null, ioe.toString());
- AuthentificationForm.append(stringItem);
- AuthentificationForm.setTitle("Done.");
- } finally {
- try {
- if (out != null) {
- out.close();
- }
- if (in != null) {
- in.close();
- }
- if (hc != null) {
- hc.close();
- }
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement