update user
This commit is contained in:
parent
40bbcc12b6
commit
7c49cb679c
|
@ -1,7 +1,5 @@
|
|||
package monnethic.mobile.database;
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
|
@ -10,28 +8,47 @@ import java.util.Date;
|
|||
|
||||
//Class User which represent an User for api rest
|
||||
public class User {
|
||||
private int userId;
|
||||
private int user_id;
|
||||
private String name;
|
||||
private String firstname;
|
||||
private String email;
|
||||
private String password;
|
||||
private long creation_date;
|
||||
private long modification_date;
|
||||
private String phone;
|
||||
private String association;
|
||||
private boolean verified;
|
||||
private boolean approved;
|
||||
private String user_hash;
|
||||
|
||||
//Constructors
|
||||
public User(){}
|
||||
public User(String name, String firstname, String email, String password) {
|
||||
this.name = name;
|
||||
this.firstname = firstname;
|
||||
public User() {
|
||||
}
|
||||
|
||||
public User(String email, String password){
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public User(int userId, String name, String firstname, String user_hash, String email, String password, long creation_date, long modification_date, boolean verified, boolean approved) {
|
||||
this.userId=userId;
|
||||
public User(String name, String firstname, String email, String password, String association) {
|
||||
this.name = name;
|
||||
this.firstname = firstname;
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
this.association = association;
|
||||
}
|
||||
|
||||
public User(String name, String firstname, String email, String password, String phone, String association){
|
||||
this.name = name;
|
||||
this.firstname = firstname;
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
this.phone = phone;
|
||||
this.association = association;
|
||||
}
|
||||
|
||||
|
||||
public User(String name, String firstname,String user_hash, String email, String password, long creation_date, long modification_date, boolean verified, boolean approved) {
|
||||
this.name = name;
|
||||
this.firstname = firstname;
|
||||
this.user_hash = user_hash;
|
||||
|
@ -43,10 +60,26 @@ public class User {
|
|||
this.approved = approved;
|
||||
}
|
||||
|
||||
public User(String name, String firstname,String user_hash, String email, String password, long creation_date, long modification_date, String phone, String association, boolean verified, boolean approved) {
|
||||
this.name = name;
|
||||
this.firstname = firstname;
|
||||
this.user_hash = user_hash;
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
this.creation_date = creation_date;
|
||||
this.modification_date = modification_date;
|
||||
this.phone = phone;
|
||||
this.association = association;
|
||||
this.verified = verified;
|
||||
this.approved = approved;
|
||||
}
|
||||
|
||||
|
||||
//Getters and Setters
|
||||
public int getUserId(){return userId;}
|
||||
public void setUserId(int userId){this.userId=userId;}
|
||||
public int getUserId() {
|
||||
return user_id;
|
||||
}
|
||||
public void setUserId(int userId) {this.user_id = userId;}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -55,6 +88,10 @@ public class User {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
public String getUser_hash(){return user_hash;}
|
||||
public void setUser_hash(String user_hash){this.user_hash = user_hash;}
|
||||
|
||||
|
||||
public String getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
|
@ -62,9 +99,6 @@ public class User {
|
|||
this.firstname = firstname;
|
||||
}
|
||||
|
||||
public String getUser_hash(){return user_hash;}
|
||||
public void setUser_hash(String user_hash){this.user_hash=user_hash;}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
@ -93,6 +127,12 @@ public class User {
|
|||
this.modification_date = modification_date;
|
||||
}
|
||||
|
||||
public String getPhone(){return phone;}
|
||||
public void setPhone(String phone){this.phone=phone;}
|
||||
|
||||
public String getAssociation(){return association;}
|
||||
public void setAssociation(){this.association=association;}
|
||||
|
||||
public boolean isVerified() {
|
||||
return verified;
|
||||
}
|
||||
|
@ -106,4 +146,23 @@ public class User {
|
|||
public void setApproved(boolean approved) {
|
||||
this.approved = approved;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User{" +
|
||||
"userId=" + user_id +
|
||||
", name='" + name + '\'' +
|
||||
", firstname='" + firstname + '\'' +
|
||||
", email='" + email + '\'' +
|
||||
", password='" + password + '\'' +
|
||||
", creation_date=" + creation_date +
|
||||
", modification_date=" + modification_date +
|
||||
", phone= "+phone+
|
||||
", association= "+association+
|
||||
", verified=" + verified +
|
||||
", approved=" + approved +
|
||||
", user_hash='" + user_hash + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
package monnethic.mobile.homepage;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.widget.EditText;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import monnethic.mobile.restApi.Config;
|
||||
import monnethic.mobile.restApi.UserApiHandler;
|
||||
|
||||
public class InputController {
|
||||
private static Pattern pattern;
|
||||
private static Matcher matcher;
|
||||
|
@ -28,15 +32,24 @@ public class InputController {
|
|||
return matcher.matches();
|
||||
}
|
||||
|
||||
//TODO VERIFY IF INPUTED USER ALREADY EXIST IN LDAP
|
||||
public static boolean checkUser(String mail){
|
||||
//Statement stmt = null;
|
||||
//String query = "SELECT userId FROM USER_TABLE WHERE email="+mail+";";
|
||||
return false;
|
||||
|
||||
public static Boolean checkUser(String email){
|
||||
boolean result = false;
|
||||
try{
|
||||
String[] params = new String[]{email};
|
||||
return new CheckUserTask().execute(params).get();
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//TODO CHECK USER AND SEND BACK ID
|
||||
public static boolean checkUser(String mail, String password){
|
||||
return true;
|
||||
private static class CheckUserTask extends AsyncTask<String,String,Boolean> {
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(String... params) {
|
||||
UserApiHandler userApiHandler = new UserApiHandler();
|
||||
return userApiHandler.checkUser(params[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,8 +11,8 @@ import android.widget.EditText;
|
|||
import android.widget.Toast;
|
||||
import com.example.monnthic.monnethicmobile.R;
|
||||
import org.json.JSONObject;
|
||||
import monnethic.mobile.restApi.Config;
|
||||
import monnethic.mobile.restApi.HttpCallHandler;
|
||||
import monnethic.mobile.database.User;
|
||||
import monnethic.mobile.restApi.UserApiHandler;
|
||||
import monnethic.mobile.wallet.HomeWalletActivity;
|
||||
|
||||
public class LoginActivity extends AppCompatActivity {
|
||||
|
@ -56,35 +56,35 @@ public class LoginActivity extends AppCompatActivity {
|
|||
} else if(InputController.isEmptyEdit(password)) {
|
||||
Toast.makeText(this, "You did not enter your password", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
if(InputController.checkUser(email.getText().toString(),password.getText().toString())){
|
||||
String[] params = {email.getText().toString(),password.getText().toString()};
|
||||
new UserLoggerTask(this).execute(params);
|
||||
}else{
|
||||
Toast.makeText(this, "Wrong authentication", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
User user = new User(email.getText().toString(),password.getText().toString());
|
||||
new UserLoggerTask(this).execute(user);
|
||||
}
|
||||
}
|
||||
|
||||
//AsyncTask for login
|
||||
private class UserLoggerTask extends AsyncTask<String,String,JSONObject> {
|
||||
private class UserLoggerTask extends AsyncTask<User,String,JSONObject> {
|
||||
Context mContext;
|
||||
private UserLoggerTask(final Context context){
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(JSONObject result) {
|
||||
protected void onPostExecute(JSONObject jsonObject) {
|
||||
try{
|
||||
if(result!=null){
|
||||
if(result.getInt("status") == 200){
|
||||
if(jsonObject!=null){
|
||||
if(jsonObject.getInt("status")==404){
|
||||
Toast.makeText(mContext, "User Not Found", Toast.LENGTH_SHORT).show();
|
||||
} else if(jsonObject.getInt("status")==403){
|
||||
Toast.makeText(mContext, "Wrong authentication", Toast.LENGTH_SHORT).show();
|
||||
} else if(jsonObject.getInt("status")==200){
|
||||
Intent walletHomeIntent = new Intent(LoginActivity.this, HomeWalletActivity.class);
|
||||
walletHomeIntent.putExtra("USER_HASH", result.getString("user_hash"));
|
||||
walletHomeIntent.putExtra("USER_HASH", jsonObject.getString("user_hash"));
|
||||
walletHomeIntent.putExtra("USER_PWD",password.getText().toString());
|
||||
walletHomeIntent.putExtra("SESSION_ID","0");
|
||||
walletHomeIntent.putExtra("SESSION_ID",jsonObject.getString("session_id"));
|
||||
LoginActivity.this.startActivity(walletHomeIntent);
|
||||
finish();
|
||||
} else {
|
||||
Toast.makeText(mContext, result.getString("response"), Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(mContext, "AN ERROR OCCURED", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}else{
|
||||
Toast.makeText(mContext, "AN ERROR OCCURED", Toast.LENGTH_SHORT).show();
|
||||
|
@ -94,12 +94,10 @@ public class LoginActivity extends AppCompatActivity {
|
|||
}
|
||||
}
|
||||
@Override
|
||||
protected JSONObject doInBackground(String... params) {
|
||||
protected JSONObject doInBackground(User... u) {
|
||||
try{
|
||||
String url = Config.USER_LOGIN;
|
||||
String[] paramsList = {params[0],params[1]};
|
||||
HttpCallHandler httpCallHandler = new HttpCallHandler(); //TODO UserApiHandler
|
||||
return new JSONObject(httpCallHandler.executeLoginHttp(url,paramsList));
|
||||
UserApiHandler userApiHandler = new UserApiHandler();
|
||||
return userApiHandler.loginUser(u[0]);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
|
|
|
@ -9,15 +9,11 @@ import android.view.View;
|
|||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.monnthic.monnethicmobile.R;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import monnethic.mobile.database.User;
|
||||
import monnethic.mobile.restApi.Config;
|
||||
import monnethic.mobile.restApi.HttpCallHandler;
|
||||
import monnethic.mobile.user.UserAccountActivity;
|
||||
import monnethic.mobile.restApi.UserApiHandler;
|
||||
import monnethic.mobile.wallet.HomeWalletActivity;
|
||||
|
||||
public class RegisterActivity extends AppCompatActivity {
|
||||
private EditText name;
|
||||
|
@ -26,6 +22,7 @@ public class RegisterActivity extends AppCompatActivity {
|
|||
private EditText confirmEmail;
|
||||
private EditText password;
|
||||
private EditText confirmPassword;
|
||||
private EditText phone;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -38,6 +35,7 @@ public class RegisterActivity extends AppCompatActivity {
|
|||
confirmEmail = findViewById(R.id.inputConfEmail);
|
||||
password = findViewById(R.id.inputPassword);
|
||||
confirmPassword = findViewById(R.id.inputConfPassword);
|
||||
phone = findViewById(R.id.inputPhone);
|
||||
Button buttonCancel = findViewById(R.id.buttonCancel);
|
||||
Button buttonOk = findViewById(R.id.buttonOk);
|
||||
|
||||
|
@ -59,9 +57,13 @@ 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())){
|
||||
User inputUser = new User(name.getText().toString(),firstname.getText().toString(),email.getText().toString(),password.getText().toString());
|
||||
}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 {
|
||||
Toast.makeText(this, "User already exist", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -109,18 +111,15 @@ public class RegisterActivity extends AppCompatActivity {
|
|||
private UserRegisterTask(final Context context){mContext=context;}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(JSONObject result){
|
||||
protected void onPostExecute(JSONObject jsonObject){
|
||||
try{
|
||||
if(result!=null){
|
||||
if(result.getInt("status") == 200){
|
||||
System.out.println(result);
|
||||
Intent accountIntent = new Intent(RegisterActivity.this, UserAccountActivity.class);
|
||||
accountIntent.putExtra("userHash", result.getString("userHash"));
|
||||
RegisterActivity.this.startActivity(accountIntent);
|
||||
if(jsonObject!=null){
|
||||
Intent walletHomeIntent = new Intent(RegisterActivity.this, HomeWalletActivity.class);
|
||||
walletHomeIntent.putExtra("USER_HASH", jsonObject.getString("user_hash"));
|
||||
walletHomeIntent.putExtra("USER_PWD",password.getText().toString());
|
||||
walletHomeIntent.putExtra("SESSION_ID",jsonObject.getString("session_id"));
|
||||
RegisterActivity.this.startActivity(walletHomeIntent);
|
||||
finish();
|
||||
}else{
|
||||
Toast.makeText(mContext, result.getString("response"), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}else{
|
||||
Toast.makeText(mContext, "AN ERROR OCCURED", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
@ -132,9 +131,8 @@ public class RegisterActivity extends AppCompatActivity {
|
|||
@Override
|
||||
protected JSONObject doInBackground(User... users) {
|
||||
try{
|
||||
String url = Config.USER_REGISTER;
|
||||
HttpCallHandler httpCallHandler = new HttpCallHandler();
|
||||
return new JSONObject(httpCallHandler.executeRegisterHttp(url,users[0]));
|
||||
UserApiHandler userApiHandler = new UserApiHandler();
|
||||
return userApiHandler.registerUser(users[0]);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
|
|
|
@ -84,6 +84,7 @@ public class HttpCallHandler {
|
|||
while ((line = bufferedReader.readLine())!=null){
|
||||
stringBuilder.append(line);
|
||||
}
|
||||
stringBuilder.append("{\"status\":"+200+"}");
|
||||
returnValue = stringBuilder.toString();
|
||||
}
|
||||
return returnValue;
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
package monnethic.mobile.restApi;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import monnethic.mobile.database.User;
|
||||
|
||||
public class UserApiHandler {
|
||||
|
||||
public JSONObject registerUser(User u){ //return JSON with session ID
|
||||
HttpCallHandler httpCallHandler = new HttpCallHandler();
|
||||
try{
|
||||
String url = Config.USER_REGISTER;
|
||||
Map<String, String> map = new HashMap<>();
|
||||
|
||||
map.put("name",u.getName());
|
||||
map.put("firstname",u.getFirstname());
|
||||
map.put("email",u.getEmail());
|
||||
map.put("phone",u.getPhone());
|
||||
map.put("association",u.getAssociation());
|
||||
map.put("password",u.getPassword());
|
||||
|
||||
String responseCall = httpCallHandler.postHttp(new URL(url), map);
|
||||
JSONObject jsonObject = new JSONObject(responseCall);
|
||||
u.setUser_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"));
|
||||
|
||||
return jsonReturn;
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public JSONObject loginUser(User u){ //return JSON with session ID
|
||||
HttpCallHandler httpCallHandler = new HttpCallHandler();
|
||||
try{
|
||||
String url = Config.USER_LOGIN;
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("email",u.getEmail());
|
||||
map.put("password",u.getPassword());
|
||||
|
||||
String responseCall = httpCallHandler.postHttp(new URL(url), map);
|
||||
JSONObject jsonObject = new JSONObject(responseCall);
|
||||
u.setUser_hash(jsonObject.getString("user_hash"));
|
||||
|
||||
|
||||
JSONObject jsonReturn = new JSONObject();
|
||||
jsonReturn.put("status",jsonObject.getString("status"));
|
||||
jsonReturn.put("user_hash",u.getUser_hash());
|
||||
//jsonReturn.put("session_id",jsonObject.getString("session_id")); //TODO
|
||||
jsonReturn.put("session_id",jsonObject.getString("0"));
|
||||
|
||||
return jsonReturn;
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Boolean checkUser(String email){
|
||||
HttpCallHandler httpCallHandler = new HttpCallHandler();
|
||||
Boolean response=false;
|
||||
try{
|
||||
String url = Config.USER_GET+"?user_email="+email;
|
||||
String responseCall = httpCallHandler.getHttp(new URL(url));
|
||||
response = new JSONObject(responseCall).getBoolean("response");
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
|
@ -31,7 +31,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/textView9"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="65dp"
|
||||
android:layout_marginTop="25dp"
|
||||
|
||||
android:ems="10"
|
||||
android:hint="Name"
|
||||
|
@ -72,11 +72,22 @@
|
|||
android:inputType="textEmailAddress" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/inputPassword"
|
||||
android:id="@+id/inputPhone"
|
||||
android:layout_width="250dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/inputConfEmail"
|
||||
android:layout_alignStart="@+id/inputConfEmail"
|
||||
android:layout_marginTop="11dp"
|
||||
android:ems="10"
|
||||
android:hint="Phone"
|
||||
android:inputType="phone" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/inputPassword"
|
||||
android:layout_width="250dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/inputPhone"
|
||||
android:layout_alignStart="@+id/inputPhone"
|
||||
android:layout_marginTop="13dp"
|
||||
android:ems="10"
|
||||
android:hint="Password"
|
||||
|
@ -96,8 +107,8 @@
|
|||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="40dp"
|
||||
android:layout_marginBottom="20dp">
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginBottom="40dp">
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonOk"
|
||||
|
|
Loading…
Reference in a new issue