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());
}
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;
}
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);
}
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);
}
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);
}
}
}
}
Aggregations