Пример #1
0
  public static void saveStylist(Stylist stylist, String password1, String password2) {

    System.out.println("Add saveStylist");

    if (password1.equals(password2)) {
      Account acct = new Account();
      acct.email = stylist.email;
      acct.password = password1;
      acct.type = UserTypes.STYLIST;
      acct.save();

      stylist.acctId = new ObjectId(acct.id.toString());
      stylist.save();
      Salon salon = Salon.read(stylist.salonKey);

      String text =
          "Hi, A stylist how may work at your salon has just created an account with the username "
              + stylist.username
              + " you may wish to add them to your list of stylists.";
      String[] to = {salon.email};
      String from = "*****@*****.**";

      Email msg = new Email(text, to, from, "Stylist just signed up", "Repinzle");
      msg.sendMessage();

      Do.login(acct.email, acct.password);

      View.stylist(stylist.username);
    } else {
      stylist("The passwords entered do not match");
    }
  }
Пример #2
0
  public static void saveSalon(Salon salon, String password1, String password2) {

    System.out.println("Add saveSalon");

    if (password1.equals(password2)) {
      Account acct = new Account();
      acct.email = salon.email;
      acct.password = password1;
      acct.type = UserTypes.SALON;
      acct.save();
      salon.acctId = acct.id;
      salon.save();

      String text =
          "Hi, your Repinzle account has been created. Your temporary password is: "
              + acct.password;
      String[] to = {salon.email};
      String from = "*****@*****.**";

      Email msg = new Email(text, to, from, "Confirm your Repinzle salon account", "Repinzle");
      msg.sendMessage();

      View.salon(salon.key);
    } else {
      salon("The passwords entered do not match");
    }
  }
Пример #3
0
 @Test
 public void findRepostByAccounts_Entity_複数_00() {
   Account acnt1 = Account.findByLoginName("goro_san").first();
   Account acnt2 = Account.findByLoginName("jiro_san").first();
   List<RepostBase> lst = RepostBase.findRepostByAccounts(acnt1, acnt2).fetch();
   assertThat(lst.size(), is(24));
   // DBからの取得リストの並び保証なし
 }
Пример #4
0
 @Test
 public void findRepostByAccounts_Entity_複数_降順_00() {
   Account acnt1 = Account.findByLoginName("goro_san").first();
   Account acnt2 = Account.findByLoginName("jiro_san").first();
   List<RepostBase> lst =
       RepostBase.findRepostByAccounts(acnt1, acnt2)
           .orderBy(RepostBase.OrderBy.DATE_OF_REPOST_DESC)
           .fetch();
   assertThat(lst.size(), is(24));
   assertThat(lst.get(0).contributor.loginUser.screenName, is("goro_san"));
 }
Пример #5
0
 @Test
 public void findRepostByTags_String_単数_投稿者_00() {
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst = RepostBase.findRepostByTags("tag-goro-red").contributor(acnt).fetch();
   assertThat(lst.size(), is(3));
   // DBからの取得リストの並び保証なし
 }
Пример #6
0
  public static void index() {
    Test test = Test.findById(1L);
    Account account = Account.find("byEmail", Security.connected()).first();
    TestResult testResult =
        TestResult.find("test = ? and account = ? order by resultDate desc", test, account).first();

    List<TestResultAttr> lastRes = TestResultAttr.find("byTestResult", testResult).fetch();
    List<String[]> last = getTappingData(lastRes);
    List<TestResultAttr> allRes =
        TestResultAttr.find("testResult.test = ? and testResult.account = ?", test, account)
            .fetch();
    List<String[]> all = getTappingData(allRes);
    @SuppressWarnings("JpaQlInspection")
    Query query =
        JPA.em()
            .createQuery(
                "select t.sortOrder - 1, avg(a.val) "
                    + "from TestResult r, TestResultAttr a, TestAttr t "
                    + "where a.testResult = r and a.testAttr = t and r.test = :test and r.account = :account group by t.sortOrder order by t.sortOrder");
    query.setParameter("test", test);
    query.setParameter("account", account);
    List<String[]> avg = query.getResultList();

    render(account, last, avg, all);
  }
Пример #7
0
 public void doJob() {
   // Check if the database is empty
   if (Account.count() == 0) {
     Fixtures.deleteDatabase();
     Fixtures.loadModels("data.yml");
   }
 }
Пример #8
0
 @Test
 public void findRepostByCategories_String_複数_投稿者_00() {
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst =
       RepostBase.findRepostByCategories("cat-biz", "cat-enta").contributor(acnt).fetch();
   assertThat(lst.size(), is(3));
   // DBからの取得リストの並び保証なし
 }
Пример #9
0
 // -------------------------------------+
 @Test
 public void findRepostByCategories_Entity_単数_投稿者_00() {
   Category cat1 = Category.findBySerialCode("cat-biz").first();
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst = RepostBase.findRepostByCategories(cat1).contributor(acnt).fetch();
   assertThat(lst.size(), is(2));
   // DBからの取得リストの並び保証なし
 }
Пример #10
0
 @Test
 public void findRepostByTweets_String_複数_投稿者_00() {
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst =
       RepostBase.findRepostByTweets("twt-goro2", "twt-jiro1").contributor(acnt).fetch();
   assertThat(lst.size(), is(5));
   // DBからの取得リストの並び保証なし
 }
Пример #11
0
 // -------------------------------------+
 @Test
 public void findRepostByTweets_Entity_単数_投稿者_00() {
   Tweet twt1 = Tweet.findBySerialCode("twt-goro2").first();
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst = RepostBase.findRepostByTweets(twt1).contributor(acnt).fetch();
   assertThat(lst.size(), is(2));
   // DBからの取得リストの並び保証なし
 }
Пример #12
0
 // -------------------------------------+
 @Test
 public void findRepostByUsers_Entity_単数_投稿者_00() {
   User usr1 = User.findBySerialCode("usr-goro").first();
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst = RepostBase.findRepostByUsers(usr1).contributor(acnt).fetch();
   assertThat(lst.size(), is(2));
   // DBからの取得リストの並び保証なし
 }
Пример #13
0
 @Test
 public void findRepostByTags_Entity_複数_投稿者_00() {
   Tag tag1 = Tag.findBySerialCode("tag-goro-red").first();
   Tag tag2 = Tag.findBySerialCode("tag-jiro-hello").first();
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst = RepostBase.findRepostByTags(tag1, tag2).contributor(acnt).fetch();
   assertThat(lst.size(), is(3));
   // DBからの取得リストの並び保証なし
 }
Пример #14
0
  public static void signup(String email, String password1, String password2) {

    Account acct = new Account();
    if (password1.equals(password2)) {
      acct.email = email;
      acct.password = password1;
      acct.type = UserTypes.USER;
      acct.save();
    }

    User user = new User();
    user.acctId = acct.id;
    user.email = email;
    user.save();
    session.put("userid", user.userid.toString());
    session.put("useremail", email);

    Add.user();
  }
Пример #15
0
 @Test
 public void findRepostByCategories_String_複数_投稿者_降順_00() {
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst =
       RepostBase.findRepostByCategories("cat-biz", "cat-enta")
           .contributor(acnt)
           .orderBy(RepostBase.OrderBy.DATE_OF_REPOST_DESC)
           .fetch();
   assertThat(lst.size(), is(3));
   assertThat(lst.get(0).getLabel().serialCode, is("cat-biz"));
 }
Пример #16
0
 @Test
 public void findRepostByTweets_String_複数_投稿者_降順_00() {
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst =
       RepostBase.findRepostByTweets("twt-goro2", "twt-jiro1")
           .contributor(acnt)
           .orderBy(RepostBase.OrderBy.DATE_OF_REPOST_DESC)
           .fetch();
   assertThat(lst.size(), is(5));
   assertThat(lst.get(0).getItem().serialCode, is("twt-jiro1"));
 }
Пример #17
0
 @Test
 public void findRepostByTags_String_複数_投稿者_降順_00() {
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst =
       RepostBase.findRepostByTags("tag-goro-red", "tag-jiro-hello")
           .contributor(acnt)
           .orderBy(RepostBase.OrderBy.DATE_OF_REPOST_DESC)
           .fetch();
   assertThat(lst.size(), is(3));
   assertThat(lst.get(0).getLabel().serialCode, is("tag-goro-red"));
 }
Пример #18
0
 // -------------------------------------+
 @Test
 public void findRepostByUsers_Entity_単数_投稿者_降順_00() {
   User usr1 = User.findBySerialCode("usr-goro").first();
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst =
       RepostBase.findRepostByUsers(usr1)
           .contributor(acnt)
           .orderBy(RepostBase.OrderBy.DATE_OF_REPOST_DESC)
           .fetch();
   assertThat(lst.size(), is(2));
   assertThat(lst.get(0).getItem().serialCode, is("usr-goro"));
 }
  public ChangesStatus transferMoney(
      int account_id_from, int account_id_to, int customer_id_by, int amount)
      throws BelowMinimumBalanceException {

    Connection connection = DBConnectionHelper.getConnection();
    try {
      Account account_1 = new Account();
      account_1 = accountDAO.getObject(connection, account_id_from);

      double newAmount_1 = account_1.getAmount() - amount;
      if (newAmount_1 < BusinessRules.SAVING_ACCOUNT_MIN_BALANCE_AMOUNT) {
        throw new BelowMinimumBalanceException("Below Minimum balance exceed");
      }
      account_1.setAmount(newAmount_1);
      accountDAO.save(connection, account_1);

      Account account_2 = new Account();
      account_2 = accountDAO.getObject(connection, account_id_to);

      double newAmount_2 = account_2.getAmount() + amount;
      account_2.setAmount(newAmount_2);
      accountDAO.save(connection, account_2);

      Transaction transaction = new Transaction();
      transaction.setCustomer_id_by(customer_id_by);
      transaction.setAccount_id(account_id_from);
      transaction.setAccount_id_to(account_id_to);
      transaction.setTransaction_amount(amount);
      transaction.setTransaction_type(3);

      Date date = new Date();
      transaction.setTransaction_time(new Timestamp(date.getTime()));
      transactionDAO.create(connection, transaction);
      // If exception found roll back in catch block
      connection.commit();

      return new ChangesStatus(true, "Successfully Transfered " + amount);

    } catch (NotFoundException e) {
      e.printStackTrace();

    } catch (SQLException e) {
      try {
        e.printStackTrace();
        connection.rollback();
        return new ChangesStatus(false, "Rolledbacked. Transaction Unsuccessful.");
      } catch (SQLException e1) {
        e1.printStackTrace();
        return new ChangesStatus(false, "Unsuccessful Rolledback.");
      }
    } finally {
      try {
        connection.close();
      } catch (SQLException e) {
        e.printStackTrace();
      }
    }
    return null;
  }
Пример #20
0
  public static void saveUser(User user) {

    String userid = session.get("userid");
    String email = session.get("useremail");

    User u = User.read(userid);
    u.realname = user.realname;
    u.stylistUsername = user.stylistUsername;
    u.stylist = Stylist.readByUsername(user.stylistUsername);
    u.save();

    Account acct = Account.read(email);
    Do.login(acct.email, acct.password);

    View.user(u.userid.toString());
  }
  public ChangesStatus withdrawMoney(int account_id, int customer_id_by, int amount, int pin)
      throws BelowMinimumBalanceException {

    Connection connection = DBConnectionHelper.getConnection();

    try {
      Account account = accountDAO.getObject(connection, account_id);

      // Checking Security Pin
      if (!(account.getPin() == pin)) {
        return new ChangesStatus(false, "Security Pin do not match! Transaction Canceled.");
      }

      // Checking Permission
      if (!(PermissionHelper.isThisAccountOwnByThisCustomer(account_id, customer_id_by))) {
        return new ChangesStatus(false, "You do not own this account. Transaction Canceled.");
      }

      double newAmount = account.getAmount() - amount;

      if (newAmount < BusinessRules.SAVING_ACCOUNT_MIN_BALANCE_AMOUNT) {
        throw new BelowMinimumBalanceException("Below Minimum Balance to be left");
      }

      account.setAmount(newAmount);

      accountDAO.save(connection, account);

      Transaction transaction = new Transaction();
      transaction.setCustomer_id_by(customer_id_by);
      transaction.setAccount_id(account_id);
      transaction.setTransaction_amount(amount);
      transaction.setTransaction_type(2);

      Date date = new Date();
      transaction.setTransaction_time(new Timestamp(date.getTime()));
      transactionDAO.create(connection, transaction);
      // If exception found roll back in catch block
      connection.commit();

      return new ChangesStatus(true, "Successfully Withdrawed" + amount);

    } catch (NotFoundException e) {
      e.printStackTrace();
    } catch (SQLException e) {
      try {
        connection.rollback();
        e.printStackTrace();
        return new ChangesStatus(false, "Transaction Rolledbacked. Unsuccessful.");
      } catch (SQLException e1) {
        e1.printStackTrace();
        return new ChangesStatus(false, "Unsuccessful Rolledback.");
      }
    } finally {
      try {
        connection.close();
      } catch (SQLException e) {
        e.printStackTrace();
      }
    }
    return null;
  }
Пример #22
0
  public void onStart(Application app) {

    Logger.info("Application started");
    String uploadPath = Configuration.getUploadPath();
    File file = new File(uploadPath);
    if (!file.exists()) {
      try {
        if (!file.mkdir()) {
          System.out.println(file.getAbsolutePath());
        }
        ;
      } catch (Exception e) {
        e.printStackTrace();
        System.out.println(
            "Error while creating directory for server files, please check 'uploadPath' value in application.conf file");
        System.exit(-1);
      }
    } else {
      if (!file.canRead() || !file.canWrite()) {
        System.out.println(
            "Error: Server have no read and write access to "
                + uploadPath
                + ", please check 'uploadPath' value in application.conf file");
        System.exit(-1);
      }
    }

    // Checking existence of main directory
    String usersFilesDir = Configuration.getUploadPath();
    File applicationDir = new File(usersFilesDir + "/users/");
    if (!applicationDir.exists()) {
      Boolean createAppDir = applicationDir.mkdir();
      if (!createAppDir) {
        Logger.warn("Error while creating users directory");
        System.exit(-1);
      } else {
        Logger.info("Users directory created");
      }
    }

    if (Configuration.isApplyNewLimits()) {
      for (Account account : Account.findAll()) {
        account.setNewLimits();
      }
    }

    if (Configuration.isCreateDefaultUsers()) {
      UserService userService = new UserService(app);
      try {
        Integer nDefault = Configuration.getnDefaultUsers();
        String nameDefault = Configuration.getNameDefaultUser();
        for (int i = 1; i <= nDefault; i++) {
          String username = nameDefault + Integer.toString(i);
          String email = username + "@vdjviz.com";
          LocalUser localUser = LocalUser.find.byId(email);
          if (localUser == null) {
            Option<PasswordHasher> bcrypt = Registry.hashers().get("bcrypt");
            SocialUser socialUser =
                new SocialUser(
                    new IdentityId(email, "userpass"),
                    username,
                    username,
                    String.format("%s %s", username, username),
                    Option.apply(email),
                    null,
                    AuthenticationMethod.UserPassword(),
                    null,
                    null,
                    Some.apply(
                        new PasswordInfo(
                            "bcrypt", BCrypt.hashpw(username, BCrypt.gensalt()), null)));
            userService.doSave(socialUser);
          }
        }
      } catch (RuntimeException e) {
        Logger.error("Error while creating default users");
        e.printStackTrace();
      }
    }

    // Deleting empty files
    for (Account account : Account.findAll()) {
      for (UserFile userFile : account.getUserfiles()) {
        File fileDir = new File(userFile.getDirectoryPath());
        if (!fileDir.exists() || !userFile.checkExist()) {
          UserFile.deleteFile(userFile);
          Logger.of("user." + account.getUserName())
              .warn(
                  "Deleted empty file "
                      + userFile.getFileName()
                      + " for user : "******"user." + account.getUserName())
                              .info("File " + userFile.getFileName() + " was deleted");
                        }
                      }
                    }
                  }
                }
              },
              Akka.system().dispatcher());
    }
  }
Пример #23
0
 // NGな用法 contributorは呼び出してはいけない
 //	@Test(expected = IllegalArgumentException.class)
 @Test(expected = DeprecatedMethodUseException.class)
 public void findRepostByAccounts_例外_01() throws Exception {
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst = RepostBase.findRepostByAccounts("usr-goro").contributor(acnt).fetch();
 }
Пример #24
0
 public static void index() {
   String account_id = session.get("account_id");
   Account account = Account.findById(new Long(account_id));
   render(account);
 }