Esempio n. 1
0
 public boolean updateUser(
     DtoUser dtoUser,
     String firstName,
     String lastName,
     String address,
     String emailAddress,
     String pin,
     DtoUserType dtoUserType,
     DtoUserStatus dtoUserStatus) {
   boolean updated = false;
   try {
     super.open();
     dtoUser.setFirstName(firstName);
     dtoUser.setLastName(lastName);
     dtoUser.setAddress(address);
     dtoUser.setEmailAddress(emailAddress);
     dtoUser.setUserPass(pin.length() > DtoUser.PIN_LENGTH ? pin : SecureUtils.getSecureStr(pin));
     dtoUser.setDtoUserType(dtoUserType);
     dtoUser.setDtoUserStatus(dtoUserStatus);
     this.updateUser(dtoUser);
     updated = true;
   } catch (Exception e) {
     Log.e(TAG, e.getMessage());
     e.printStackTrace();
   } finally {
     super.close();
   }
   return updated;
 }
Esempio n. 2
0
 /**
  * Method to get all users
  *
  * @return List<DtoUser>
  */
 public List<DtoUser> getUsersByUserName(String userName) {
   List<DtoUser> listDtoUser = new ArrayList<DtoUser>();
   try {
     super.open();
     String selectQuery =
         "SELECT * FROM "
             + MySQLiteHelper.TableUser.TABLE_NAME
             + " WHERE upper("
             + MySQLiteHelper.TableUser.COLUMN_USERNAME
             + ") like upper(?)";
     Cursor cursor =
         super.getSqLiteDatabase().rawQuery(selectQuery, new String[] {"%" + userName + "%"});
     cursor.moveToFirst();
     while (!cursor.isAfterLast()) {
       DtoUser dtoUser = cursorToDtoUser(cursor);
       listDtoUser.add(dtoUser);
       cursor.moveToNext();
     }
     cursor.close();
   } catch (Exception e) {
     Log.e(TAG, e.getMessage());
     e.printStackTrace();
   } finally {
     super.close();
   }
   return listDtoUser;
 }
Esempio n. 3
0
 public DtoUser checkUserCredentials(String user, String pass) {
   DtoUser dtoUser = null;
   try {
     super.open();
     dtoUser = this.getUser(user, pass);
   } catch (Exception e) {
     Log.e(TAG, e.getMessage());
     e.printStackTrace();
   } finally {
     super.close();
   }
   return dtoUser;
 }
Esempio n. 4
0
 public boolean existUserName(String userName) {
   DtoUser dtoUser = null;
   try {
     super.open();
     dtoUser = this.getUserByUserName(userName);
   } catch (Exception e) {
     Log.e(TAG, e.getMessage());
     e.printStackTrace();
   } finally {
     super.close();
   }
   return dtoUser != null;
 }
Esempio n. 5
0
 public DtoUser createUser(
     String userName,
     String firstName,
     String lastName,
     String address,
     String emailAddress,
     String pin) {
   DtoUser dtoUser = null;
   try {
     super.open();
     dtoUser = new DtoUser();
     dtoUser.setUserName(userName);
     dtoUser.setFirstName(firstName);
     dtoUser.setLastName(lastName);
     dtoUser.setAddress(address);
     dtoUser.setEmailAddress(emailAddress);
     dtoUser.setUserPass(SecureUtils.getSecureStr(pin));
     dtoUser.setDtoUserType(
         new DtoUserType(
             DtoUserType.Type.BASIC.userType(),
             DtoUserType.Type.BASIC.typeName(),
             DtoUserType.Type.BASIC.description()));
     dtoUser.setDtoUserStatus(
         new DtoUserStatus(
             DtoUserStatus.Status.RECEIVED.status(),
             DtoUserStatus.Status.RECEIVED.statusName(),
             DtoUserStatus.Status.RECEIVED.description()));
     this.addUser(dtoUser);
   } catch (Exception e) {
     dtoUser = null;
     Log.e(TAG, e.getMessage());
     e.printStackTrace();
   } finally {
     super.close();
   }
   return dtoUser;
 }
