felocsss před 1 rokem
rodič
revize
27e21a3462

+ 1 - 1
app/build.gradle

@@ -83,7 +83,7 @@ dependencies {
     implementation "io.coil-kt:coil:2.4.0"
     //Preference
     implementation 'androidx.preference:preference:1.2.0'
-
+    implementation 'com.squareup.okhttp3:okhttp:4.11.0'
 }
 
 configurations {

+ 1 - 0
app/src/main/AndroidManifest.xml

@@ -15,6 +15,7 @@
         android:fullBackupContent="@xml/backup_rules"
         android:icon="@mipmap/ic_launcher"
         android:label="@string/app_name"
+        android:usesCleartextTraffic="true"
         android:roundIcon="@mipmap/ic_launcher_round"
         android:supportsRtl="true"
         android:theme="@style/Theme.AppCompat.Light.NoActionBar"

+ 53 - 0
app/src/main/java/com/sharix/sportsmanfriend/requests/HTTPRequest.java

@@ -0,0 +1,53 @@
+package com.sharix.sportsmanfriend.requests;
+
+import android.os.StrictMode;
+import android.util.Log;
+
+import com.sharix.sportsmanfriend.view.SingInSingUpActivity;
+
+import java.io.IOException;
+
+import okhttp3.FormBody;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.RequestBody;
+import okhttp3.Response;
+
+public class HTTPRequest {
+
+    OkHttpClient client = new OkHttpClient();
+    private String mainURL = "https://admin.sports.sharix-app.org";
+    private SingInSingUpActivity context;
+
+    public HTTPRequest(SingInSingUpActivity singInSingUpActivity) {
+        context = singInSingUpActivity;
+    }
+
+    public String login(String login, String password) {
+
+        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
+        StrictMode.setThreadPolicy(policy);
+
+        Log.e("MMMAAAIIINNN", "ОНО вызвалось");
+
+        RequestBody requestBody = new FormBody.Builder()
+                .add("password", password)
+                .add("phone_number", login)
+                .build();
+
+        Request request = new Request.Builder()
+                .post(requestBody)
+                .url(mainURL + "/auth/token/login/")
+                .build();
+
+        try (Response response = client.newCall(request).execute()) {
+            if (!response.isSuccessful()) {
+                throw new IOException("Запрос к серверу не был успешен: " +
+                        response.code() + " " + response.message());
+            }
+            return response.body().string();
+        } catch (IOException e) {
+            return "Ошибка";
+        }
+    }
+}

+ 4 - 0
app/src/main/java/com/sharix/sportsmanfriend/view/SingInSingUpActivity.java

@@ -8,6 +8,7 @@ import android.widget.TextView;
 import androidx.appcompat.app.AppCompatActivity;
 
 import com.sharix.sportsmanfriend.R;
+import com.sharix.sportsmanfriend.requests.HTTPRequest;
 
 public class SingInSingUpActivity extends AppCompatActivity {
 
@@ -35,5 +36,8 @@ public class SingInSingUpActivity extends AppCompatActivity {
             startActivity(intent);
         });
 
+        HTTPRequest httpRequest = new HTTPRequest(SingInSingUpActivity.this);
+        test.setText(httpRequest.login("99999999999", "password"));
     }
+
 }