Hello, I have a problem. When a user types in his usename and
password, then hits a Validate button, i'd like to check whether the
String couple he just typed matches anything in a database.
I do that by calling execute() which is within the LoginCommand class
which implements Command.
However, it doesn't work, and I can't even run it as GWT hosted mode
application, I get the following error :
Failed to load module
Errors in 'file:/home/..../command/LoginCommand.java'
Line 42 : No source code is available for type .../LogonServiceImpl;
did you forget to inherit a required module ?
(Line 42 : LogonServiceImpl logservice = new LogonServiceImpl();)


___________________________________________________________________________
___________________________________________________________________________


package com.enseirb.projecthandler.client.command;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.enseirb.projecthandler.server.servlet.LogonServiceImpl;
import com.enseirb.projecthandler.client.object.SerializableUser;
import com.enseirb.projecthandler.client.service.LogonService;
import com.enseirb.projecthandler.client.service.LogonServiceAsync;
import com.enseirb.projecthandler.client.view.Login;
import com.enseirb.projecthandler.client.view.Menu;
import com.enseirb.projecthandler.server.mapping.HibernateUtil;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;

public class LoginCommand implements Command {
        private Login logSystem;

        public void execute(){
                //Gets informations on an onclick event
                final String login = logSystem.getUsername();
        final String pass = logSystem.getPassword();

        //Gets the service and specifies its name
        LogonServiceAsync logonService = (LogonServiceAsync) GWT.create
(LogonService.class);
        ServiceDefTarget endpoint = (ServiceDefTarget) logonService;
        String moduleRelativeURL = GWT.getModuleBaseURL() + "logon";
        endpoint.setServiceEntryPoint(moduleRelativeURL);

        //Creates callback
        AsyncCallback callback = new AsyncCallback() {
            public void onFailure(Throwable caught) {
                Window.alert("Login process failed !");
            }
            public void onSuccess(Object result) {
                SerializableUser user = (SerializableUser) result;
                if (user!=null) {
                        LogonServiceImpl logservice = new LogonServiceImpl();
                        user = logservice.checkLogin(login, pass);

                        if(user.getStatus().equals("admin")){
                                logSystem.setLogin();
                                Command home = new ViewHomeCommand();
                        }
                        else if(user.getStatus().equals("student")){
                                logSystem.setLogin();
                                Command cmd = new LogStudentCommand();
                        }
                        else if(user.getStatus().equals("teacher")){
                                logSystem.setLogin();
                                Command cmd = new ShowCaseCommand(1);
                        }
                }
                else {//Maybe useless... to be checked
                        logSystem = null;
                        Window.alert("Invalid login/password !");
                }
            }
        };
        logonService.checkLogin(login, pass, callback);
        }

        public LoginCommand(Login login){
                logSystem = login;
        }
}




_____________________________________________________________________________
_____________________________________________________________________________




package com.enseirb.projecthandler.server.servlet;

import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.hibernate.Session;
import com.enseirb.projecthandler.client.object.SerializableUser;
import com.enseirb.projecthandler.client.service.LogonService;
import com.enseirb.projecthandler.server.mapping.HibernateUtil;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/*
 * Implementation of our service interface with a server-side servlet
 */

public class LogonServiceImpl extends RemoteServiceServlet
implements LogonService{


        private HttpSession getSession() {
                // Get the current request and then return its session
                return this.getThreadLocalRequest().getSession();
        }

        @Override
        public SerializableUser checkLogin(String login, String password) {
                // TODO Check login and password from a database
                // return user from database if match

                //Connection to database
                Session session = 
HibernateUtil.getSessionFactory().openSession();
                List users = session.createQuery("from User").list();
                SerializableUser[] userlist = new 
SerializableUser[users.size()];

                for(Integer i=0;i<userlist.length;i++){

                        if(userlist[i].getLogin().equals(login) && 
userlist[i].getPassword
().equals(password)){
                                SerializableUser user = new 
SerializableUser(userlist[i].getLogin
(),
                                                
userlist[i].getLogin()+"@enseirb.fr", userlist[i].getStatus(),
userlist[i].getPassword());
                                
getThreadLocalRequest().getSession().setAttribute("user", user);
                                HttpSession sessionObj = 
getThreadLocalRequest().getSession();

                                return user;
                        }
                }
                return null;
        }
}


_____________________________________________________________________________
_____________________________________________________________________________




package com.enseirb.projecthandler.client.service;

import com.enseirb.projecthandler.client.object.SerializableUser;
import com.google.gwt.user.client.rpc.RemoteService;

/*
 * Interface of service which checks login
 * @param login
 * @param password
 * returns corresponding user if the couple is correct
 */

public interface LogonService extends RemoteService{

        SerializableUser checkLogin(String username, String password);
}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to