Search in sources :

Example 51 with User

use of org.mamute.model.User in project mamute by caelum.

the class EditAnswerTest method should_edit_and_automatically_approve_author_edit.

@Test
public void should_edit_and_automatically_approve_author_edit() throws Exception {
    Question question = createQuestionWithDao(moderator(), "Titulo da questao hahaha", "Descricao da questao longa demais", tag("java"));
    User karmaNigga = karmaNigga();
    Answer answer = answerQuestionWithDao(karmaNigga, question, "Resposta da questao do teste de edicao", false);
    String newDescription = "my new description of the first answer";
    UserFlow navigation = login(navigate(), karmaNigga.getEmail());
    navigation = editAnswerWithFlow(navigation, answer, newDescription, "comment");
    VRaptorTestResult answerEdited = navigation.followRedirect().execute();
    answerEdited.wasStatus(200).isValid();
    List<String> messagesList = messagesList(answerEdited);
    assertTrue(messagesList.contains(message("status.no_need_to_approve")));
    AnswerAndVotes answerAndVotes = answerEdited.getObject("answers");
    List<Answer> answers = new ArrayList<Answer>(answerAndVotes.getVotes().keySet());
    assertEquals(newDescription, answers.get(0).getDescription());
}
Also used : Answer(org.mamute.model.Answer) User(org.mamute.model.User) UserFlow(br.com.caelum.vraptor.test.requestflow.UserFlow) ArrayList(java.util.ArrayList) Question(org.mamute.model.Question) AnswerAndVotes(org.mamute.model.AnswerAndVotes) VRaptorTestResult(br.com.caelum.vraptor.test.VRaptorTestResult) Test(org.junit.Test)

Example 52 with User

use of org.mamute.model.User in project mamute by caelum.

the class DbAuthenticator method authenticate.

public boolean authenticate(String email, String password) {
    User retrieved = users.findByMailAndPassword(email, password);
    if (retrieved == null) {
        retrieved = users.findByMailAndLegacyPasswordAndUpdatePassword(email, password);
    }
    if (retrieved == null) {
        return false;
    }
    system.login(retrieved);
    return true;
}
Also used : User(org.mamute.model.User)

Example 53 with User

use of org.mamute.model.User in project mamute by caelum.

the class LDAPApi method createUserIfNeeded.

private void createUserIfNeeded(LDAPResource ldap, String cn) throws LdapException {
    Entry ldapUser = ldap.getUser(cn);
    String email = ldap.getAttribute(ldapUser, emailAttr);
    User user = users.findByEmail(email);
    if (user == null) {
        String fullName = ldap.getAttribute(ldapUser, nameAttr);
        if (isNotEmpty(surnameAttr)) {
            fullName += " " + ldap.getAttribute(ldapUser, surnameAttr);
        }
        user = new User(fromTrustedText(fullName.trim()), email);
        LoginMethod brutalLogin = LoginMethod.brutalLogin(user, email, PLACHOLDER_PASSWORD);
        user.add(brutalLogin);
        users.save(user);
        loginMethods.save(brutalLogin);
    }
    // update moderator status
    if (isNotEmpty(moderatorGroup) && ldap.getGroups(ldapUser).contains(moderatorGroup)) {
        user = user.asModerator();
    } else {
        user.removeModerator();
    }
    updateAvatarImage(ldap, ldapUser, user);
    users.save(user);
}
Also used : Entry(org.apache.directory.api.ldap.model.entry.Entry) User(org.mamute.model.User) LoginMethod(org.mamute.model.LoginMethod)

Example 54 with User

use of org.mamute.model.User in project mamute by caelum.

the class CommentAnswerTest method login.

@Before
public void login() {
    DaoManager manager = new DaoManager();
    User author = manager.randomUser();
    Question question = manager.createQuestion(author);
    manager.answerQuestion(author, question);
}
Also used : User(org.mamute.model.User) Question(org.mamute.model.Question) DaoManager(org.mamute.integration.util.DaoManager) Before(org.junit.Before)

Example 55 with User

use of org.mamute.model.User in project mamute by caelum.

the class LdapSSOFilter method checkSSO.

public void checkSSO(@Observes MethodReady methodReady) {
    if (env.supports(LDAPApi.LDAP_SSO) && !loggedUser.isLoggedIn() && request.getRequestURI() != null && !request.getRequestURI().endsWith("/logout")) {
        String userName = request.getRemoteUser();
        if (userName != null && ldap.authenticateSSO(userName)) {
            String email = ldap.getEmail(userName);
            User retrieved = users.findByEmail(email);
            if (retrieved != null) {
                system.login(retrieved);
            }
        }
    }
}
Also used : User(org.mamute.model.User) LoggedUser(org.mamute.model.LoggedUser)

Aggregations

User (org.mamute.model.User)97 Test (org.junit.Test)56 Question (org.mamute.model.Question)28 LoggedUser (org.mamute.model.LoggedUser)25 VRaptorTestResult (br.com.caelum.vraptor.test.VRaptorTestResult)9 UserFlow (br.com.caelum.vraptor.test.requestflow.UserFlow)9 Answer (org.mamute.model.Answer)9 LoginMethod (org.mamute.model.LoginMethod)9 Post (br.com.caelum.vraptor.Post)7 Before (org.junit.Before)7 Tag (org.mamute.model.Tag)7 QuestionInformation (org.mamute.model.QuestionInformation)6 Email (org.apache.commons.mail.Email)5 UserPersonalInfo (org.mamute.dto.UserPersonalInfo)5 ReputationEvent (org.mamute.model.ReputationEvent)5 ArrayList (java.util.ArrayList)4 Watcher (org.mamute.model.watch.Watcher)4 DateTime (org.joda.time.DateTime)3 Elements (org.jsoup.select.Elements)3 DaoManager (org.mamute.integration.util.DaoManager)3