Search in sources :

Example 1 with UserRegistration

use of org.onebusaway.users.services.internal.UserRegistration in project onebusaway-application-modules by camsys.

the class UserIndexRegistrationServiceImpl method setRegistrationForUserIndexKey.

@Override
public void setRegistrationForUserIndexKey(UserIndexKey key, int userId, String registrationCode) {
    Element element = new Element(key, new UserRegistration(userId, registrationCode));
    _cache.put(element);
}
Also used : Element(net.sf.ehcache.Element) UserRegistration(org.onebusaway.users.services.internal.UserRegistration)

Example 2 with UserRegistration

use of org.onebusaway.users.services.internal.UserRegistration in project onebusaway-application-modules by camsys.

the class UserServiceImplTest method testCompletePhoneNumberRegistration.

@Test
public void testCompletePhoneNumberRegistration() {
    User userA = createUser(1234);
    UserIndexKey key = new UserIndexKey(UserIndexTypes.PHONE_NUMBER, "12065551234");
    UserDao userDao = Mockito.mock(UserDao.class);
    _service.setUserDao(userDao);
    Mockito.when(userDao.getUserForId(1234)).thenReturn(userA);
    UserIndex migratedIndex = new UserIndex();
    migratedIndex.setId(key);
    migratedIndex.setUser(userA);
    migratedIndex.setCredentials("");
    Mockito.when(userDao.getUserIndexForId(key)).thenReturn(migratedIndex);
    UserIndexRegistrationService registrationService = Mockito.mock(UserIndexRegistrationService.class);
    _service.setUserIndexRegistrationService(registrationService);
    UserRegistration registration = new UserRegistration(1234, "5555");
    Mockito.when(registrationService.getRegistrationForUserIndexKey(key)).thenReturn(registration);
    UserPropertiesService userPropertiesService = Mockito.mock(UserPropertiesService.class);
    _service.setUserPropertiesService(userPropertiesService);
    User userB = createUser(1235);
    UserIndex index = createUserIndex(key.getType(), key.getValue(), userB);
    UserIndex updated = _service.completePhoneNumberRegistration(index, "5554");
    assertTrue(updated == null);
    updated = _service.completePhoneNumberRegistration(index, "5555");
    assertTrue(updated != null);
    Mockito.verify(userPropertiesService).mergeProperties(userB, userA);
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) User(org.onebusaway.users.model.User) UserIndexRegistrationService(org.onebusaway.users.services.internal.UserIndexRegistrationService) UserDao(org.onebusaway.users.services.UserDao) UserPropertiesService(org.onebusaway.users.services.UserPropertiesService) UserRegistration(org.onebusaway.users.services.internal.UserRegistration) Test(org.junit.Test)

Example 3 with UserRegistration

use of org.onebusaway.users.services.internal.UserRegistration in project onebusaway-application-modules by camsys.

the class UserServiceImpl method completePhoneNumberRegistration.

@Override
public UserIndex completePhoneNumberRegistration(UserIndex userIndex, String registrationCode) {
    UserRegistration registration = _userIndexRegistrationService.getRegistrationForUserIndexKey(userIndex.getId());
    if (registration == null)
        return null;
    String expectedCode = registration.getRegistrationCode();
    if (!expectedCode.equals(registrationCode))
        return null;
    /**
     * At this point, we have a valid registration code. We may safely clear the
     * registration
     */
    _userIndexRegistrationService.clearRegistrationForUserIndexKey(userIndex.getId());
    User targetUser = _userDao.getUserForId(registration.getUserId());
    if (targetUser == null)
        return null;
    User phoneUser = userIndex.getUser();
    /**
     * If the user index is already registered, our work is done
     */
    if (phoneUser.equals(targetUser))
        return userIndex;
    /**
     * If the phone user only has one index (the phoneNumber index), we merge
     * the phone user with the registration target user. Otherwise, we keep the
     * phone user, but just transfer the phone index
     */
    if (phoneUser.getUserIndices().size() == 1) {
        mergeUsers(userIndex.getUser(), targetUser);
    } else {
        userIndex.setUser(targetUser);
        targetUser.getUserIndices().add(userIndex);
        phoneUser.getUserIndices().remove(userIndex);
        _userDao.saveOrUpdateUsers(phoneUser, targetUser);
    }
    // Refresh the user index
    return getUserIndexForId(userIndex.getId());
}
Also used : User(org.onebusaway.users.model.User) UserRegistration(org.onebusaway.users.services.internal.UserRegistration)

Aggregations

UserRegistration (org.onebusaway.users.services.internal.UserRegistration)3 User (org.onebusaway.users.model.User)2 Element (net.sf.ehcache.Element)1 Test (org.junit.Test)1 UserIndex (org.onebusaway.users.model.UserIndex)1 UserIndexKey (org.onebusaway.users.model.UserIndexKey)1 UserDao (org.onebusaway.users.services.UserDao)1 UserPropertiesService (org.onebusaway.users.services.UserPropertiesService)1 UserIndexRegistrationService (org.onebusaway.users.services.internal.UserIndexRegistrationService)1