package com.ds.listing.services;

import com.ds.listing.model.User;

import java.util.ArrayList;

import javax.ejb.Singleton;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

@Singleton
public class UserService {
  
    @PersistenceContext(unitName="primary")
    private EntityManager em;
  
    public User login(String userName, String password){
        System.out.println(userName);
        System.out.println(password);
        try{
            Query query = em.createQuery("select u from User u where  u.name = :username AND u.failed < 4").setParameter("username", userName);
            User current = (User)query.getSingleResult();
            if(current.getPassword() == password){
                return current;
            }else{
                current.setFailed(current.getFailed()+1);
                return null;
            }
        }catch (Exception e){
            return null;
        }
  }
  
}

@@ -416,84 +416,8 @@
 d)%7B%0A
-        System.out.println(userName);%0A        System.out.println(password);%0A
     
@@ -425,16 +425,16 @@
    try%7B%0A
+
         
@@ -627,16 +627,89 @@
 sult();%0A
+            System.out.println(current.getId()+%22 - %22+current.getName());%0A
         
@@ -903,16 +903,16 @@
       %7D%0A
-
         
@@ -933,16 +933,66 @@
 ion e)%7B%0A
+            System.out.println(%22error occurred%22);%0A
         

fix query