Ejemplo n.º 1
0
		public async void loadProductData() 
		{
			ServerQuery q = new ServerQuery ();
			ServerResponse rep = null;
			try {
				Dictionary<String, String> urlParams = new Dictionary<String, String>();
				urlParams.Add ("category_uid",categoryUid);
				rep = await q.Get (ServerQuery.SERVER_URL + "/product/list/", urlParams, AuthType.USER);
			} catch(WebException e) {
				Console.WriteLine (e.ToString ());
				await DisplayAlert ("Erreur", "Impossible de joindre le serveur, veuillez vérifier votre connexion.", "OK");
			} catch(UserAuthFailedException e) {
				Console.WriteLine (e.ToString ());
				await DisplayAlert ("Erreur", "Vous n'êtes pas connecté ! Veuillez vous authentifier.", "OK");
				App context = ((App)App.Current);
				context.MainPage = new NavigationPage(new LoginPage());
			}

			if (rep != null) {
				Device.BeginInvokeOnMainThread( ()=> {
					list.ItemsSource = null;
					list.ItemsSource = Product.DeserializeArray (rep.content["result"]);
				});
			}
			list.EndRefresh();
		}
Ejemplo n.º 2
0
		public async void attemptRegister(String email, String password, String firstname, String lastname) 
		{
			ServerQuery q = new ServerQuery ();
			ServerResponse rep = null;

			emailField.IsEnabled = false;
			passwordField.IsEnabled = false;
			firstnameField.IsEnabled = false;
			lastnameField.IsEnabled = false;
			submitButton.IsEnabled = false;

			try {
				Dictionary<String, String> postParams = new Dictionary<String, String>();
				postParams.Add("password", password);
				postParams.Add("email", email);
				postParams.Add("firstname", firstname);
				postParams.Add("lastname", lastname);
				rep = await q.Post (ServerQuery.SERVER_URL + "/auth/subscribe", null, postParams, AuthType.APP);
			} catch(WebException e) {
				Console.WriteLine (e.ToString());
				await DisplayAlert ("Erreur", "Impossible de joindre le serveur, veuillez vérifier votre connexion.", "OK");
			}

			if (rep != null) {
				Console.WriteLine ("Reponse : " + rep.content.ToString());
				if (rep.content.ContainsKey("code")) {
					int code = rep.content["code"];
					if (code == 0) {
						await DisplayAlert ("Bienvenue", "Vous êtes maitenant inscrit", "OK");
						await this.Navigation.PopAsync ();
					} else {
						emailField.IsEnabled = true;
						passwordField.IsEnabled = true;
						firstnameField.IsEnabled = true;
						lastnameField.IsEnabled = true;
						submitButton.IsEnabled = true;
						if(rep.content.ContainsKey("message"))
							await DisplayAlert ("Erreur", "Erreur durant l'inscription : " + rep.content["message"], "OK");
						else
							await DisplayAlert ("Erreur", "Une erreur est survenue", "OK");
					}
				}
			}
		}
Ejemplo n.º 3
0
		public async void loadStoreData() 
		{
			ServerQuery q = new ServerQuery ();
			ServerResponse rep = null;
			try {
				rep = await q.Get (ServerQuery.SERVER_URL + "/store/list", null, AuthType.APP);
			} catch(WebException e) {
				Console.WriteLine (e.ToString ());
				await DisplayAlert ("Erreur", "Impossible de joindre le serveur, veuillez vérifier votre connexion.", "OK");
			}

			if (rep != null) {
				Device.BeginInvokeOnMainThread( ()=> {
					list.ItemsSource = null;
					list.ItemsSource = Store.DeserializeArray (rep.content["result"]);
				});
			}
			list.EndRefresh();
		}
Ejemplo n.º 4
0
		public async void checkUserSession() 
		{
			ServerQuery q = new ServerQuery ();
			ServerResponse rep = null;
			try {
				Dictionary<String, String> urlParams = new Dictionary<String, String>();
				urlParams.Add("search", "test");
				rep = await q.Get (ServerQuery.SERVER_URL + "/product/list", urlParams, AuthType.USER);
				if(rep != null) {
					App context = ((App)App.Current);
					context.MainPage = new RootPage();
				}
			} catch(WebException e) {
				Console.WriteLine (e.ToString());
				await DisplayAlert ("Erreur", "Impossible de joindre le serveur, veuillez vérifier votre connexion.", "OK");
			} catch(UserAuthFailedException e) {
				Console.WriteLine (e.ToString ());
			}
		}
Ejemplo n.º 5
0
		public async void loadCategoryData() 
		{
			ServerQuery q = new ServerQuery ();
			ServerResponse rep = null;
			try {
				Dictionary<String, String> urlParams = new Dictionary<String, String>();
				urlParams.Add ("store_uid",storeUid);
				rep = await q.Get (ServerQuery.SERVER_URL + "/category/list/", urlParams, AuthType.APP);
			} catch(WebException e) {
				Console.WriteLine (e.ToString ());
				await DisplayAlert ("Erreur", "Impossible de joindre le serveur, veuillez vérifier votre connexion.", "OK");
			}

			if (rep != null) {
				Device.BeginInvokeOnMainThread( ()=> {
					list.ItemsSource = null;
					list.ItemsSource = Category.DeserializeArray (rep.content["result"]);
				});
			}
			list.EndRefresh();
		}
Ejemplo n.º 6
0
		/// <summary>
		/// Authenticate a User with the specified username and password.
		/// Returns TRUE if successful or FALSE otherwise.
		/// </summary>
		/// <param name="username">Username.</param>
		/// <param name="password">Password.</param>
		public async Task<Boolean> Authenticate(string username, string password)
		{
			Dictionary<String, String> body = new Dictionary<String, String> ();
			ServerQuery server = new ServerQuery ();
			body.Add ("client_id", AppAuth.CLIENT_ID);
			body.Add ("client_secret", AppAuth.CLIENT_SECRET);
			body.Add ("grant_type", "password");
			body.Add ("username", username);
			body.Add ("password", password);

			ServerResponse response = await server.Post (ServerQuery.SERVER_URL + "/oauth/token", null, body, AuthType.NONE);

			if (response != null && response.isOk()) {
				if (response.content.ContainsKey ("access_token") && response.content.ContainsKey ("refresh_token")) {
					AccessToken = (String) response.content ["access_token"];
					RefreshToken = (String) response.content ["refresh_token"];
					return true;
				}
			}

			return false;
		}
Ejemplo n.º 7
0
		/// <summary>
		/// Attempt to refresh the Application's access token
		/// If the refresh token is reject then a request for a fresh token will be sent
		/// </summary>
		public async Task<ServerResponse> Refresh()
		{
			Dictionary<String, String> body = new Dictionary<String, String> ();
			ServerQuery server = new ServerQuery ();
			body.Add ("client_id", CLIENT_ID);
			body.Add ("client_secret", CLIENT_SECRET);
			if (RefreshToken != null) {
				body.Add ("grant_type", "refresh_token");
				body.Add ("refresh_token", RefreshToken);
			} else {
				body.Add ("grant_type", "client_credentials");
			}

			ServerResponse response = await server.Post (ServerQuery.SERVER_URL + "/oauth/token", null, body, AuthType.NONE);
			if (response != null && response.isBad()) { // refresh token rejected
				AccessToken = null;
				RefreshToken = null;
				return await Refresh ();
			}

			AccessToken = (String) response.content ["access_token"];
			RefreshToken = (String) response.content ["refresh_token"];
			return response;
		}