Package com.nevernote.service.jpa

Source Code of com.nevernote.service.jpa.UsersServiceImpl

package com.nevernote.service.jpa;

import java.util.List;

import org.jasypt.util.password.BasicPasswordEncryptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.google.common.collect.Lists;
import com.nevernote.domain.Users;
import com.nevernote.repository.UsersRepository;
import com.nevernote.service.UsersService;

@Service("usersService")
@Repository
@Transactional
public class UsersServiceImpl implements UsersService {

  final static Logger logger = LoggerFactory.getLogger(UsersServiceImpl.class);

  @Autowired
  private UsersRepository usersRepository;

  @Transactional(readOnly = true)
  @Override
  public List<Users> findAll() {
    logger.info("---------- Finding all contacts ----------");
    return Lists.newArrayList(usersRepository.findAll());
  }

  @Transactional(readOnly = true)
  @Override
  public Users findById(String id) {
    logger.info("---------- Finding contact with ID: {} ----------", id);
    return usersRepository.findOne(id);
  }

  @Override
  public Users save(String id, Users user) {
    return usersRepository.save(user);
  }

  @Override
  public Users loginCheck(String id, String pass) {
       
    Users validate = usersRepository.findOne(id);
   
    BasicPasswordEncryptor passwordEncryptor = new BasicPasswordEncryptor();
    if ((validate != null && validate.getEnabled()) && passwordEncryptor.checkPassword(pass, validate.getPassword())){
      return validate;
    } else{
      return null;
    }
  }

  @Override
  public boolean changePassword(String id, String password) {
    Users userUpdate;
    BasicPasswordEncryptor passwordEncryptor = new BasicPasswordEncryptor();
    userUpdate = usersRepository.findOne(id);
    if (userUpdate == null || !userUpdate.getEnabled()){
      return false;
    } else {
      userUpdate.setPassword(passwordEncryptor.encryptPassword(password));
      save(userUpdate.getId(), userUpdate);
    }

    return true;
  }
}
TOP

Related Classes of com.nevernote.service.jpa.UsersServiceImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.