Subversion Repositories eFlore/Applications.cel

Rev

Rev 12 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 12 Rev 33
Line 6... Line 6...
6
 */
6
 */
Line 7... Line 7...
7
 
7
 
8
import org.tela_botanica.client.CarnetEnLigneModele;
8
import org.tela_botanica.client.CarnetEnLigneModele;
Line -... Line 9...
-
 
9
import org.tela_botanica.client.interfaces.Rafraichissable;
-
 
10
 
-
 
11
import com.google.gwt.http.client.Request;
-
 
12
import com.google.gwt.http.client.RequestBuilder;
-
 
13
import com.google.gwt.http.client.RequestCallback;
9
import org.tela_botanica.client.interfaces.Rafraichissable;
14
import com.google.gwt.http.client.RequestException;
10
 
15
import com.google.gwt.http.client.Response;
11
import com.google.gwt.json.client.JSONArray;
16
import com.google.gwt.json.client.JSONArray;
12
import com.google.gwt.json.client.JSONBoolean;
17
import com.google.gwt.json.client.JSONBoolean;
13
import com.google.gwt.json.client.JSONParser;
18
import com.google.gwt.json.client.JSONParser;
Line 47... Line 52...
47
	
52
	
Line 48... Line 53...
48
	public void getEtatUtilisateur(final Rafraichissable r) {
53
	public void getEtatUtilisateur(final Rafraichissable r) {
Line 49... Line 54...
49
 
54
 
-
 
55
		// Recherche identifiant utilisateur identifie
-
 
56
 
-
 
57
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET,carnetEnLigneModele.getConfig().getServiceBaseUrl() + "/User/") ;
-
 
58
		
Line 50... Line 59...
50
		// Recherche identifiant utilisateur identifie
59
		try {
51
 
-
 
52
		HTTPRequest.asyncGet(carnetEnLigneModele.getConfig().getServiceBaseUrl() + "/User/", new ResponseTextHandler() {
-
 
53
 
-
 
54
			public void onCompletion(String str) {
-
 
55
				JSONValue jsonValue = JSONParser.parse(str);
-
 
56
				JSONArray jsonArray;
60
			
57
				if ((jsonArray = jsonValue.isArray()) != null) {
-
 
58
					String identifiant = ((JSONString) jsonArray.get(0))
-
 
59
							.stringValue(); // Identifiant utilisateur ou
-
 
60
											// identifiant de session si non
-
 
61
											// identifie
-
 
-
 
61
			rb.sendRequest(null, new RequestCallback() {
62
					boolean identifie = ((JSONBoolean) jsonArray.get(1))
62
 
63
							.booleanValue(); // Drapeau leve si utilisateur
-
 
64
												// deja identifie
-
 
Line -... Line 63...
-
 
63
				public void onError(Request request, Throwable exception) {
-
 
64
					// TODO Auto-generated method stub
-
 
65
					
-
 
66
				}
-
 
67
 
-
 
68
				public void onResponseReceived(Request request,
-
 
69
						Response response) {
-
 
70
					
-
 
71
					JSONValue jsonValue = JSONParser.parse(response.getText());
-
 
72
					JSONArray jsonArray;
-
 
73
					if ((jsonArray = jsonValue.isArray()) != null) {
-
 
74
						String identifiant = ((JSONString) jsonArray.get(0))
-
 
75
								.stringValue(); // Identifiant utilisateur ou
-
 
76
												// identifiant de session si non
-
 
77
												// identifie
-
 
78
						boolean identifie = ((JSONBoolean) jsonArray.get(1))
-
 
79
								.booleanValue(); // Drapeau leve si utilisateur
-
 
80
													// deja identifie
-
 
81
						r.rafraichir(new Utilisateur(identifiant, identifie),true);
-
 
82
					}			
-
 
83
				}			
-
 
84
			}) ;
-
 
85
			
65
					r.rafraichir(new Utilisateur(identifiant, identifie),true);
86
			
Line 66... Line 87...
66
				}
87
		} catch (RequestException e) {
Line 67... Line 88...
67
			}
88
			
-
 
89
			
-
 
90
		}
-
 
91
	}
68
		});
92
 
-
 
93
 
-
 
94
 
-
 
95
	public void deconnecterUtilisateur(final Rafraichissable r, String user) {
-
 
96
 
-
 
97
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, carnetEnLigneModele.getConfig().getServiceBaseUrl()+ "/User/" + user) ;
Line 69... Line 98...
69
 
