diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt b/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt index e95854e7..2443679b 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt @@ -1245,3 +1245,5 @@ val SwipeRefreshLayout.onScrollListener: RecyclerView.OnScrollListener operator fun Iterable>.get(key: K): V? { return firstOrNull { it.first == key }?.second } + +fun ByteArray.toHexString() = joinToString("") { "%02x".format(it) } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Constants.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Constants.kt index c2c5e47e..ee52cf1a 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Constants.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Constants.kt @@ -118,3 +118,7 @@ const val VULCAN_WEB_ENDPOINT_LUCKY_NUMBER = "Start.mvc/GetKidsLuckyNumbers" const val VULCAN_WEB_ENDPOINT_REGISTER_DEVICE = "RejestracjaUrzadzeniaToken.mvc/Get" const val EDUDZIENNIK_USER_AGENT = "Szkolny.eu/${BuildConfig.VERSION_NAME}" + +const val PODLASIE_API_VERSION = "1.0.31" +const val PODLASIE_API_URL = "https://cpdklaser.zeto.bialystok.pl/api" +const val PODLASIE_API_USER_ENDPOINT = "/pobierzDaneUcznia" diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Errors.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Errors.kt index 55d50c11..8301f62f 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Errors.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Errors.kt @@ -200,6 +200,12 @@ const val ERROR_EDUDZIENNIK_WEB_LIMITED_ACCESS = 521 const val ERROR_EDUDZIENNIK_WEB_SESSION_EXPIRED = 522 const val ERROR_EDUDZIENNIK_WEB_TEAM_MISSING = 530 +const val ERROR_LOGIN_PODLASIE_API_INVALID_TOKEN = 601 +const val ERROR_LOGIN_PODLASIE_API_DEVICE_LIMIT = 602 +const val ERROR_PODLASIE_API_NO_TOKEN = 630 +const val ERROR_PODLASIE_API_OTHER = 631 +const val ERROR_PODLASIE_API_DATA_MISSING = 632 + const val ERROR_TEMPLATE_WEB_OTHER = 801 const val EXCEPTION_API_TASK = 900 @@ -222,5 +228,6 @@ const val EXCEPTION_EDUDZIENNIK_FILE_REQUEST = 921 const val ERROR_ONEDRIVE_DOWNLOAD = 930 const val EXCEPTION_VULCAN_WEB_LOGIN = 931 const val EXCEPTION_VULCAN_WEB_REQUEST = 932 +const val EXCEPTION_PODLASIE_API_REQUEST = 940 const val LOGIN_NO_ARGUMENTS = 1201 diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/LoginMethods.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/LoginMethods.kt index 58159e71..24444a58 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/LoginMethods.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/LoginMethods.kt @@ -143,6 +143,7 @@ val edudziennikLoginMethods = listOf( ) const val LOGIN_TYPE_PODLASIE = 6 +const val LOGIN_MODE_PODLASIE_API = 0 const val LOGIN_METHOD_PODLASIE_API = 100 val podlasieLoginMethods = listOf( LoginMethod(LOGIN_TYPE_PODLASIE, LOGIN_METHOD_PODLASIE_API, PodlasieLoginApi::class.java) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/EdziennikTask.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/EdziennikTask.kt index 13de2f17..bd609cdb 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/EdziennikTask.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/EdziennikTask.kt @@ -12,6 +12,7 @@ import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.Edudziennik import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.Idziennik import pl.szczodrzynski.edziennik.data.api.edziennik.librus.Librus import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.Mobidziennik +import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.Podlasie import pl.szczodrzynski.edziennik.data.api.edziennik.template.Template import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.Vulcan import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback @@ -74,6 +75,7 @@ open class EdziennikTask(override val profileId: Int, val request: Any) : IApiTa LOGIN_TYPE_VULCAN -> Vulcan(app, profile, loginStore, taskCallback) LOGIN_TYPE_IDZIENNIK -> Idziennik(app, profile, loginStore, taskCallback) LOGIN_TYPE_EDUDZIENNIK -> Edudziennik(app, profile, loginStore, taskCallback) + LOGIN_TYPE_PODLASIE -> Podlasie(app, profile, loginStore, taskCallback) LOGIN_TYPE_TEMPLATE -> Template(app, profile, loginStore, taskCallback) else -> null } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/DataPodlasie.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/DataPodlasie.kt index a56c65bd..45edda13 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/DataPodlasie.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/DataPodlasie.kt @@ -1,7 +1,12 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-5-12 + */ + package pl.szczodrzynski.edziennik.data.api.edziennik.podlasie import pl.szczodrzynski.edziennik.App -import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_TEMPLATE_API +import pl.szczodrzynski.edziennik.crc32 +import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_PODLASIE_API import pl.szczodrzynski.edziennik.data.api.models.Data import pl.szczodrzynski.edziennik.data.db.entity.LoginStore import pl.szczodrzynski.edziennik.data.db.entity.Profile @@ -14,12 +19,10 @@ class DataPodlasie(app: App, profile: Profile?, loginStore: LoginStore) : Data(a override fun satisfyLoginMethods() { loginMethods.clear() if (isApiLoginValid()) - loginMethods += LOGIN_METHOD_TEMPLATE_API + loginMethods += LOGIN_METHOD_PODLASIE_API } - override fun generateUserCode(): String { - TODO("Not yet implemented") - } + override fun generateUserCode(): String = "$schoolShortName:$loginShort:${studentId?.crc32()}" /* _ /\ (_) @@ -33,4 +36,51 @@ class DataPodlasie(app: App, profile: Profile?, loginStore: LoginStore) : Data(a var apiToken: String? get() { mApiToken = mApiToken ?: loginStore.getLoginData("apiToken", null); return mApiToken } set(value) { loginStore.putLoginData("apiToken", value); mApiToken = value } + + private var mApiUrl: String? = null + var apiUrl: String? + get() { mApiUrl = mApiUrl ?: profile?.getStudentData("apiUrl", null); return mApiUrl } + set(value) { profile?.putStudentData("apiUrl", value) ?: return; mApiUrl = value } + + /* ____ _ _ + / __ \| | | | + | | | | |_| |__ ___ _ __ + | | | | __| '_ \ / _ \ '__| + | |__| | |_| | | | __/ | + \____/ \__|_| |_|\___|*/ + private var mStudentId: String? = null + var studentId: String? + get() { mStudentId = mStudentId ?: profile?.getStudentData("studentId", null); return mStudentId } + set(value) { profile?.putStudentData("studentId", value) ?: return; mStudentId = value } + + private var mStudentLogin: String? = null + var studentLogin: String? + get() { mStudentLogin = mStudentLogin ?: profile?.getStudentData("studentLogin", null); return mStudentLogin } + set(value) { profile?.putStudentData("studentLogin", value) ?: return; mStudentLogin = value } + + private var mSchoolName: String? = null + var schoolName: String? + get() { mSchoolName = mSchoolName ?: profile?.getStudentData("schoolName", null); return mSchoolName } + set(value) { profile?.putStudentData("schoolName", value) ?: return; mSchoolName = value } + + private var mClassName: String? = null + var className: String? + get() { mClassName = mClassName ?: profile?.getStudentData("className", null); return mClassName } + set(value) { profile?.putStudentData("className", value) ?: return; mClassName = value } + + private var mSchoolYear: String? = null + var schoolYear: String? + get() { mSchoolYear = mSchoolYear ?: profile?.getStudentData("schoolYear", null); return mSchoolYear } + set(value) { profile?.putStudentData("schoolYear", value) ?: return; mSchoolYear = value } + + private var mCurrentSemester: Int? = null + var currentSemester: Int + get() { mCurrentSemester = mCurrentSemester ?: profile?.getStudentData("currentSemester", 0); return mCurrentSemester ?: 0 } + set(value) { profile?.putStudentData("currentSemester", value) ?: return; mCurrentSemester = value } + + val schoolShortName: String? + get() = studentLogin?.replace(".podlaskie.pl", "") + + val loginShort: String? + get() = studentLogin?.split('@')?.get(0) } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/Podlasie.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/Podlasie.kt index 99c02eec..b2b5cf31 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/Podlasie.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/Podlasie.kt @@ -1,14 +1,19 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-5-12 + */ + package pl.szczodrzynski.edziennik.data.api.edziennik.podlasie import com.google.gson.JsonObject import pl.szczodrzynski.edziennik.App +import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.data.PodlasieData import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.firstlogin.PodlasieFirstLogin -import pl.szczodrzynski.edziennik.data.api.edziennik.template.TemplateFeatures +import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.login.PodlasieLogin import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikInterface import pl.szczodrzynski.edziennik.data.api.models.ApiError +import pl.szczodrzynski.edziennik.data.api.podlasieLoginMethods import pl.szczodrzynski.edziennik.data.api.prepare -import pl.szczodrzynski.edziennik.data.api.templateLoginMethods import pl.szczodrzynski.edziennik.data.db.entity.LoginStore import pl.szczodrzynski.edziennik.data.db.entity.Profile import pl.szczodrzynski.edziennik.data.db.entity.Teacher @@ -47,10 +52,14 @@ class Podlasie(val app: App, val profile: Profile?, val loginStore: LoginStore, |__*/ override fun sync(featureIds: List, viewId: Int?, onlyEndpoints: List?, arguments: JsonObject?) { data.arguments = arguments - data.prepare(templateLoginMethods, TemplateFeatures, featureIds, viewId, onlyEndpoints) + data.prepare(podlasieLoginMethods, PodlasieFeatures, featureIds, viewId, onlyEndpoints) Utils.d(TAG, "LoginMethod IDs: ${data.targetLoginMethodIds}") Utils.d(TAG, "Endpoint IDs: ${data.targetEndpointIds}") - + PodlasieLogin(data) { + PodlasieData(data) { + completed() + } + } } override fun getMessage(message: MessageFull) { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/PodlasieFeatures.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/PodlasieFeatures.kt new file mode 100644 index 00000000..c799753c --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/PodlasieFeatures.kt @@ -0,0 +1,9 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-5-12 + */ + +package pl.szczodrzynski.edziennik.data.api.edziennik.podlasie + +import pl.szczodrzynski.edziennik.data.api.models.Feature + +val PodlasieFeatures = listOf() diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/data/PodlasieApi.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/data/PodlasieApi.kt new file mode 100644 index 00000000..9ebf57b1 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/data/PodlasieApi.kt @@ -0,0 +1,107 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-5-12 + */ + +package pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.data + +import com.google.gson.JsonObject +import im.wangchao.mhttp.Request +import im.wangchao.mhttp.RequestParams +import im.wangchao.mhttp.Response +import im.wangchao.mhttp.callback.JsonCallbackHandler +import pl.szczodrzynski.edziennik.data.api.* +import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.DataPodlasie +import pl.szczodrzynski.edziennik.data.api.models.ApiError +import pl.szczodrzynski.edziennik.getInt +import pl.szczodrzynski.edziennik.getJsonObject +import pl.szczodrzynski.edziennik.toHexString +import pl.szczodrzynski.edziennik.utils.Utils +import java.security.MessageDigest +import java.text.SimpleDateFormat +import java.util.* + +open class PodlasieApi(open val data: DataPodlasie, open val lastSync: Long?) { + companion object { + const val TAG = "PodlasieApi" + } + + val profileId + get() = data.profile?.id ?: -1 + + val profile + get() = data.profile + + fun apiGet(tag: String, endpoint: String, onSuccess: (json: JsonObject) -> Unit) { + val url = PODLASIE_API_URL + endpoint + + Utils.d(tag, "Request: Podlasie/Api - $url") + + if (data.apiToken == null) { + data.error(tag, ERROR_PODLASIE_API_NO_TOKEN) + return + } + + val callback = object : JsonCallbackHandler() { + override fun onSuccess(json: JsonObject?, response: Response?) { + if (json == null || response == null) { + data.error(ApiError(TAG, ERROR_RESPONSE_EMPTY) + .withResponse(response)) + return + } + + val error = json.getJsonObject("system_message")?.getInt("code") + + error?.let { code -> + when (code) { + 0 -> ERROR_PODLASIE_API_DATA_MISSING + 4 -> ERROR_LOGIN_PODLASIE_API_DEVICE_LIMIT + 5 -> ERROR_LOGIN_PODLASIE_API_INVALID_TOKEN + 200 -> null // Not an error + else -> ERROR_PODLASIE_API_OTHER + }?.let { errorCode -> + data.error(ApiError(tag, errorCode) + .withApiResponse(json) + .withResponse(response)) + return@onSuccess + } + } + + try { + onSuccess(json) + } catch (e: Exception) { + data.error(ApiError(tag, EXCEPTION_PODLASIE_API_REQUEST) + .withResponse(response) + .withThrowable(e) + .withApiResponse(json)) + } + } + + override fun onFailure(response: Response?, throwable: Throwable?) { + data.error(ApiError(tag, ERROR_REQUEST_FAILURE) + .withResponse(response) + .withThrowable(throwable)) + } + } + + Request.builder() + .url(url) + .userAgent(SYSTEM_USER_AGENT) + .requestParams(RequestParams(mapOf( + "token" to data.apiToken, + "securityToken" to getSecurityToken(), + "mobileId" to data.app.deviceId, + "ver" to PODLASIE_API_VERSION + ))) + .callback(callback) + .build() + .enqueue() + } + + private fun getSecurityToken(): String { + val format = SimpleDateFormat("yyyy-MM-dd HH", Locale.ENGLISH).format(Calendar.getInstance().time.time) + val instance = MessageDigest.getInstance("SHA-256") + val digest = instance.digest("-EYlwYu8u16miVd8tT?oO7cvoUVQrQN0vr!$format".toByteArray()).toHexString() + val digest2 = instance.digest(data.apiToken!!.toByteArray()).toHexString() + return instance.digest("$digest$digest2".toByteArray()).toHexString() + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/data/PodlasieData.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/data/PodlasieData.kt new file mode 100644 index 00000000..98cbb539 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/data/PodlasieData.kt @@ -0,0 +1,42 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-5-12 + */ + +package pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.data + +import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.DataPodlasie +import pl.szczodrzynski.edziennik.utils.Utils + +class PodlasieData(val data: DataPodlasie, val onSuccess: () -> Unit) { + companion object { + const val TAG = "PodlasieData" + } + + init { + nextEndpoint(onSuccess) + } + + private fun nextEndpoint(onSuccess: () -> Unit) { + if (data.targetEndpointIds.isEmpty()) { + onSuccess() + return + } + if (data.cancelled) { + onSuccess() + return + } + val id = data.targetEndpointIds.firstKey() + val lastSync = data.targetEndpointIds.remove(id) + useEndpoint(id, lastSync) { + data.progress(data.progressStep) + nextEndpoint(onSuccess) + } + } + + private fun useEndpoint(endpointId: Int, lastSync: Long?, onSuccess: (endpointId: Int) -> Unit) { + Utils.d(TAG, "Using endpoint $endpointId. Last sync time = $lastSync") + when (endpointId) { + else -> onSuccess(endpointId) + } + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/firstlogin/PodlasieFirstLogin.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/firstlogin/PodlasieFirstLogin.kt index 5603222b..bedd9a25 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/firstlogin/PodlasieFirstLogin.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/firstlogin/PodlasieFirstLogin.kt @@ -1,13 +1,70 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-5-12 + */ + package pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.firstlogin +import org.greenrobot.eventbus.EventBus +import pl.szczodrzynski.edziennik.* +import pl.szczodrzynski.edziennik.data.api.LOGIN_TYPE_PODLASIE +import pl.szczodrzynski.edziennik.data.api.PODLASIE_API_USER_ENDPOINT import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.DataPodlasie +import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.data.PodlasieApi +import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.login.PodlasieLoginApi +import pl.szczodrzynski.edziennik.data.api.events.FirstLoginFinishedEvent +import pl.szczodrzynski.edziennik.data.db.entity.Profile class PodlasieFirstLogin(val data: DataPodlasie, val onSuccess: () -> Unit) { companion object { const val TAG = "PodlasieFirstLogin" } + private val api = PodlasieApi(data, null) + init { - // TODO + val loginStoreId = data.loginStore.id + val loginStoreType = LOGIN_TYPE_PODLASIE + + PodlasieLoginApi(data) { + api.apiGet(TAG, PODLASIE_API_USER_ENDPOINT) { json -> + val uuid = json.getString("Uuid") + val login = json.getString("Login") + val firstName = json.getString("FirstName") + val lastName = json.getString("LastName") + val studentNameLong = "$firstName $lastName".fixName() + val studentNameShort = studentNameLong.getShortName() + val schoolName = json.getString("SchoolName") + val className = json.getString("SchoolClass") + val schoolYear = json.getString("ActualSchoolYear")?.replace(' ', '/') + val semester = json.getString("ActualTermShortcut")?.length + val apiUrl = json.getString("URL") + + val profile = Profile( + loginStoreId, + loginStoreId, + loginStoreType, + studentNameLong, + login, + studentNameLong, + studentNameShort, + null + ).apply { + studentData["studentId"] = uuid + studentData["studentLogin"] = login + studentData["schoolName"] = schoolName + studentData["className"] = className + studentData["schoolYear"] = schoolYear + studentData["currentSemester"] = semester ?: 1 + studentData["apiUrl"] = apiUrl + + schoolYear?.split('/')?.get(0)?.toInt()?.let { + studentSchoolYearStart = it + } + } + + EventBus.getDefault().postSticky(FirstLoginFinishedEvent(listOf(profile), data.loginStore)) + onSuccess() + } + } } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/login/PodlasieLogin.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/login/PodlasieLogin.kt new file mode 100644 index 00000000..406bb997 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/login/PodlasieLogin.kt @@ -0,0 +1,54 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-5-12 + */ + +package pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.login + +import pl.szczodrzynski.edziennik.R +import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_PODLASIE_API +import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.DataPodlasie +import pl.szczodrzynski.edziennik.utils.Utils + +class PodlasieLogin(val data: DataPodlasie, val onSuccess: () -> Unit) { + companion object { + const val TAG = "PodlasieLogin" + } + + private var cancelled = false + + init { + nextLoginMethod(onSuccess) + } + + private fun nextLoginMethod(onSuccess: () -> Unit) { + if (data.targetLoginMethodIds.isEmpty()) { + onSuccess() + return + } + if (cancelled) { + onSuccess() + return + } + useLoginMethod(data.targetLoginMethodIds.removeAt(0)) { usedMethodId -> + data.progress(data.progressStep) + if (usedMethodId != -1) + data.loginMethods.add(usedMethodId) + nextLoginMethod(onSuccess) + } + } + + private fun useLoginMethod(loginMethodId: Int, onSuccess: (usedMethodId: Int) -> Unit) { + // this should never be true + if (data.loginMethods.contains(loginMethodId)) { + onSuccess(-1) + return + } + Utils.d(TAG, "Using login method $loginMethodId") + when (loginMethodId) { + LOGIN_METHOD_PODLASIE_API -> { + data.startProgress(R.string.edziennik_progress_login_podlasie_api) + PodlasieLoginApi(data) { onSuccess(loginMethodId) } + } + } + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/login/PodlasieLoginApi.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/login/PodlasieLoginApi.kt index 70c5258a..6eb70d06 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/login/PodlasieLoginApi.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/login/PodlasieLoginApi.kt @@ -1,7 +1,10 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-5-12 + */ + package pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.login import pl.szczodrzynski.edziennik.data.api.ERROR_LOGIN_DATA_MISSING -import pl.szczodrzynski.edziennik.data.api.ERROR_PROFILE_MISSING import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.DataPodlasie import pl.szczodrzynski.edziennik.data.api.models.ApiError @@ -11,11 +14,6 @@ class PodlasieLoginApi(val data: DataPodlasie, val onSuccess: () -> Unit) { } init { run { - if (data.profile == null) { - data.error(ApiError(TAG, ERROR_PROFILE_MISSING)) - return@run - } - if (data.isApiLoginValid()) { onSuccess() } else { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginInfo.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginInfo.kt index 679bcb68..d7230356 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginInfo.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginInfo.kt @@ -333,6 +333,34 @@ object LoginInfo { ) ) ) + ), + Register( + loginType = LOGIN_TYPE_PODLASIE, + internalName = "podlasie", + registerName = R.string.login_type_podlasie, + registerLogo = R.drawable.login_logo_podlasie, + loginModes = listOf( + Mode( + loginMode = LOGIN_MODE_PODLASIE_API, + name = R.string.login_mode_podlasie_api, + icon = R.drawable.login_mode_podlasie_api, + guideText = R.string.login_mode_podlasie_api_guide, + credentials = listOf( + Credential( + keyName = "apiToken", + name = R.string.login_hint_token, + icon = CommunityMaterial.Icon2.cmd_lock_outline, + emptyText = R.string.login_error_no_token, + invalidText = R.string.login_error_incorrect_token, + errorCodes = mapOf(), + isRequired = true, + validationRegex = "[a-zA-Z0-9]{10}", + caseMode = Credential.CaseMode.UNCHANGED + ) + ), + errorCodes = mapOf() + ) + ) ) ) } diff --git a/app/src/main/res/drawable-nodpi/login_logo_podlasie.png b/app/src/main/res/drawable-nodpi/login_logo_podlasie.png new file mode 100644 index 00000000..ed46d77c Binary files /dev/null and b/app/src/main/res/drawable-nodpi/login_logo_podlasie.png differ diff --git a/app/src/main/res/drawable-xhdpi/login_mode_podlasie_api.png b/app/src/main/res/drawable-xhdpi/login_mode_podlasie_api.png new file mode 100644 index 00000000..c951d686 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/login_mode_podlasie_api.png differ diff --git a/app/src/main/res/values/errors.xml b/app/src/main/res/values/errors.xml index db856eb0..0fe3df08 100644 --- a/app/src/main/res/values/errors.xml +++ b/app/src/main/res/values/errors.xml @@ -160,6 +160,12 @@ ERROR_EDUDZIENNIK_WEB_SESSION_EXPIRED ERROR_EDUDZIENNIK_WEB_TEAM_MISSING + ERROR_LOGIN_PODLASIE_API_INVALID_TOKEN + ERROR_LOGIN_PODLASIE_API_DEVICE_LIMIT + ERROR_PODLASIE_API_NO_TOKEN + ERROR_PODLASIE_API_OTHER + ERROR_PODLASIE_API_DATA_MISSING + ERROR_TEMPLATE_WEB_OTHER EXCEPTION_API_TASK @@ -180,6 +186,9 @@ EXCEPTION_EDUDZIENNIK_WEB_REQUEST EXCEPTION_EDUDZIENNIK_FILE_REQUEST ERROR_ONEDRIVE_DOWNLOAD + EXCEPTION_VULCAN_WEB_LOGIN + EXCEPTION_VULCAN_WEB_REQUEST + EXCEPTION_PODLASIE_API_REQUEST LOGIN_NO_ARGUMENTS @@ -339,6 +348,12 @@ Sesja wygasła Nie można pobrać informacji o klasie i szkole + Nieprawidłowy token + Przekroczono maksymalną liczbę urządzeń (5) + ERROR_PODLASIE_API_NO_TOKEN + ERROR_PODLASIE_API_OTHER + Brak danych. Zgłoś błąd programiście. + ERROR_TEMPLATE_WEB_OTHER Błąd synchronizacji. Upewnij się, że masz połączenie z internetem, a następnie zgłoś błąd. @@ -359,6 +374,9 @@ Wystąpił błąd Wystąpił błąd podczas pobierania pliku Nie udało się pobrać pliku z OneDrive + EXCEPTION_VULCAN_WEB_LOGIN + EXCEPTION_VULCAN_WEB_REQUEST + Zgłoś błąd: wyjątek w API PPE Nie podano parametrów diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1ee557ac..2ad4d82b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1352,4 +1352,8 @@ Zaloguj używając e-maila i hasła Użyj danych, które podajesz na stronie internetowej e-dziennika Podaj adres e-mail i hasło, których używasz do logowania w przeglądarce na stronie EduDziennika. + Podlaska Platforma Edukacyjna + Zaloguj używając tokenu + Podaj token aplikacji mobilnej. + Logowanie do PPE…