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 Matcher matcher;
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) {
return etText.getText().toString().trim().length() == 0;
@ -26,18 +25,13 @@ public class InputController {
matcher = pattern.matcher(password);
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){
boolean result = false;
Boolean result = null;
try{
String[] params = new String[]{email};
return new CheckUserTask().execute(params).get();
result = new CheckUserTask().execute(params).get();
} catch (Exception e){
e.printStackTrace();
}

View file

@ -5,6 +5,7 @@ import android.content.Intent;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
@ -57,24 +58,33 @@ public class RegisterActivity extends AppCompatActivity {
if(checkInputEmpty()){
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();
}else if(InputController.validEmail(email.getText().toString())){ //checkUser
if(!InputController.checkUser(email.getText().toString())){
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 if(InputController.validEmail(email.getText().toString())){
Boolean userExist = InputController.checkUser(email.getText().toString());//checkUser
Log.i("RegisterActivity-val","userExist : "+userExist);
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 {
Toast.makeText(this, "User already exist", Toast.LENGTH_SHORT).show();
Toast.makeText(this, "An error occured", Toast.LENGTH_SHORT).show();
}
}
}
}
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)){
Toast.makeText(this, "You did not enter your name", Toast.LENGTH_SHORT).show();
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)){
Toast.makeText(this, "You did not enter your firstname", Toast.LENGTH_SHORT).show();
return false;
@ -87,6 +97,9 @@ public class RegisterActivity extends AppCompatActivity {
} else if(InputController.isEmptyEdit(confirmEmail)){
Toast.makeText(this, "You did not confirm your email", Toast.LENGTH_SHORT).show();
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)){
Toast.makeText(this, "You did not enter your password", Toast.LENGTH_SHORT).show();
return false;

View file

@ -10,7 +10,7 @@ public class Config {
//USER
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";
//TRANSACTION

View file

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

View file

@ -18,7 +18,7 @@ import monnethic.mobile.user.UserAccountActivity;
public class CreateWalletActivity extends AppCompatActivity {
private String user_hash;
private String user_password;
private int session_id;
private String session_id;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -33,13 +33,13 @@ public class CreateWalletActivity extends AppCompatActivity {
Intent intent = getIntent();
user_hash = intent.getStringExtra("USER_HASH");
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() {
@Override
public void onClick(View view) {
//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);
}
});

View file

@ -15,7 +15,7 @@ import monnethic.mobile.transaction.TransactionActivity;
public class HomeWalletActivity extends AppCompatActivity {
private String user_hash;
private String user_password;
private int session_id;
private String session_id;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -27,7 +27,7 @@ public class HomeWalletActivity extends AppCompatActivity {
Intent intent = getIntent();
user_hash = intent.getStringExtra("USER_HASH");
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() {
@Override
@ -48,7 +48,7 @@ public class HomeWalletActivity extends AppCompatActivity {
Intent createWalletIntent = new Intent(HomeWalletActivity.this, CreateWalletActivity.class);
createWalletIntent.putExtra("USER_HASH",user_hash);
createWalletIntent.putExtra("USER_PWD",user_password);
createWalletIntent.putExtra("SESSION_ID",String.valueOf(session_id));
createWalletIntent.putExtra("SESSION_ID",session_id);
HomeWalletActivity.this.startActivity(createWalletIntent);
}
@ -56,7 +56,7 @@ public class HomeWalletActivity extends AppCompatActivity {
Intent selectWalletIntent = new Intent(HomeWalletActivity.this, SelectWalletActivity.class);
selectWalletIntent.putExtra("USER_HASH",user_hash);
selectWalletIntent.putExtra("USER_PWD",user_password);
selectWalletIntent.putExtra("SESSION_ID",String.valueOf(session_id));
selectWalletIntent.putExtra("SESSION_ID",session_id);
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);
}
TextView wallet_hash = (TextView) convertView.findViewById(R.id.wallet_hash);
TextView wallet_type = (TextView) convertView.findViewById(R.id.wallet_type);
TextView wallet_balance = (TextView) convertView.findViewById(R.id.wallet_balance);
TextView wallet_hash = convertView.findViewById(R.id.wallet_hash);
TextView wallet_type = convertView.findViewById(R.id.wallet_type);
TextView wallet_balance = convertView.findViewById(R.id.wallet_balance);
ViewGroup.LayoutParams params = convertView.getLayoutParams();
params.height = 300;

View file

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

View file

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