98
		
-
 
99
		try {
-
 
100
			
-
 
101
			rb.sendRequest(null, new RequestCallback() {
-
 
102
 
-
 
103
				public void onError(Request request, Throwable exception) {
-
 
104
					// TODO Auto-generated method stub
-
 
105
					
-
 
106
				}
-
 
107
 
-
 
108
				public void onResponseReceived(Request request,
-
 
109
						Response response) {
-
 
110
					
Line 70... Line 111...
70
	}
111
					JSONValue jsonValue = JSONParser.parse(response.getText());
71
 
112
					JSONArray jsonArray;
72
 
-
 
73
 
-
 
74
	public void deconnecterUtilisateur(final Rafraichissable r, String user) {
-
 
75
 
-
 
76
		HTTPRequest.asyncGet(carnetEnLigneModele.getConfig().getServiceBaseUrl()+ "/User/" + user    ,
113
					if ((jsonArray = jsonValue.isArray()) != null) {
77
				new ResponseTextHandler() {
-
 
78
 
-
 
-
 
114
						String identifiant = ((JSONString) jsonArray.get(0))
79
					public void onCompletion(String str) {
115
						.stringValue(); // Identifiant utilisateur ou
80
						
116
										// identifiant de session si non
81
							JSONValue jsonValue = JSONParser.parse(str);
117
										// identifie
82
							JSONArray jsonArray;
118
						boolean identifie = ((JSONBoolean) jsonArray.get(1))
83
							if ((jsonArray = jsonValue.isArray()) != null) {
119
						.booleanValue(); // Drapeau leve si utilisateur
84
								String identifiant = ((JSONString) jsonArray.get(0))
120
											// deja identifie
85
								.stringValue(); // Identifiant utilisateur ou
121
						
Line 86... Line 122...
86
												// identifiant de session si non
122
					r.rafraichir(new Utilisateur(identifiant, identifie),true);
-
 
123
					}				
-
 
124
				}			
-
 
125
				
-
 
126
			}) ;
-
 
127
			
-
 
128
		} catch (RequestException e) {
Line 87... Line 129...
87
												// identifie
129
			
88
								boolean identifie = ((JSONBoolean) jsonArray.get(1))
130
			
-
 
131
		}
-
 
132
	}
Line 89... Line 133...
89
								.booleanValue(); // Drapeau leve si utilisateur
133
 
-
 
134
 
90
													// deja identifie
135
 
91
								
136
	public void connecteUtilisateur (final Rafraichissable r, String login, String password) {
92
							r.rafraichir(new Utilisateur(identifiant, identifie),true);
137
		
-
 
138
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET,carnetEnLigneModele.getConfig().getServiceBaseUrl() + "/User/" + login + "/" + password) ;
-
 
139
		
-
 
140
		try {
-
 
141
			
-
 
142
			rb.sendRequest(null, new RequestCallback() {
-
 
143
 
-
 
144
				public void onError(Request request, Throwable exception) {
-
 
145
					// TODO Auto-generated method stub
-
 
146
					
Line 93... Line -...
93
							}
-
 
94
					}
-
 
95
		});
-
 
96
	}
-
 
97
 
-
 
98
 
-
 
99
 
-
 
100
	public void connecteUtilisateur (final Rafraichissable r, String login, String password) {
-
 
101
 
-
 
102
		HTTPRequest.asyncGet(carnetEnLigneModele.getConfig().getServiceBaseUrl() + "/User/" + login + "/" + password ,
-
 
103
				new ResponseTextHandler() {
-
 
104
 
-
 
105
					public void onCompletion(String str) {
-
 
106
			
-
 
Line -... Line 147...
-
 
147
				}
-
 
148
 
-
 
149
				public void onResponseReceived(Request request,
-
 
150
						Response response) {
-
 
151
					
-
 
152
					JSONValue jsonValue = JSONParser.parse(response.getText());
-
 
153
					JSONArray jsonArray;
-
 
154
					
-
 
155
					if ((jsonArray = jsonValue.isArray()) != null) {
-
 
156
						String identifiant = ((JSONString) jsonArray.get(0))
-
 
157
						.stringValue(); // Identifiant utilisateur ou
107
						JSONValue jsonValue = JSONParser.parse(str);
158
										// identifiant de session si non