|
@@ -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 "Ошибка";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|