Search in sources :

Example 6 with User

use of models.User in project modules.playframework.org by playframework.

the class AllowToVote method isAllowed.

@Override
public boolean isAllowed(String name, String meta, DeadboltHandler deadboltHandler, Http.Context ctx) {
    boolean allowed = true;
    if (StringUtils.isEmpty(meta)) {
        Logger.error("HasVoted required a moduleKey in the meta data");
    } else {
        User user = (User) deadboltHandler.getRoleHolder(ctx);
        if (user != null) {
            for (Iterator<Vote> iterator = user.votes.iterator(); allowed && iterator.hasNext(); ) {
                Vote vote = iterator.next();
                allowed = !meta.equals(vote.playModule.key);
            }
        }
    }
    return allowed;
}
Also used : Vote(models.Vote) User(models.User)

Example 7 with User

use of models.User in project modules.playframework.org by playframework.

the class UserServices method createUser.

public User createUser(String userName, String displayName, String password, List<UserRole> roles) {
    User user = new User();
    user.userName = userName;
    user.displayName = displayName;
    user.password = password;
    user.accountActive = true;
    user.roles = new ArrayList<UserRole>(roles);
    user.rates = new ArrayList<Rate>();
    user.save();
    user.saveManyToManyAssociations("roles");
    return user;
}
Also used : User(models.User) UserRole(models.UserRole) Rate(models.Rate)

Example 8 with User

use of models.User in project play-cookbook by spinscale.

the class SolrSearchTest method testQuery.

@Test
public void testQuery() {
    List<User> users = new Query("name:alex", User.class).fetch();
    assertEquals(1, users.size());
    assertEquals("alex", users.get(0).name);
}
Also used : User(models.User) Query(play.modules.solr.Query) SolrQuery(org.apache.solr.client.solrj.SolrQuery) UnitTest(play.test.UnitTest) Test(org.junit.Test)

Example 9 with User

use of models.User in project play-cookbook by spinscale.

the class SolrSearchTest method simpleUserTest.

@Test
public void simpleUserTest() throws Exception {
    SolrQuery query = new SolrQuery();
    query.setQuery("name:alex");
    QueryResponse rp = server.query(query);
    SolrDocumentList results = rp.getResults();
    assertEquals(1, results.size());
    assertEquals("alex", results.get(0).getFieldValue("name"));
    User u = User.find("byName", "alex").first();
    assertEquals(u.getClass().getName() + ":" + u.id.toString(), results.get(0).getFieldValue("id"));
}
Also used : User(models.User) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrDocumentList(org.apache.solr.common.SolrDocumentList) SolrQuery(org.apache.solr.client.solrj.SolrQuery) UnitTest(play.test.UnitTest) Test(org.junit.Test)

Example 10 with User

use of models.User in project play-cookbook by spinscale.

the class RegistrationServiceImpl method triggerEmail.

@Override
public void triggerEmail(Object context) {
    if (context instanceof User) {
        User user = (User) context;
        Registration registration = Registration.find("byUser", user).first();
        Mails.sendConfirmation(registration);
    }
}
Also used : User(models.User) Registration(models.Registration)

Aggregations

User (models.User)30 CurrentUser (actions.CurrentUser)7 CurrentUser.currentUser (actions.CurrentUser.currentUser)7 Test (org.junit.Test)7 Result (play.mvc.Result)7 Module (models.Module)6 UnitTest (play.test.UnitTest)6 RoleHolderPresent (be.objectify.deadbolt.actions.RoleHolderPresent)5 Vote (models.Vote)4 EntityManager (javax.persistence.EntityManager)3 Rate (models.Rate)3 Registration (models.Registration)3 SolrQuery (org.apache.solr.client.solrj.SolrQuery)3 Transactional (com.google.inject.persist.Transactional)2 VoteResponseForm (forms.modules.VoteResponseForm)2 Query (javax.persistence.Query)2 Article (models.Article)2 ModuleVersion (models.ModuleVersion)2 PlayVersion (models.PlayVersion)2 Tweet (models.Tweet)2