Ejemplo n.º 1
0
        private async void btRegister_Click(object sender, RoutedEventArgs e)
        {
            Error.Text = "";
            Error.Foreground = new SolidColorBrush(Colors.Red);
            Error.Visibility = Visibility.Collapsed;

            WebRequest registerReq = new WebRequest();
            string json = "{\"username\":\""
                + login.Text + "\",\"password\":\""
                + password.Password + "\",\"email\":\""
                + Email.Text + "\"}";

            string response = await registerReq.PostRequest("http://api.nyxo.me/api/user/signup", json);
            JsonObject jsonObject = JsonValue.Parse(response).GetObject();
            JsonValue status = jsonObject.GetNamedValue("status");
            if (status.ToString() == "\"error\"")
            {
                Error.Text = jsonObject.GetNamedValue("message").ToString();
                Error.Visibility = Visibility.Visible;
            }
            else if (status.ToString() == "\"ok\"")
            {
                Error.Text = jsonObject.GetNamedValue("message").ToString();
                Error.Foreground = new SolidColorBrush(Colors.Black);
                Error.Visibility = Visibility.Visible;
            }
        }
Ejemplo n.º 2
0
        public async void Connexion_Click(object sender, RoutedEventArgs e)
        {
            WebRequest loginReq = new WebRequest();
            string json = "{\"username\":\"" + login.Text + "\","
                + "\"password\":\"" + password.Password + "\"}";

            string response = await loginReq.PostRequest("https://api.nyxo.me/api/user/login", json);
            JsonObject jsonObject = JsonValue.Parse(response).GetObject();
            JsonValue status = jsonObject.GetNamedValue("status");
            if (status.ToString() == "\"error\"")
            {
                Error.Text = jsonObject.GetNamedValue("message").ToString();
                Error.Visibility = Visibility.Visible;
            }
            else if (status.ToString() == "\"ok\"")
            {
                JsonValue sessionHash = jsonObject.GetNamedValue("data");
                User user = new User(login.Text, password.Password, sessionHash.ToString());
                Frame.Navigate(typeof(View.Accueil));
            }
        }