update register & create wallet

This commit is contained in:
GME 2019-04-15 19:56:10 +02:00
parent 4ef452983a
commit 07e193747e
9 changed files with 60 additions and 51 deletions

View file

@ -13,7 +13,6 @@ public class InputController {
private static Pattern pattern; private static Pattern pattern;
private static Matcher matcher; private static Matcher matcher;
private static final String PASSWORD_PATTERN = "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{6,20})"; private static final String PASSWORD_PATTERN = "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{6,20})";
private static final String NAME_PATTERN = "((?=.*[a-z]).{4,30})";
public static boolean isEmptyEdit(EditText etText) { public static boolean isEmptyEdit(EditText etText) {
return etText.getText().toString().trim().length() == 0; return etText.getText().toString().trim().length() == 0;
@ -26,18 +25,13 @@ public class InputController {
matcher = pattern.matcher(password); matcher = pattern.matcher(password);
return matcher.matches(); return matcher.matches();
} }
public static boolean nameValidator(String name){
pattern = Pattern.compile(NAME_PATTERN);
matcher = pattern.matcher(name);
return matcher.matches();
}
public static Boolean checkUser(String email){ public static Boolean checkUser(String email){
boolean result = false; Boolean result = null;
try{ try{
String[] params = new String[]{email}; String[] params = new String[]{email};
return new CheckUserTask().execute(params).get(); result = new CheckUserTask().execute(params).get();
} catch (Exception e){ } catch (Exception e){
e.printStackTrace(); e.printStackTrace();
} }

View file

@ -5,6 +5,7 @@ import android.content.Intent;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
@ -57,24 +58,33 @@ public class RegisterActivity extends AppCompatActivity {
if(checkInputEmpty()){ if(checkInputEmpty()){
if(!InputController.passwordValidator(password.getText().toString())){ if(!InputController.passwordValidator(password.getText().toString())){
Toast.makeText(this, "Password must contains 6 to 20 characters, one lowercase, one uppercase and one digit", Toast.LENGTH_LONG).show(); Toast.makeText(this, "Password must contains 6 to 20 characters, one lowercase, one uppercase and one digit", Toast.LENGTH_LONG).show();
}else if(InputController.validEmail(email.getText().toString())){ //checkUser }else if(InputController.validEmail(email.getText().toString())){
if(!InputController.checkUser(email.getText().toString())){ Boolean userExist = InputController.checkUser(email.getText().toString());//checkUser
User inputUser = new User(name.getText().toString(),firstname.getText().toString(),email.getText().toString(),password.getText().toString(),phone.getText().toString(),"gonette"); Log.i("RegisterActivity-val","userExist : "+userExist);
new UserRegisterTask(this).execute(inputUser); if(userExist != null){
if(userExist){
Toast.makeText(this, "User already exist", Toast.LENGTH_SHORT).show();
} else {
User inputUser = new User(name.getText().toString(),firstname.getText().toString(),email.getText().toString(),password.getText().toString(),phone.getText().toString(),"gonette");
new UserRegisterTask(this).execute(inputUser);
}
} else { } else {
Toast.makeText(this, "User already exist", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "An error occured", Toast.LENGTH_SHORT).show();
} }
} }
} }
} }
private boolean checkInputEmpty(){ private boolean checkInputEmpty(){
Log.i("checkInputEmpty",name.getText().toString());
Log.i("checkInputEmpty",firstname.getText().toString());
Log.i("checkInputEmpty",email.getText().toString());
Log.i("checkInputEmpty",confirmEmail.getText().toString());
Log.i("checkInputEmpty",password.getText().toString());
if(InputController.isEmptyEdit(name)){ if(InputController.isEmptyEdit(name)){
Toast.makeText(this, "You did not enter your name", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "You did not enter your name", Toast.LENGTH_SHORT).show();
return false; return false;
} else if (!InputController.nameValidator(name.getText().toString())){
Toast.makeText(this, "Name must be 4 to 30 character long", Toast.LENGTH_SHORT).show();
return false;
} else if(InputController.isEmptyEdit(firstname)){ } else if(InputController.isEmptyEdit(firstname)){
Toast.makeText(this, "You did not enter your firstname", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "You did not enter your firstname", Toast.LENGTH_SHORT).show();
return false; return false;
@ -87,6 +97,9 @@ public class RegisterActivity extends AppCompatActivity {
} else if(InputController.isEmptyEdit(confirmEmail)){ } else if(InputController.isEmptyEdit(confirmEmail)){
Toast.makeText(this, "You did not confirm your email", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "You did not confirm your email", Toast.LENGTH_SHORT).show();
return false; return false;
} else if(InputController.isEmptyEdit(phone)){
Toast.makeText(this, "You did not enter your phone number", Toast.LENGTH_SHORT).show();
return false;
} else if(InputController.isEmptyEdit(password)){ } else if(InputController.isEmptyEdit(password)){
Toast.makeText(this, "You did not enter your password", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "You did not enter your password", Toast.LENGTH_SHORT).show();
return false; return false;

View file

@ -10,7 +10,7 @@ public class Config {
//USER //USER
static public String USER_LOGIN = BASE_URL_USER+"login"; static public String USER_LOGIN = BASE_URL_USER+"login";
static public String USER_REGISTER = BASE_URL_USER+"save"; static public String USER_REGISTER = BASE_URL_USER+"register";
static public String USER_GET = BASE_URL_USER+"get"; static public String USER_GET = BASE_URL_USER+"get";
//TRANSACTION //TRANSACTION

View file

@ -1,5 +1,7 @@
package monnethic.mobile.restApi; package monnethic.mobile.restApi;
import android.util.Log;
import org.json.JSONObject; import org.json.JSONObject;
import java.net.URL; import java.net.URL;
@ -27,11 +29,12 @@ public class UserApiHandler {
String responseCall = httpCallHandler.postHttp(new URL(url), map); String responseCall = httpCallHandler.postHttp(new URL(url), map);
JSONObject jsonObject = new JSONObject(responseCall); JSONObject jsonObject = new JSONObject(responseCall);
u.setUser_hash(jsonObject.getString("user_hash")); u.setUser_hash(jsonObject.getString("user_hash"));
Log.i("UserApiHandler-register","user_hash :"+jsonObject.getString("user_hash"));
JSONObject jsonReturn = new JSONObject(); JSONObject jsonReturn = new JSONObject();
jsonReturn.put("user_hash",u.getUser_hash()); jsonReturn.put("user_hash",u.getUser_hash());
//jsonReturn.put("session_id",jsonObject.getString("session_id")); //TODO //jsonReturn.put("session_id",String.valueOf(jsonObject.getString("session_id"))); //TODO
jsonReturn.put("session_id",jsonObject.getString("0")); jsonReturn.put("session_id",String.valueOf(0));
return jsonReturn; return jsonReturn;
}catch (Exception e){ }catch (Exception e){
@ -58,8 +61,8 @@ public class UserApiHandler {
JSONObject jsonReturn = new JSONObject(); JSONObject jsonReturn = new JSONObject();
jsonReturn.put("status",200); jsonReturn.put("status",200);
jsonReturn.put("user_hash",u.getUser_hash()); jsonReturn.put("user_hash",u.getUser_hash());
//jsonReturn.put("session_id",jsonObject.getString("session_id")); //TODO //jsonReturn.put("session_id",String.valueOf(jsonObject.getString("session_id"))); //TODO
jsonReturn.put("session_id",0); jsonReturn.put("session_id",String.valueOf(0));
return jsonReturn; return jsonReturn;
} }
@ -71,7 +74,7 @@ public class UserApiHandler {
public Boolean checkUser(String email){ public Boolean checkUser(String email){
HttpCallHandler httpCallHandler = new HttpCallHandler(); HttpCallHandler httpCallHandler = new HttpCallHandler();
Boolean response=false; Boolean response = null;
try{ try{
String url = Config.USER_GET+"?user_email="+email; String url = Config.USER_GET+"?user_email="+email;
String responseCall = httpCallHandler.getHttp(new URL(url)); String responseCall = httpCallHandler.getHttp(new URL(url));

View file

@ -18,7 +18,7 @@ import monnethic.mobile.user.UserAccountActivity;
public class CreateWalletActivity extends AppCompatActivity { public class CreateWalletActivity extends AppCompatActivity {
private String user_hash; private String user_hash;
private String user_password; private String user_password;
private int session_id; private String session_id;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -33,13 +33,13 @@ public class CreateWalletActivity extends AppCompatActivity {
Intent intent = getIntent(); Intent intent = getIntent();
user_hash = intent.getStringExtra("USER_HASH"); user_hash = intent.getStringExtra("USER_HASH");
user_password = intent.getStringExtra("USER_PWD"); user_password = intent.getStringExtra("USER_PWD");
session_id = Integer.parseInt(intent.getStringExtra("SESSION_ID")); session_id = intent.getStringExtra("SESSION_ID");
buttonValidate.setOnClickListener(new View.OnClickListener() { buttonValidate.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
//TODO ASYNC wallet_type //TODO ASYNC wallet_type
Wallet wallet = new Wallet(wallet_type.toString(),user_hash); Wallet wallet = new Wallet(wallet_type.getText().toString(),user_hash);
new CreateWalletTask(context).execute(wallet); new CreateWalletTask(context).execute(wallet);
} }
}); });

View file

@ -15,7 +15,7 @@ import monnethic.mobile.transaction.TransactionActivity;
public class HomeWalletActivity extends AppCompatActivity { public class HomeWalletActivity extends AppCompatActivity {
private String user_hash; private String user_hash;
private String user_password; private String user_password;
private int session_id; private String session_id;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -27,7 +27,7 @@ public class HomeWalletActivity extends AppCompatActivity {
Intent intent = getIntent(); Intent intent = getIntent();
user_hash = intent.getStringExtra("USER_HASH"); user_hash = intent.getStringExtra("USER_HASH");
user_password = intent.getStringExtra("USER_PWD"); user_password = intent.getStringExtra("USER_PWD");
session_id = Integer.parseInt(intent.getStringExtra("SESSION_ID")); session_id = intent.getStringExtra("SESSION_ID");
buttonCreateWallet.setOnClickListener(new View.OnClickListener() { buttonCreateWallet.setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -48,7 +48,7 @@ public class HomeWalletActivity extends AppCompatActivity {
Intent createWalletIntent = new Intent(HomeWalletActivity.this, CreateWalletActivity.class); Intent createWalletIntent = new Intent(HomeWalletActivity.this, CreateWalletActivity.class);
createWalletIntent.putExtra("USER_HASH",user_hash); createWalletIntent.putExtra("USER_HASH",user_hash);
createWalletIntent.putExtra("USER_PWD",user_password); createWalletIntent.putExtra("USER_PWD",user_password);
createWalletIntent.putExtra("SESSION_ID",String.valueOf(session_id)); createWalletIntent.putExtra("SESSION_ID",session_id);
HomeWalletActivity.this.startActivity(createWalletIntent); HomeWalletActivity.this.startActivity(createWalletIntent);
} }
@ -56,7 +56,7 @@ public class HomeWalletActivity extends AppCompatActivity {
Intent selectWalletIntent = new Intent(HomeWalletActivity.this, SelectWalletActivity.class); Intent selectWalletIntent = new Intent(HomeWalletActivity.this, SelectWalletActivity.class);
selectWalletIntent.putExtra("USER_HASH",user_hash); selectWalletIntent.putExtra("USER_HASH",user_hash);
selectWalletIntent.putExtra("USER_PWD",user_password); selectWalletIntent.putExtra("USER_PWD",user_password);
selectWalletIntent.putExtra("SESSION_ID",String.valueOf(session_id)); selectWalletIntent.putExtra("SESSION_ID",session_id);
HomeWalletActivity.this.startActivity(selectWalletIntent); HomeWalletActivity.this.startActivity(selectWalletIntent);
} }

View file

@ -24,9 +24,9 @@ public class WalletAdapter extends ArrayAdapter<Wallet> {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.wallet_view_template, parent, false); convertView = LayoutInflater.from(getContext()).inflate(R.layout.wallet_view_template, parent, false);
} }
TextView wallet_hash = (TextView) convertView.findViewById(R.id.wallet_hash); TextView wallet_hash = convertView.findViewById(R.id.wallet_hash);
TextView wallet_type = (TextView) convertView.findViewById(R.id.wallet_type); TextView wallet_type = convertView.findViewById(R.id.wallet_type);
TextView wallet_balance = (TextView) convertView.findViewById(R.id.wallet_balance); TextView wallet_balance = convertView.findViewById(R.id.wallet_balance);
ViewGroup.LayoutParams params = convertView.getLayoutParams(); ViewGroup.LayoutParams params = convertView.getLayoutParams();
params.height = 300; params.height = 300;

View file

@ -31,46 +31,46 @@
<TextView <TextView
android:id="@+id/textViewAdresse" android:id="@+id/textViewAdresse"
android:layout_width="80dp" android:layout_width="60dp"
android:layout_height="25dp" android:layout_height="32dp"
android:layout_marginBottom="20dp" android:layout_marginStart="20dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:layout_marginStart="48dp" android:layout_marginBottom="20dp"
android:text="Adresse :" android:text="Adresse :"
app:layout_constraintBottom_toTopOf="@+id/textViewAmount" app:layout_constraintBottom_toTopOf="@+id/textViewAmount"
app:layout_constraintEnd_toStartOf="@+id/textViewAdresseDisplay" app:layout_constraintEnd_toStartOf="@+id/textViewAdresseDisplay"
app:layout_constraintHorizontal_bias="0.0" app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent" /> app:layout_constraintStart_toStartOf="parent" />
<TextView <TextView
android:id="@+id/textViewAdresseDisplay" android:id="@+id/textViewAdresseDisplay"
android:layout_width="216dp" android:layout_width="268dp"
android:layout_height="26dp" android:layout_height="32dp"
android:layout_marginEnd="32dp" android:layout_marginEnd="16dp"
android:layout_marginBottom="20dp" android:layout_marginBottom="20dp"
android:textSize="10sp" android:textSize="9sp"
app:layout_constraintBottom_toTopOf="@+id/textViewAmountDisplay" app:layout_constraintBottom_toTopOf="@+id/textViewAmountDisplay"
app:layout_constraintEnd_toEndOf="parent" /> app:layout_constraintEnd_toEndOf="parent" />
<TextView <TextView
android:id="@+id/textViewAmount" android:id="@+id/textViewAmount"
android:layout_width="80dp" android:layout_width="60dp"
android:layout_height="25dp" android:layout_height="25dp"
android:layout_marginBottom="140dp" android:layout_marginStart="20dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:layout_marginStart="48dp" android:layout_marginBottom="140dp"
android:text="Montant :" android:text="Montant :"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/textViewAmountDisplay" app:layout_constraintEnd_toStartOf="@+id/textViewAmountDisplay"
app:layout_constraintHorizontal_bias="0.0" app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent" /> app:layout_constraintStart_toStartOf="parent" />
<TextView <TextView
android:id="@+id/textViewAmountDisplay" android:id="@+id/textViewAmountDisplay"
android:layout_width="150dp" android:layout_width="172dp"
android:layout_height="25dp" android:layout_height="25dp"
android:layout_marginEnd="112dp"
android:layout_marginBottom="140dp" android:layout_marginBottom="140dp"
android:layout_marginEnd="96dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" /> app:layout_constraintEnd_toEndOf="parent" />
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>

View file

@ -66,7 +66,7 @@
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_marginTop="215dp" android:layout_marginTop="215dp"
android:textAlignment="center" android:textAlignment="center"
android:textSize="30sp" /> android:textSize="18sp" />
<TextView <TextView
android:id="@+id/textBalance" android:id="@+id/textBalance"
@ -77,7 +77,7 @@
android:layout_marginTop="177dp" android:layout_marginTop="177dp"
android:text="BALANCE" android:text="BALANCE"
android:textAlignment="center" android:textAlignment="center"
android:textSize="18sp" android:textSize="20sp"
android:textStyle="bold" /> android:textStyle="bold" />
<TextView <TextView
@ -90,8 +90,7 @@
android:layout_marginLeft="30dp" android:layout_marginLeft="30dp"
android:layout_marginRight="30dp" android:layout_marginRight="30dp"
android:layout_marginTop="90dp" android:layout_marginTop="90dp"
android:gravity="center" android:textSize="12sp" />
android:textSize="15sp" />
</RelativeLayout> </RelativeLayout>