Search in sources :

Example 1 with UserPersonalInfo

use of org.mamute.dto.UserPersonalInfo in project mamute by caelum.

the class UserProfileController method editProfile.

@Post
public void editProfile(@Load User user, SanitizedText name, String email, SanitizedText website, SanitizedText location, DateTime birthDate, MarkedText description, boolean isSubscribed, boolean receiveAllUpdates) {
    if (!user.getId().equals(currentUser.getCurrent().getId())) {
        result.redirectTo(ListController.class).home(null);
        return;
    }
    if (website != null) {
        website = correctWebsite(website);
    }
    UserPersonalInfo info = new UserPersonalInfo(user).withName(name).withEmail(email).withWebsite(website).withLocation(location).withBirthDate(birthDate).withAbout(description).withReceiveAllUpdates(receiveAllUpdates).withIsSubscribed(isSubscribed);
    if (!infoValidator.validate(info)) {
        infoValidator.onErrorRedirectTo(this).editProfile(user);
        return;
    }
    users.updateLoginMethod(user, email);
    user.setPersonalInformation(info);
    result.redirectTo(this).showProfile(user, user.getSluggedName());
}
Also used : UserPersonalInfo(org.mamute.dto.UserPersonalInfo) Post(br.com.caelum.vraptor.Post)

Example 2 with UserPersonalInfo

use of org.mamute.dto.UserPersonalInfo in project mamute by caelum.

the class UserPersonalInfoValidatorTest method should_not_validate_user_trying_to_update_name_before_allowed_time.

@Test
public void should_not_validate_user_trying_to_update_name_before_allowed_time() {
    User artur = user("artur com seis caracteres", validEmail);
    UserPersonalInfo info = new UserPersonalInfo(artur).withName(fromTrustedText("newName")).withEmail(artur.getEmail());
    when(bundle.getMessage("date.joda.simple.pattern")).thenReturn("dd/MM/YYYY");
    assertFalse(infoValidator.validate(info));
}
Also used : User(org.mamute.model.User) UserPersonalInfo(org.mamute.dto.UserPersonalInfo) Test(org.junit.Test)

Example 3 with UserPersonalInfo

use of org.mamute.dto.UserPersonalInfo in project mamute by caelum.

the class UserPersonalInfoValidatorTest method should_pass_validation_with_not_required_elements_null.

@Test
public void should_pass_validation_with_not_required_elements_null() {
    User artur = user("artur com seis caracteres", validEmail);
    UserPersonalInfo info = new UserPersonalInfo(artur).withName(fromTrustedText(artur.getName())).withEmail(artur.getEmail());
    assertTrue(infoValidator.validate(info));
}
Also used : User(org.mamute.model.User) UserPersonalInfo(org.mamute.dto.UserPersonalInfo) Test(org.junit.Test)

Example 4 with UserPersonalInfo

use of org.mamute.dto.UserPersonalInfo in project mamute by caelum.

the class UserPersonalInfoValidatorTest method should_not_validate_null_user.

@Test
public void should_not_validate_null_user() {
    UserPersonalInfo info = new UserPersonalInfo(null);
    assertFalse(infoValidator.validate(info));
}
Also used : UserPersonalInfo(org.mamute.dto.UserPersonalInfo) Test(org.junit.Test)

Example 5 with UserPersonalInfo

use of org.mamute.dto.UserPersonalInfo in project mamute by caelum.

the class UserPersonalInfoValidatorTest method should_not_validate_under_twelve_years_old_user.

@Test
public void should_not_validate_under_twelve_years_old_user() {
    User artur = user("artur com seis caracteres", validEmail);
    DateTime hoje = DateTime.now();
    UserPersonalInfo info = new UserPersonalInfo(artur).withName(fromTrustedText(artur.getName())).withEmail(artur.getEmail()).withBirthDate(hoje);
    assertFalse(infoValidator.validate(info));
}
Also used : User(org.mamute.model.User) UserPersonalInfo(org.mamute.dto.UserPersonalInfo) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

UserPersonalInfo (org.mamute.dto.UserPersonalInfo)7 Test (org.junit.Test)6 User (org.mamute.model.User)5 DateTime (org.joda.time.DateTime)2 Post (br.com.caelum.vraptor.Post)1