public Integer savePasswordChanged(ChangePassword cp) {
   Md5PasswordEncoder passwordEncoder = new Md5PasswordEncoder();
   cp.setPassword(passwordEncoder.encodePassword(cp.getPassword(), null));
   cp.setNewpassword(passwordEncoder.encodePassword(cp.getNewpassword(), null));
   Query query =
       new Query(Criteria.where("id").is(cp.getUserid()).and("password").is(cp.getPassword()));
   Users usr = mongoTemplate.findOne(query, Users.class);
   if (null != usr) {
     usr.setPassword(cp.getNewpassword());
     usr.setModifiedDate(new Date());
     userRepository.save(usr);
     return 1;
   } else {
     return 0;
   }
 }
  public int resetAndSavePassword(String email) {
    Users user = userRepository.findByEmail(email);
    if (null == user) {
      return 0;
    } else {

      Random randomGenerator = new Random();
      int randomInt = randomGenerator.nextInt(100000);

      Md5PasswordEncoder passwordEncoder = new Md5PasswordEncoder();
      user.setPassword(passwordEncoder.encodePassword(randomInt + "", null));

      userRepository.save(user);
      return randomInt;
    }
  }
  public String save(Users users) {
    // System.out.println("users.getjoinedid:::: "+users.getJoinedid());
    if (StringUtils.isNotEmpty(users.getId())) {
      Users userstmp = getUserForEdit(users.getId());
      userstmp.setColorTheme(users.getColorTheme());
      userstmp.setName(users.getName());
      userstmp.setEmail(users.getEmail());
      userstmp.setModifiedDate(new Date());
      users = userstmp;
    } else {
      if (userRepository.findByUsername(users.getUsername()) != null) {
        return "username";
      } else if (userRepository.findByEmail(users.getEmail()) != null) {
        return "email";
      }
      Md5PasswordEncoder passwordEncoder = new Md5PasswordEncoder();
      users.setPassword(passwordEncoder.encodePassword(users.getPassword(), null));
      users.setCreatedDate(new Date());
      users.setModifiedDate(new Date());
    }

    userRepository.save(users);
    return "save";
  }