diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser
index 9e00445..7e327e4 100644
Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 5889604..8bdd263 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,55 +1,19 @@
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
@@ -72,22 +36,32 @@
-
-
-
+
+
+
-
-
+
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
@@ -95,6 +69,11 @@
+
+
+ Looper.prepare()
+
+
@@ -2229,6 +2208,10 @@
@@ -2253,26 +2236,44 @@
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
@@ -2440,38 +2441,37 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
-
-
-
+
+
+
-
-
+
+
+
@@ -2482,14 +2482,54 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
@@ -2498,5 +2538,45 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/org/libre/agosto/p2play/HostActivity.kt b/app/src/main/java/org/libre/agosto/p2play/HostActivity.kt
index a2bffa7..4bd2205 100644
--- a/app/src/main/java/org/libre/agosto/p2play/HostActivity.kt
+++ b/app/src/main/java/org/libre/agosto/p2play/HostActivity.kt
@@ -72,7 +72,9 @@ class HostActivity : AppCompatActivity() {
host = host.replace("/","")
ManagerSingleton.url = host
AsyncTask.execute {
- Looper.prepare()
+ if (Looper.myLooper()==null)
+ Looper.prepare()
+
val keys = client.getKeys()
if(keys.client_id!=""){
editor.putString("client_id",keys.client_id)
diff --git a/app/src/main/java/org/libre/agosto/p2play/LoginActivity.kt b/app/src/main/java/org/libre/agosto/p2play/LoginActivity.kt
index 320b87a..64ac851 100644
--- a/app/src/main/java/org/libre/agosto/p2play/LoginActivity.kt
+++ b/app/src/main/java/org/libre/agosto/p2play/LoginActivity.kt
@@ -39,7 +39,9 @@ class LoginActivity : AppCompatActivity() {
val password = passwordText.text.toString()
AsyncTask.execute {
- Looper.prepare()
+ if (Looper.myLooper()==null)
+ Looper.prepare()
+
val token = _auth.login(username, password, client_id, client_secret)
// Log.d("token", token.token )
diff --git a/app/src/main/java/org/libre/agosto/p2play/RegisterActivity.kt b/app/src/main/java/org/libre/agosto/p2play/RegisterActivity.kt
index a59b630..5cf3692 100644
--- a/app/src/main/java/org/libre/agosto/p2play/RegisterActivity.kt
+++ b/app/src/main/java/org/libre/agosto/p2play/RegisterActivity.kt
@@ -1,12 +1,56 @@
package org.libre.agosto.p2play
+import android.content.SharedPreferences
+import android.os.AsyncTask
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
+import android.os.Looper
+import android.preference.PreferenceManager
+import android.util.Log
+import kotlinx.android.synthetic.main.activity_register.*
+import org.libre.agosto.p2play.ajax.Auth
class RegisterActivity : AppCompatActivity() {
+ private val _auth = Auth()
+ lateinit var settings: SharedPreferences
+ lateinit var client_id: String
+ lateinit var client_secret: String
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_register)
+ setTitle(R.string.registerActionBtn)
+ ManagerSingleton.context = this
+
+ settings = PreferenceManager.getDefaultSharedPreferences(this)
+ client_id = settings.getString("client_id", "")
+ client_secret = settings.getString("client_secret", "")
+
+ registerBtn.setOnClickListener { registerUser() }
+ }
+
+ fun registerUser(){
+ registerBtn.isEnabled = false
+ val username = userText2.text.toString()
+ val password = passwordText2.text.toString()
+ val email = emailText.text.toString()
+ AsyncTask.execute {
+ if (Looper.myLooper()==null)
+ Looper.prepare()
+
+ val res = _auth.register(username, password, email)
+ Log.d("Res register", res.toString())
+ runOnUiThread {
+ when (res) {
+ 1 -> {
+ ManagerSingleton.Toast(getString(R.string.registerSuccess_msg))
+ finish()
+ }
+ 0 -> ManagerSingleton.Toast(getString(R.string.registerFailed_msg))
+ -1 -> ManagerSingleton.Toast(getString(R.string.registerError_msg))
+ }
+ registerBtn.isEnabled = true
+ }
+ }
}
}
diff --git a/app/src/main/java/org/libre/agosto/p2play/ajax/Auth.kt b/app/src/main/java/org/libre/agosto/p2play/ajax/Auth.kt
index c683052..bfd8525 100644
--- a/app/src/main/java/org/libre/agosto/p2play/ajax/Auth.kt
+++ b/app/src/main/java/org/libre/agosto/p2play/ajax/Auth.kt
@@ -48,6 +48,27 @@ class Auth: Client() {
return token
}
+ fun register(username: String, password: String, email: String): Int{
+ var con = this._newCon("users/register","POST")
+ val params:String= "username=$username&password=$password&email=$email"
+ con.outputStream.write(params.toByteArray())
+
+ var response = 0
+
+ try {
+ if (con.responseCode == 204) {
+ response = 1
+ }
+ }
+ catch (err: Exception){
+ err.printStackTrace()
+ response = -1
+ }
+
+ return response
+
+ }
+
fun me(token: String): UserModel{
var con = this._newCon("users/me","GET", token)
diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml
index 417720e..3135acc 100644
--- a/app/src/main/res/layout/activity_login.xml
+++ b/app/src/main/res/layout/activity_login.xml
@@ -90,7 +90,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/registerActionBtn"
- android:visibility="invisible" />
+ android:visibility="visible" />
diff --git a/app/src/main/res/layout/activity_register.xml b/app/src/main/res/layout/activity_register.xml
index f01cc03..acb9e6d 100644
--- a/app/src/main/res/layout/activity_register.xml
+++ b/app/src/main/res/layout/activity_register.xml
@@ -47,13 +47,13 @@
android:layout_height="30dp" />
Login now
Create new account
- Email:
- user@mail.com
- Register now
-
+
You are logged
An error has ocurred
Invalid credentials
+ You are registered
+ An error has ocurred
+ Invalid data
+
+
+ Register now
+ Email:
+ user@mail.com
+
\ No newline at end of file