Package org.j2cms.service.impl

Source Code of org.j2cms.service.impl.UserServiceImpl

package org.j2cms.service.impl;

import javax.persistence.Query;

import org.j2cms.model.user.User;
import org.j2cms.service.UserService;
import org.j2cms.service.base.DaoSupport;
import org.j2cms.utils.MD532;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service @Transactional
public class UserServiceImpl extends DaoSupport<User> implements UserService {
  public boolean validate(String username, String password){
    long count = (Long)em.createQuery("select count(o) from User o where o.username=?1 and o.password=?2")
    .setParameter(1, username).setParameter(2, new MD532().getMD5(password)).getSingleResult();
    return count>0;
  }
  public User findByUsername(String username){
    Query query =em.createQuery("select o from User o where o.username=?1").setParameter(1, username);
    if(query.getResultList().size()==0 ){
            return null;
        }else{
            return (User) query.getSingleResult();
        }

  }
  public boolean checkUsername(String username){
    Query query =em.createQuery("select o from User o where o.username=?1").setParameter(1, username);
    if(query.getResultList().size()==0 ){
            return false;
        }else{
            return true;
        }
  }

}
TOP

Related Classes of org.j2cms.service.impl.UserServiceImpl

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.