Esempio n. 6
0
  /** Method to create default user */
  public void createDefaultUser() {
    try {
      super.open();
      super.getSqLiteDatabase().beginTransaction();
      List<DtoUser> listDtoUser = this.getUsers();
      if (listDtoUser.isEmpty()) {
        DtoUser dtoSuperUser = new DtoUser();
        dtoSuperUser.setUserName("ramirezf");
        dtoSuperUser.setUserPass(SecureUtils.getSecureStr("2605"));
        dtoSuperUser.setFirstName("Fernando de Jesus");
        dtoSuperUser.setLastName("Ramirez Mendoza");
        dtoSuperUser.setAddress("Pozo de Cobre 228, Fracc. Pozo Bravo Sur");
        dtoSuperUser.setEmailAddress("*****@*****.**");
        dtoSuperUser.setDtoUserType(
            new DtoUserType(
                DtoUserType.Type.SUPER.userType(),
                DtoUserType.Type.SUPER.typeName(),
                DtoUserType.Type.SUPER.description()));
        dtoSuperUser.setDtoUserStatus(
            new DtoUserStatus(
                DtoUserStatus.Status.ACTIVE.status(),
                DtoUserStatus.Status.ACTIVE.statusName(),
                DtoUserStatus.Status.ACTIVE.description()));

        DtoUser dtoAdminUser = new DtoUser();
        dtoAdminUser.setUserName("ramirezj");
        dtoAdminUser.setUserPass(SecureUtils.getSecureStr("2605"));
        dtoAdminUser.setFirstName("Josue Fernando");
        dtoAdminUser.setLastName("Ramirez Sanchez");
        dtoAdminUser.setAddress("Pozo Blanco 154, Pozo Bravo Norte");
        dtoAdminUser.setEmailAddress("*****@*****.**");
        dtoAdminUser.setDtoUserType(
            new DtoUserType(
                DtoUserType.Type.ADMIN.userType(),
                DtoUserType.Type.ADMIN.typeName(),
                DtoUserType.Type.ADMIN.description()));
        dtoAdminUser.setDtoUserStatus(
            new DtoUserStatus(
                DtoUserStatus.Status.ACTIVE.status(),
                DtoUserStatus.Status.ACTIVE.statusName(),
                DtoUserStatus.Status.ACTIVE.description()));

        DtoUser dtoSalesUser = new DtoUser();
        dtoSalesUser.setUserName("sancheze");
        dtoSalesUser.setUserPass(SecureUtils.getSecureStr("2605"));
        dtoSalesUser.setFirstName("Erika Janette");
        dtoSalesUser.setLastName("Sanchez Gutierrez");
        dtoSalesUser.setAddress("Andador Zenzontle 9206, Pilar Blanco");
        dtoSalesUser.setEmailAddress("*****@*****.**");
        dtoSalesUser.setDtoUserType(
            new DtoUserType(
                DtoUserType.Type.SALES.userType(),
                DtoUserType.Type.SALES.typeName(),
                DtoUserType.Type.SALES.description()));
        dtoSalesUser.setDtoUserStatus(
            new DtoUserStatus(
                DtoUserStatus.Status.ACTIVE.status(),
                DtoUserStatus.Status.ACTIVE.statusName(),
                DtoUserStatus.Status.ACTIVE.description()));

        DtoUser dtoBasicUser = new DtoUser();
        dtoBasicUser.setUserName("sanchezb");
        dtoBasicUser.setUserPass(SecureUtils.getSecureStr("2605"));
        dtoBasicUser.setFirstName("Brenda Yaneth");
        dtoBasicUser.setLastName("Sanchez Gutierrez");
        dtoBasicUser.setAddress("Andador Zenzontle 9206, Pilar Blanco");
        dtoBasicUser.setEmailAddress("*****@*****.**");
        dtoBasicUser.setDtoUserType(
            new DtoUserType(
                DtoUserType.Type.BASIC.userType(),
                DtoUserType.Type.BASIC.typeName(),
                DtoUserType.Type.BASIC.description()));
        dtoBasicUser.setDtoUserStatus(
            new DtoUserStatus(
                DtoUserStatus.Status.ACTIVE.status(),
                DtoUserStatus.Status.ACTIVE.statusName(),
                DtoUserStatus.Status.ACTIVE.description()));

        this.addUser(dtoSuperUser);
        this.addUser(dtoAdminUser);
        this.addUser(dtoSalesUser);
        this.addUser(dtoBasicUser);
        super.getSqLiteDatabase().setTransactionSuccessful();
      }
    } catch (Exception e) {
      Log.e(TAG, e.getMessage());
      e.printStackTrace();
    } finally {
      super.getSqLiteDatabase().endTransaction();
      super.close();
    }
  }