Exemplo n.º 1
0
 @PUT
 @Path("changepswd")
 public Response changePassword(final User user) {
   User userFound = null;
   final EntityManager em = emf.createEntityManager();
   if (UserType.EMAIL.equals(user.getUserType())) {
     userFound = UserUtil.findUserByKeyAndType(em, user.getEmail(), user.getUserType().name());
   } else if (UserType.MOBILE.equals(user.getUserType())) {
     userFound =
         UserUtil.findUserByKeyAndType(em, user.getPhoneNumber(), user.getUserType().name());
   }
   if (userFound != null) {
     final User userEntity = userFound;
     userEntity.setPassword(user.getPassword());
     TransactionManager.manage(
         new Transactional(em) {
           @Override
           public void transact() {
             em.merge(userEntity);
           }
         });
     return Response.ok(AuthenticationConstants.UPDATESUCCESS).build();
   } else {
     String[] keysForLog = {user.getEmail(), user.getPhoneNumber(), user.getUserType().name()};
     Logger.getLogger(UsersResource.class.getName())
         .log(
             Level.INFO,
             "Change password faild: mail: {0}, phoneNumber: {1}, userType: {2}.",
             keysForLog);
     return Response.ok(AuthenticationConstants.UPDATEFAILURE).build();
   }
 }
Exemplo n.º 2
0
 private boolean userExist(String registerKey, UserType userType) {
   String[] authenticateKeysForLog = {registerKey, userType.name()};
   Logger.getLogger(UsersResource.class.getName())
       .log(
           Level.INFO,
           "######### Check if user exists: registerKey: {0}, userType: {1}.",
           authenticateKeysForLog);
   EntityManager em = emf.createEntityManager();
   if (UserType.MOBILE.equals(userType)) {
     Query queryQ = em.createNamedQuery("User.findByPhoneNumber");
     queryQ.setParameter("phoneNumber", registerKey);
     return !queryQ.getResultList().isEmpty();
   }
   if (UserType.DUDU.equals(userType)) {
     Query queryQ = em.createNamedQuery("User.findByUserId");
     queryQ.setParameter("userId", registerKey);
     return !queryQ.getResultList().isEmpty();
   }
   if (UserType.QQ.equals(userType)) {
     Query queryQ = em.createNamedQuery("User.findByQQ");
     queryQ.setParameter("qq", registerKey);
     return !queryQ.getResultList().isEmpty();
   }
   if (UserType.WEIBO.equals(userType)) {
     Query queryQ = em.createNamedQuery("User.findByWeibo");
     queryQ.setParameter("weibo", registerKey);
     return !queryQ.getResultList().isEmpty();
   }
   if (UserType.EMAIL.equals(userType)) {
     Query queryQ = em.createNamedQuery("User.findByEmail");
     queryQ.setParameter("email", registerKey);
     return !queryQ.getResultList().isEmpty();
   }
   return true;
 }