clean mobile app
This commit is contained in:
parent
e547852d79
commit
22a8886f3f
|
@ -30,7 +30,6 @@
|
|||
</activity>
|
||||
<activity android:name="monnethic.mobile.homepage.RegisterActivity" />
|
||||
<activity android:name="monnethic.mobile.homepage.LoginActivity" />
|
||||
<activity android:name="monnethic.mobile.wallet.WalletActivity" />
|
||||
<activity android:name="monnethic.mobile.user.UserAccountActivity" />
|
||||
<activity android:name="monnethic.mobile.demo.DemoActivity" />
|
||||
<activity android:name="monnethic.mobile.wallet.WalletPresenterActivity" />
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
package monnethic.mobile.database;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import monnethic.mobile.transaction.Transaction;
|
||||
import monnethic.mobile.user.User;
|
||||
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.dao.DaoManager;
|
||||
import com.j256.ormlite.jdbc.JdbcConnectionSource;
|
||||
import com.j256.ormlite.support.ConnectionSource;
|
||||
|
||||
public class DatabaseHelper {
|
||||
private static final String DATABASE_NAME = "monnethic";
|
||||
private static final String DATABASE_USER = "";
|
||||
private static final String DATABASE_PWD = "";
|
||||
private final static String DATABASE_URL = "jdbc:postgresql:///"+DATABASE_NAME;
|
||||
|
||||
|
||||
public ConnectionSource setupDatabaseConnection(){
|
||||
try{
|
||||
return new JdbcConnectionSource(DATABASE_URL, DATABASE_USER, DATABASE_PWD);
|
||||
}catch (Exception e){
|
||||
System.out.print("\n"+e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public void insertTransaction(Transaction tx){
|
||||
try{
|
||||
//Dao<Transaction, Integer> dao = getDao(Transaction.class);
|
||||
//dao.create(tx);
|
||||
} catch(Exception exception){
|
||||
Log.e("DATABASE","Can't insert Transaction into Database", exception);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package monnethic.mobile.database;
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
@DatabaseTable(tableName = "T_TEST")
|
||||
public class DatabaseTest {
|
||||
private static final String NAME_FIELD_NAME = "name";
|
||||
private static final String ID_FIELD_NAME = "id";
|
||||
|
||||
@DatabaseField(columnName = ID_FIELD_NAME, id = true)
|
||||
private int id;
|
||||
@DatabaseField(columnName = NAME_FIELD_NAME, canBeNull = false)
|
||||
private String name;
|
||||
|
||||
public DatabaseTest(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public DatabaseTest() {
|
||||
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
86
app/src/main/java/monnethic/mobile/database/Transaction.java
Normal file
86
app/src/main/java/monnethic/mobile/database/Transaction.java
Normal file
|
@ -0,0 +1,86 @@
|
|||
package monnethic.mobile.database;
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Date;
|
||||
|
||||
public class Transaction {
|
||||
private int transactionId;
|
||||
private long transactionDate;
|
||||
private String transactionFrom;
|
||||
private String transactionTo;
|
||||
private String transactionHash;
|
||||
private Double transactionAmount;
|
||||
private String transactionUnit;
|
||||
|
||||
//Constructors
|
||||
public Transaction(String transactionFrom, String transactionTo, String transactionHash, Double transactionAmount, String transactionUnit) {
|
||||
this.transactionFrom = transactionFrom;
|
||||
this.transactionTo = transactionTo;
|
||||
this.transactionHash = transactionHash;
|
||||
this.transactionAmount = transactionAmount;
|
||||
this.transactionUnit = transactionUnit;
|
||||
}
|
||||
|
||||
public Transaction(int transactionId, long transactionDate, String transactionFrom, String transactionTo, String transactionHash, Double transactionAmount, String transactionUnit) {
|
||||
this.transactionId = transactionId;
|
||||
this.transactionDate = transactionDate;
|
||||
this.transactionFrom = transactionFrom;
|
||||
this.transactionTo = transactionTo;
|
||||
this.transactionHash = transactionHash;
|
||||
this.transactionAmount = transactionAmount;
|
||||
this.transactionUnit = transactionUnit;
|
||||
}
|
||||
|
||||
//Getters and Setters
|
||||
public int getTransactionId() {
|
||||
return transactionId;
|
||||
}
|
||||
public void setTransactionId(int transactionId) {
|
||||
this.transactionId = transactionId;
|
||||
}
|
||||
|
||||
public long getTransactionDate() {
|
||||
return transactionDate;
|
||||
}
|
||||
public void setTransactionDate(long transactionDate) {
|
||||
this.transactionDate = transactionDate;
|
||||
}
|
||||
|
||||
public String getTransactionFrom() {
|
||||
return transactionFrom;
|
||||
}
|
||||
public void setTransactionFrom(String transactionFrom) {
|
||||
this.transactionFrom = transactionFrom;
|
||||
}
|
||||
|
||||
public String getTransactionTo() {
|
||||
return transactionTo;
|
||||
}
|
||||
public void setTransactionTo(String transactionTo) {
|
||||
this.transactionTo = transactionTo;
|
||||
}
|
||||
|
||||
public String getTransactionHash() {
|
||||
return transactionHash;
|
||||
}
|
||||
public void setTransactionHash(String transactionHash) {
|
||||
this.transactionHash = transactionHash;
|
||||
}
|
||||
|
||||
public Double getTransactionAmount() {
|
||||
return transactionAmount;
|
||||
}
|
||||
public void setTransactionAmount(Double transactionAmount) {
|
||||
this.transactionAmount = transactionAmount;
|
||||
}
|
||||
|
||||
public String getTransactionUnit() {
|
||||
return transactionUnit;
|
||||
}
|
||||
public void setTransactionUnit(String transactionUnit) {
|
||||
this.transactionUnit = transactionUnit;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package monnethic.mobile.user;
|
||||
package monnethic.mobile.database;
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
@ -8,32 +8,20 @@ import java.util.Date;
|
|||
* Created by Guillaume on 15/04/2018.
|
||||
*/
|
||||
|
||||
|
||||
//Class User which represent an User in the postgresDB
|
||||
@DatabaseTable(tableName = "T_USER")
|
||||
//Class User which represent an User for api rest
|
||||
public class User {
|
||||
@DatabaseField(canBeNull = false)
|
||||
private int userId;
|
||||
private String name;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private String firstname;
|
||||
@DatabaseField(id = true)
|
||||
private String email;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private String password;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private long creation_date;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private long modification_date;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private boolean verified;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private boolean approved;
|
||||
private String user_hash;
|
||||
|
||||
//Constructors
|
||||
//Default constructor for ORMLite
|
||||
public User() {
|
||||
}
|
||||
|
||||
public User(String name, String firstname, String email, String password) {
|
||||
this.name = name;
|
||||
this.firstname = firstname;
|
||||
|
@ -41,9 +29,11 @@ public class User {
|
|||
this.password = password;
|
||||
}
|
||||
|
||||
public User(String name, String firstname, String email, String password, long creation_date, long modification_date, boolean verified, boolean approved) {
|
||||
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;
|
||||
this.name = name;
|
||||
this.firstname = firstname;
|
||||
this.user_hash = user_hash;
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
this.creation_date = creation_date;
|
||||
|
@ -54,10 +44,12 @@ public class User {
|
|||
|
||||
|
||||
//Getters and Setters
|
||||
public int getUserId(){return userId;}
|
||||
public void setUserId(int userId){this.userId=userId;}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
@ -65,15 +57,16 @@ public class User {
|
|||
public String getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
|
||||
public void setFirstname(String firstname) {
|
||||
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;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
@ -81,7 +74,6 @@ public class User {
|
|||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
@ -89,7 +81,6 @@ public class User {
|
|||
public long getCreation_date() {
|
||||
return creation_date;
|
||||
}
|
||||
|
||||
public void setCreation_date(long creation_date) {
|
||||
this.creation_date = creation_date;
|
||||
}
|
||||
|
@ -97,7 +88,6 @@ public class User {
|
|||
public long getModification_date() {
|
||||
return modification_date;
|
||||
}
|
||||
|
||||
public void setModification_date(long modification_date) {
|
||||
this.modification_date = modification_date;
|
||||
}
|
||||
|
@ -105,7 +95,6 @@ public class User {
|
|||
public boolean isVerified() {
|
||||
return verified;
|
||||
}
|
||||
|
||||
public void setVerified(boolean verified) {
|
||||
this.verified = verified;
|
||||
}
|
||||
|
@ -113,7 +102,6 @@ public class User {
|
|||
public boolean isApproved() {
|
||||
return approved;
|
||||
}
|
||||
|
||||
public void setApproved(boolean approved) {
|
||||
this.approved = approved;
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
package monnethic.mobile.demo;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.example.monnthic.monnethicmobile.R;
|
||||
|
||||
import monnethic.mobile.wallet.WalletPresenterActivity;
|
||||
|
||||
public class DemoActivity extends AppCompatActivity {
|
||||
private static final String WALLET_A = "0x5421c79d465a288c28e10aa43f9b7dff1b313c8e";
|
||||
private static final String WALLET_B = "";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_demo_wallet);
|
||||
Button bWalletA = findViewById(R.id.walletA);
|
||||
Button bWalletB = findViewById(R.id.walletB);
|
||||
|
||||
bWalletA.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
launchWalletPresenterActivity(0);
|
||||
}
|
||||
});
|
||||
bWalletB.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
launchWalletPresenterActivity(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void launchWalletPresenterActivity(int idWallet) {
|
||||
if (idWallet == 0) {
|
||||
Intent demoWalletIntent = new Intent(DemoActivity.this, WalletPresenterActivity.class);
|
||||
demoWalletIntent.putExtra("WALLET_ADDRESS",WALLET_A);
|
||||
DemoActivity.this.startActivity(demoWalletIntent);
|
||||
} else {
|
||||
Intent demoWalletIntent = new Intent(DemoActivity.this, WalletPresenterActivity.class);
|
||||
demoWalletIntent.putExtra("WALLET_ADDRESS","WALLET B");
|
||||
DemoActivity.this.startActivity(demoWalletIntent);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,8 +8,6 @@ import android.widget.Button;
|
|||
|
||||
import com.example.monnthic.monnethicmobile.R;
|
||||
|
||||
import monnethic.mobile.demo.DemoActivity;
|
||||
|
||||
public class HomepageActivity extends AppCompatActivity {
|
||||
//TODO MOVE TO LOGIN ACTIVITY
|
||||
private static final String[] DUMMY_CREDENTIALS = new String[]{
|
||||
|
@ -22,7 +20,6 @@ public class HomepageActivity extends AppCompatActivity {
|
|||
setContentView(R.layout.activity_homepage);
|
||||
Button bRegister = findViewById(R.id.register);
|
||||
Button bLogin = findViewById(R.id.login);
|
||||
//Button bDemo = findViewById(R.id.demo);
|
||||
|
||||
bRegister.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -36,13 +33,6 @@ public class HomepageActivity extends AppCompatActivity {
|
|||
launchLoginActivity();
|
||||
}
|
||||
});
|
||||
/*
|
||||
bDemo.setOnClickListener(new View.OnClickListener(){
|
||||
public void onClick(View view){
|
||||
launchDemoActivity();
|
||||
}
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
public void launchRegisterActivity(){
|
||||
|
@ -53,10 +43,5 @@ public class HomepageActivity extends AppCompatActivity {
|
|||
Intent loginIntent = new Intent(HomepageActivity.this, LoginActivity.class);
|
||||
HomepageActivity.this.startActivity(loginIntent);
|
||||
}
|
||||
/*
|
||||
public void launchDemoActivity(){
|
||||
Intent demoIntent = new Intent(HomepageActivity.this, DemoActivity.class);
|
||||
HomepageActivity.this.startActivity(demoIntent);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ import android.widget.Toast;
|
|||
import com.example.monnthic.monnethicmobile.R;
|
||||
|
||||
import monnethic.mobile.user.UserAccountActivity;
|
||||
import monnethic.mobile.wallet.WalletActivity;
|
||||
|
||||
public class LoginActivity extends AppCompatActivity {
|
||||
|
||||
|
|
|
@ -10,8 +10,8 @@ import android.widget.Toast;
|
|||
|
||||
import com.example.monnthic.monnethicmobile.R;
|
||||
|
||||
import monnethic.mobile.user.User;
|
||||
import monnethic.mobile.wallet.WalletActivity;
|
||||
import monnethic.mobile.database.User;
|
||||
import monnethic.mobile.user.UserAccountActivity;
|
||||
|
||||
public class RegisterActivity extends AppCompatActivity {
|
||||
|
||||
|
@ -78,14 +78,14 @@ public class RegisterActivity extends AppCompatActivity {
|
|||
Toast.makeText(this, "User already have an account, please log in", Toast.LENGTH_SHORT).show();
|
||||
}else {
|
||||
Toast.makeText(this, "INSERT", Toast.LENGTH_SHORT).show();
|
||||
launchWalletActivity(1);
|
||||
launchUserActivity(1);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO LAUNCH WALLET ACTIVITY
|
||||
private void launchWalletActivity(int ldapId){
|
||||
private void launchUserActivity(int ldapId){
|
||||
//LAUNCH APP WALLET WITH ID USER
|
||||
Intent walletIntent = new Intent(RegisterActivity.this, WalletActivity.class);
|
||||
Intent walletIntent = new Intent(RegisterActivity.this, UserAccountActivity.class);
|
||||
walletIntent.putExtra("idUser", ldapId);
|
||||
RegisterActivity.this.startActivity(walletIntent);
|
||||
finish();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
package monnethic.mobile.blockchainApi;
|
||||
package monnethic.mobile.restApi;
|
||||
|
||||
public class UrlApi {
|
||||
public class Config {
|
||||
static public String URL_BALANCE = "http://10.0.2.2:8083/balance?name=";
|
||||
}
|
|
@ -1,106 +0,0 @@
|
|||
package monnethic.mobile.transaction;
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Date;
|
||||
|
||||
@DatabaseTable(tableName = "T_TRANSACTION")
|
||||
public class Transaction {
|
||||
@DatabaseField(columnName = "transactionId", generatedId = true, unique = true)
|
||||
private int id;
|
||||
@DatabaseField(columnName = "transactionDate")
|
||||
private Date transactionDate;
|
||||
@DatabaseField(columnName = "transactionDSrcAddress")
|
||||
private String sourceAddress;
|
||||
@DatabaseField(columnName = "transactionDestAddress")
|
||||
private String destAddress;
|
||||
@DatabaseField(columnName = "transactionHash")
|
||||
private String transactionHash;
|
||||
@DatabaseField(columnName = "transactionBlockNumber")
|
||||
private String blockNumber;
|
||||
@DatabaseField(columnName = "transactionAmout")
|
||||
private BigInteger amount;
|
||||
@DatabaseField(columnName = "transactionUnit")
|
||||
private String unit;
|
||||
|
||||
public Transaction() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Transaction(Date transactionDate, String sourceAddress, String destAddress, String transactionHash, String blockNumber, BigInteger amount, String unit) {
|
||||
super();
|
||||
this.transactionDate = transactionDate;
|
||||
this.sourceAddress = sourceAddress;
|
||||
this.destAddress = destAddress;
|
||||
this.transactionHash = transactionHash;
|
||||
this.blockNumber = blockNumber;
|
||||
this.amount = amount;
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
public String getSourceAddress() {
|
||||
return sourceAddress;
|
||||
}
|
||||
|
||||
public void setSourceAddress(String sourceAddress) {
|
||||
this.sourceAddress = sourceAddress;
|
||||
}
|
||||
|
||||
public String getDestAddress() {
|
||||
return destAddress;
|
||||
}
|
||||
|
||||
public void setDestAddress(String destAddress) {
|
||||
this.destAddress = destAddress;
|
||||
}
|
||||
|
||||
public String getTransactionHash() {
|
||||
return transactionHash;
|
||||
}
|
||||
|
||||
public void setTransactionHash(String transactionHash) {
|
||||
this.transactionHash = transactionHash;
|
||||
}
|
||||
|
||||
public BigInteger getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(BigInteger amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Date getTransactionDate() {
|
||||
return transactionDate;
|
||||
}
|
||||
|
||||
public void setTransactionDate(Date transactionDate) {
|
||||
this.transactionDate = transactionDate;
|
||||
}
|
||||
|
||||
public String getUnit() {
|
||||
return unit;
|
||||
}
|
||||
|
||||
public void setUnit(String unit) {
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
public String getBlockNumber() {
|
||||
return blockNumber;
|
||||
}
|
||||
|
||||
public void setBlockNumber(String blockNumber) {
|
||||
this.blockNumber = blockNumber;
|
||||
}
|
||||
}
|
|
@ -17,14 +17,14 @@ import java.io.InputStreamReader;
|
|||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
import monnethic.mobile.blockchainApi.UrlApi;
|
||||
import monnethic.mobile.restApi.Config;
|
||||
import monnethic.mobile.transaction.MakePayementActivity;
|
||||
import monnethic.mobile.transaction.ReceivePayementActivity;
|
||||
|
||||
public class UserAccountActivity extends AppCompatActivity {
|
||||
|
||||
private TextView balance;
|
||||
private String strUrl = UrlApi.URL_BALANCE+"b";
|
||||
private String strUrl = Config.URL_BALANCE+"b";
|
||||
private String result;
|
||||
|
||||
@Override
|
||||
|
@ -80,7 +80,7 @@ public class UserAccountActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
public void refreshBalance(String userHash){
|
||||
String url = UrlApi.URL_BALANCE+userHash;
|
||||
String url = Config.URL_BALANCE+userHash;
|
||||
new GetUserBalanceTask().execute(url);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,119 +0,0 @@
|
|||
package monnethic.mobile.user;
|
||||
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.dao.DaoManager;
|
||||
import com.j256.ormlite.stmt.PreparedQuery;
|
||||
import com.j256.ormlite.stmt.QueryBuilder;
|
||||
import com.j256.ormlite.stmt.UpdateBuilder;
|
||||
import java.sql.Timestamp;
|
||||
import monnethic.mobile.database.DatabaseHelper;
|
||||
|
||||
//Class to communicate with database with ORMLite
|
||||
public class UserDao {
|
||||
private DatabaseHelper dbh = new DatabaseHelper();
|
||||
private Dao<User, String> userDao;
|
||||
|
||||
public Dao createUserDaoConnection(){
|
||||
try {
|
||||
return DaoManager.createDao(dbh.setupDatabaseConnection(),User.class);
|
||||
}catch (Exception e){
|
||||
System.out.println(e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void addUser(User user)throws Exception {
|
||||
userDao = createUserDaoConnection();
|
||||
userDao.create(user);
|
||||
}
|
||||
|
||||
public boolean checkApprovedUser(String email) throws Exception {
|
||||
userDao = createUserDaoConnection();
|
||||
QueryBuilder<User, String> queryBuilder = userDao.queryBuilder();
|
||||
queryBuilder.where().eq("email",email);
|
||||
PreparedQuery<User> preparedQuery = queryBuilder.prepare();
|
||||
User user = userDao.queryForFirst(preparedQuery);
|
||||
return user.isApproved();
|
||||
}
|
||||
|
||||
public boolean checkVerifiedUser(String email) throws Exception {
|
||||
userDao = createUserDaoConnection();
|
||||
QueryBuilder<User, String> queryBuilder = userDao.queryBuilder();
|
||||
queryBuilder.where().eq("email",email);
|
||||
PreparedQuery<User> preparedQuery = queryBuilder.prepare();
|
||||
User user = userDao.queryForFirst(preparedQuery);
|
||||
return user.isVerified();
|
||||
}
|
||||
|
||||
public boolean updateUserPassword(String email, String password) throws Exception {
|
||||
userDao = createUserDaoConnection();
|
||||
UpdateBuilder<User, String> updateBuilder = userDao.updateBuilder();
|
||||
updateBuilder.updateColumnValue("password",password);
|
||||
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
|
||||
updateBuilder.updateColumnValue("modification_date",timestamp.getTime());
|
||||
updateBuilder.where().eq("email",email);
|
||||
updateBuilder.update();
|
||||
|
||||
if(checkUserPassword(email, password)){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean verifyUserExist(String email) throws Exception {
|
||||
userDao = createUserDaoConnection();
|
||||
QueryBuilder<User, String> queryBuilder = userDao.queryBuilder();
|
||||
queryBuilder.where().eq("email",email);
|
||||
PreparedQuery<User> preparedQuery = queryBuilder.prepare();
|
||||
User user = userDao.queryForFirst(preparedQuery);
|
||||
|
||||
if(user==null){
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean checkUserPassword(String email, String password) throws Exception {
|
||||
User user = getUser(email);
|
||||
if(password.equals(user.getPassword())){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public User getUser(String email) throws Exception {
|
||||
if(!verifyUserExist(email)){
|
||||
return null;
|
||||
}else{
|
||||
userDao = createUserDaoConnection();
|
||||
QueryBuilder<User, String> queryBuilder = userDao.queryBuilder();
|
||||
queryBuilder.where().eq("email",email);
|
||||
PreparedQuery<User> preparedQuery = queryBuilder.prepare();
|
||||
return userDao.queryForFirst(preparedQuery);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void approveUser (String email) throws Exception{
|
||||
userDao = createUserDaoConnection();
|
||||
UpdateBuilder<User, String> updateBuilder = userDao.updateBuilder();
|
||||
updateBuilder.updateColumnValue("approved",true);
|
||||
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
|
||||
updateBuilder.updateColumnValue("modification_date",timestamp.getTime());
|
||||
updateBuilder.where().eq("email",email);
|
||||
updateBuilder.update();
|
||||
}
|
||||
public void verifyUser (String email) throws Exception{
|
||||
userDao = createUserDaoConnection();
|
||||
UpdateBuilder<User, String> updateBuilder = userDao.updateBuilder();
|
||||
updateBuilder.updateColumnValue("verified",true);
|
||||
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
|
||||
updateBuilder.updateColumnValue("modification_date",timestamp.getTime());
|
||||
updateBuilder.where().eq("email",email);
|
||||
updateBuilder.update();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
package monnethic.mobile.wallet;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.monnthic.monnethicmobile.R;
|
||||
|
||||
import monnethic.mobile.user.UserAccountActivity;
|
||||
|
||||
public class WalletActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_wallet);
|
||||
|
||||
Button buttonCreate = findViewById(R.id.buttonCreateWallet);
|
||||
Button buttonRestore = findViewById(R.id.buttonRestoreWallet);
|
||||
Button buttonSkip = findViewById(R.id.buttonSkip);
|
||||
|
||||
buttonCreate.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
createWallet();
|
||||
}
|
||||
});
|
||||
buttonRestore.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
restoreWallet();
|
||||
}
|
||||
});
|
||||
buttonSkip.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
skip();
|
||||
}
|
||||
});
|
||||
}
|
||||
public void skip(){
|
||||
Intent userIntent = new Intent(WalletActivity.this, UserAccountActivity.class);
|
||||
WalletActivity.this.startActivity(userIntent);
|
||||
finish();
|
||||
}
|
||||
public void createWallet(){
|
||||
Toast.makeText(this, "Coming soon", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
public void restoreWallet(){
|
||||
Toast.makeText(this, "Coming soon", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.constraint.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<Button
|
||||
android:id="@+id/walletA"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="WALLET A"
|
||||
app:layout_constraintBottom_toTopOf="@+id/walletB"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.782" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/walletB"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="192dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:text="WALLET B"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/presenter_Demo"
|
||||
android:layout_width="137dp"
|
||||
android:layout_height="23dp"
|
||||
android:layout_marginBottom="68dp"
|
||||
android:layout_marginEnd="120dp"
|
||||
android:text="WALLET FOR DEMO"
|
||||
app:layout_constraintBottom_toTopOf="@+id/walletA"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
</android.support.constraint.ConstraintLayout>
|
|
@ -1,49 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="119dp"
|
||||
android:text="Generate or Restore wallet" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/versionApp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:text="version v0.1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonCreateWallet"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/textView2"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="83dp"
|
||||
android:text="Create Wallet" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonRestoreWallet"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignStart="@+id/buttonCreateWallet"
|
||||
android:layout_below="@+id/buttonCreateWallet"
|
||||
android:layout_marginTop="54dp"
|
||||
android:text="RESTORE WALLET" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonSkip"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="35dp"
|
||||
android:layout_alignStart="@+id/buttonRestoreWallet"
|
||||
android:layout_below="@+id/buttonRestoreWallet"
|
||||
android:text="SKIP"
|
||||
android:textSize="8sp" />
|
||||
</RelativeLayout>
|
|
@ -1,27 +0,0 @@
|
|||
package monnethic.mobile.test.database;
|
||||
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.dao.DaoManager;
|
||||
import org.junit.Test;
|
||||
import monnethic.mobile.database.DatabaseHelper;
|
||||
import monnethic.mobile.database.DatabaseTest;
|
||||
|
||||
|
||||
//Testing class for postgresql connection
|
||||
public class DatabaseHelperTest {
|
||||
private DatabaseHelper dbh = new DatabaseHelper();
|
||||
|
||||
//Test connection by getting existing data in T_TEST
|
||||
@Test
|
||||
public void TestConnection(){
|
||||
Dao<DatabaseTest, Integer> testDao;
|
||||
try{
|
||||
testDao = DaoManager.createDao(dbh.setupDatabaseConnection(),DatabaseTest.class);
|
||||
DatabaseTest dbt = testDao.queryForId(1);
|
||||
assert dbt != null;
|
||||
assert "thomas".equals(dbt.getName());
|
||||
}catch (Exception e){
|
||||
System.out.println("\n"+e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,147 +0,0 @@
|
|||
package monnethic.mobile.test.user;
|
||||
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.table.TableUtils;
|
||||
|
||||
import org.junit.Test;
|
||||
import java.sql.Timestamp;
|
||||
import monnethic.mobile.user.User;
|
||||
import monnethic.mobile.user.UserDao;
|
||||
|
||||
public class UserDaoTest {
|
||||
private UserDao udao = new UserDao();
|
||||
private final String USER_EMAIL = "thomas.marshal@gmail.com";
|
||||
private final String USER_PASSWORD = "avcde";
|
||||
|
||||
@Test
|
||||
public void TestACreateTable(){
|
||||
try{
|
||||
Dao<User, String> userDao;
|
||||
userDao = udao.createUserDaoConnection();
|
||||
TableUtils.createTable(userDao);
|
||||
}catch(Exception e){
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestBInsertUser(){
|
||||
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
|
||||
User user = new User("marshal","thomas",USER_EMAIL,USER_PASSWORD,timestamp.getTime(),timestamp.getTime(),false,false);
|
||||
try{
|
||||
udao.addUser(user);
|
||||
}catch(Exception e){
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestCGetGeneratedUser(){
|
||||
try{
|
||||
User uTest = udao.getUser(USER_EMAIL);
|
||||
if(uTest==null){
|
||||
System.out.println("User don't Exist");
|
||||
}else {
|
||||
System.out.println(uTest.getEmail());
|
||||
}
|
||||
}catch(Exception e){
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestDCheckApprovedUser(){
|
||||
try{
|
||||
boolean response = udao.checkApprovedUser(USER_EMAIL);
|
||||
if(response){
|
||||
System.out.println("Approved");
|
||||
}else{
|
||||
System.out.println("Not Approved");
|
||||
}
|
||||
}catch(Exception e){
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestECheckVerifiedUser(){
|
||||
try{
|
||||
boolean response = udao.checkVerifiedUser(USER_EMAIL);
|
||||
if(response){
|
||||
System.out.println("Verified");
|
||||
}else{
|
||||
System.out.println("Not Verified");
|
||||
}
|
||||
}catch(Exception e){
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestFCheckUserPassword(){
|
||||
try{
|
||||
boolean response = udao.checkUserPassword(USER_EMAIL,USER_PASSWORD);
|
||||
if(response){
|
||||
System.out.println("Password OK");
|
||||
}else{
|
||||
System.out.println("Password Failed");
|
||||
}
|
||||
}catch(Exception e){
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestGUpdateUserPassword(){
|
||||
String newPassword = "newPassword";
|
||||
try{
|
||||
boolean response = udao.updateUserPassword(USER_EMAIL,newPassword);
|
||||
if(response){
|
||||
System.out.println("Password Changed");
|
||||
}else{
|
||||
System.out.println("Password Update Failed");
|
||||
}
|
||||
}catch(Exception e){
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestHApproveVerifyUser(){
|
||||
try{
|
||||
udao.approveUser(USER_EMAIL);
|
||||
udao.verifyUser(USER_EMAIL);
|
||||
}catch(Exception e){
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestICheckApprovedUser(){
|
||||
try{
|
||||
boolean response = udao.checkApprovedUser(USER_EMAIL);
|
||||
if(response){
|
||||
System.out.println("Approved");
|
||||
}else{
|
||||
System.out.println("Not Approved");
|
||||
}
|
||||
}catch(Exception e){
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestJCheckVerifiedUser(){
|
||||
try{
|
||||
boolean response = udao.checkVerifiedUser(USER_EMAIL);
|
||||
if(response){
|
||||
System.out.println("Verified");
|
||||
}else{
|
||||
System.out.println("Not Verified");
|
||||
}
|
||||
}catch(Exception e){
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue