Package uk.org.woodcraft.bookings.datamodel

Examples of uk.org.woodcraft.bookings.datamodel.User


    CannedQueries.save(orgWcf);
   
    Unit unit1 = new Unit(TestConstants.UNIT1_NAME, orgWcf, true);
    CannedQueries.save(unit1);
   
    User rootUser = new User("globaladmin@example.com", "Global Admin 1", "password", Accesslevel.GLOBAL_ADMIN);
    rootUser.setOrganisationKey(orgWcf.getKeyCheckNotNull());
    rootUser.setUnitKey(unit1.getKeyCheckNotNull());
    CannedQueries.save(rootUser);

    User orgUser = new User("orgbooking@example.com", "Org Booking Secretary 1", "password", Accesslevel.ORG_ADMIN);
    orgUser.setOrganisationKey(orgWcf.getKeyCheckNotNull());
    orgUser.setUnitKey(unit1.getKeyCheckNotNull());
    CannedQueries.save(orgUser);

    User unitUser = new User("unitbooking@example.com", "Unit Booking Secretary 1", "password", Accesslevel.UNIT_ADMIN);
    unitUser.setOrganisationKey(orgWcf.getKeyCheckNotNull());
    unitUser.setUnitKey(unit1.getKeyCheckNotNull());
    CannedQueries.save(unitUser);
   
   
    // And don't let this be repeated!
    AppSetting setupCompleteSetting = new AppSetting(AppSetting.SETUP_COMPLETE, "true");
View Full Code Here


  private String processLoginAttempt(HttpServletRequest request, HttpSession session) {
   
      String email = request.getParameter(LOGIN_EMAIL);
      String password = request.getParameter(LOGIN_PASSWORD);

      User user = CannedQueries.getUserByEmail(email);
      if (user != null && user.getAccessLevel().getCanLogin()
          && user.checkPassword(password))
    {
        if (!user.getApproved() )
          return "User has not yet been approved for login. Please wait until you are sent an email approving access to the booking system.";
       
        if (!user.getEmailValidated() )
          return "Your email has not been validated. Please check your inbox for a message from the booking system.";
       
       
          // The user has successfully logged in. Store their user object in
          // their HttpSession, and their home org and unit. Then return true.
          session.setAttribute(SessionConstants.USER_HANDLE, user);
          SessionUtils.setCurrentUserDetails(session,  AppSetting.getDefaultEvent(), user.getOrganisation(), user.getUnit());
         
          return "";
      } else {
          // The user did not successfully log in. Return false.
View Full Code Here

      transactions.add(new Transaction(unit1.getKeyCheckNotNull(), event1.getKeyCheckNotNull(), afterEarlyBird.getTime(), TransactionType.Payment, "Payment after earlybird", "", 10.00d));
      transactions.add(new Transaction(unit1.getKeyCheckNotNull(), event1.getKeyCheckNotNull(), afterEarlyBird.getTime(), TransactionType.Discount, "Discount for early payment", "", 5.00d));
      pm.makePersistentAll(transactions);
     
      // Users
      User user1 = new User(TestConstants.USER_ADMIN_EMAIL, "Global Admin 1", "password", Accesslevel.GLOBAL_ADMIN);
      user1.setOrganisationKey(orgWcf.getKeyCheckNotNull());
      user1.setUnitKey(unit1.getKeyCheckNotNull());
     
     
      User user2 = new User("orgadmin@example.com", "Org Admin 1", "password", Accesslevel.ORG_ADMIN);
      user2.setOrganisationKey(orgWcf.getKeyCheckNotNull());
      user2.setUnitKey(unit1.getKeyCheckNotNull());
     
      User user3 = new User("unitadmin@example.com", "Unit Admin 1", "password", Accesslevel.UNIT_ADMIN);
      user3.setOrganisationKey(orgWcf.getKeyCheckNotNull());
      user3.setUnitKey(unit1.getKeyCheckNotNull());
     
      User user4 = new User("unassigned@example.com", "Unassigned 1", "password", Accesslevel.UNIT_ADMIN);
      user4.setOrganisationKey(orgWcf.getKeyCheckNotNull());
      user4.setUnitKey(unit2.getKeyCheckNotNull());
      user4.setApproved(false);
     
      User user5 = new User("otherorg@example.com", "Other Org 1", "password", Accesslevel.ORG_ADMIN);
      user5.setOrganisationKey(otherOrg.getKeyCheckNotNull());
      user5.setUnitKey(otherOrgUnit2.getKeyCheckNotNull());
     
      pm.makePersistentAll(user1, user2, user3, user4, user5);
   
     
      // Application settings
View Full Code Here

      signup.prepare();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    signup.setEmail(email);
    User user = signup.getModel();
    user.setEmail(email);
    user.setName("New user");
    user.setPassword(password);
    assertEquals(ActionSupport.SUCCESS, signup.processSignup());
   
    // Confirm email received
    // can't easily do this
   
    User testUser = CannedQueries.getUserByEmail(email);
    assertEquals(false, testUser.getEmailValidated());
   
    ConfirmEmailAction confirmAction = new ConfirmEmailAction();
    confirmAction.setEmail(email);
    confirmAction.setHash("badhash");
   
    // Confirm failed
    assertEquals (ActionSupport.INPUT, confirmAction.execute());
    testUser = CannedQueries.getUserByEmail(email);
    assertEquals(false, testUser.getEmailValidated());
   
   
    confirmAction.setHash(SignupUtils.generateEmailConfirmHash(testUser));
    assertEquals (ActionSupport.SUCCESS,confirmAction.execute());
   
    // Confirm succeeded 
    testUser = CannedQueries.getUserByEmail(email);
    assertEquals(true, testUser.getEmailValidated());
    assertEquals(false, testUser.getApproved());
    testUser = CannedQueries.getUserByEmail(email);
    assertEquals(Accesslevel.UNIT_ADMIN, testUser.getAccessLevel());
    assertTrue(testUser.checkPassword(password));
  }
View Full Code Here

  public void testCantSignUpExistingUser()
  {
    String email = "newuser@example.com";
    String password = "testpassword";
   
    User existingUser = new User(email, "Existing user", password, Accesslevel.ORG_ADMIN);
    CannedQueries.save(existingUser);
   
    SignupAction signup = new SignupAction();
    try {
      signup.prepare();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    signup.setEmail(email);
    User user = signup.getModel();
    user.setEmail(email);
    user.setName("New user");
    user.setPassword(password);
    assertEquals(ActionSupport.INPUT, signup.processSignup());
   
    assertEquals("Existing user", CannedQueries.getUserByEmail(email).getName());
  }
View Full Code Here

    // If this is a new unit / org, anyone can touch it, since they can be created in signup
    if(checkOrg != null && checkOrg.isNew()) permitted = true;
    if(checkUnit != null && checkUnit.isNew()) permitted = true;
    if(checkUser != null && checkUser.isNew()) permitted = true;
   
    User user = SessionUtils.currentUser(false);
   
    if (user != null) {
      switch (user.getAccessLevel()) {
      case GLOBAL_ADMIN:
        permitted = true;
        break;
       
      case ORG_ADMIN:
        if(checkOrg != null && checkOrg.equals(user.getOrganisation())) permitted = true;
        if(checkUnit != null && checkUnit.getOrganisationKey().equals(user.getOrganisationKey())) permitted = true;
        if(checkUser != null && checkUser.getOrganisationKey().equals(user.getOrganisationKey())) permitted = true;
        if(checkBooking != null)
        {
          Unit unit= CannedQueries.unitByKey(checkBooking.getUnitKey());
          if (unit.getOrganisationKey().equals(user.getOrganisationKey())) permitted = true;
        }
      case UNIT_ADMIN:
        if(user.getUnit().equals(checkUnit)) permitted = true;
        if(checkUser != null && checkUser.getUnitKey().equals(user.getUnitKey())) permitted = true;
        if(checkBooking != null && checkBooking.getUnitKey().equals(user.getUnitKey())) permitted = true;
      default:
        if (user.equals(checkUser)) permitted = true;
      }
    }
   

   
View Full Code Here

   
    if (!apiSitekey.equals(actualApiKey))
      return false;
   
    // Note apiUsername is an email for these purposes
      User user = CannedQueries.getUserByEmail(apiUsername);
      if (user != null && user.getAccessLevel().equals(Accesslevel.API)
          && user.checkPassword(apiPassword))
      {
        return true;
      }
    return false;
  }
View Full Code Here

  }
 
  public String processSignup(){
   
    if(getModel() != null) {
      User existingUser = CannedQueries.getUserByEmail(getModel().getEmail());
      if (existingUser != null)
      {
        addActionError("A user with that email address already exists.");
        return INPUT;
      }
View Full Code Here

   
    // Default to user added values
   
    if (getModel() == null)
    {
      User user = new User();
      user.setIsNew(true);
     
      Organisation selectedOrg = (Organisation)getSessionObject(SessionConstants.SIGNUP_ORG);
      if (selectedOrg != null)
        user.setOrganisationKey(selectedOrg.getKey());
     
      Unit selectedUnit = (Unit)getSessionObject(SessionConstants.SIGNUP_UNIT);
      if (selectedUnit != null)
        user.setUnitKey(selectedUnit.getKey());
     
      setModel(user);
    }
  }
View Full Code Here

    assertDetached(bookings);
  }
 
  @Test
  public void testUserByEmail() {
    User user1 = CannedQueries.getUserByEmail("globaladmin@example.com");
    assertEquals("Global Admin 1", user1.getName());
    assertDetached(user1);
   
    User user2 = CannedQueries.getUserByEmail("orgadmin@example.com");
    assertEquals("Org Admin 1", user2.getName());
  }
View Full Code Here

TOP

Related Classes of uk.org.woodcraft.bookings.datamodel.User

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.