Log In | Get Help   
Home My Page Projects Code Snippets Project Openings Accounting and Billing Portal
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files
[abportal] View of /src/main/java/eu/smartlm/abs/portal/security/login/service/LoginServiceImpl.java
[abportal] / src / main / java / eu / smartlm / abs / portal / security / login / service / LoginServiceImpl.java Repository:
ViewVC logotype

View of /src/main/java/eu/smartlm/abs/portal/security/login/service/LoginServiceImpl.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (download) (annotate)
Wed Jul 28 10:05:51 2010 UTC (13 years, 9 months ago) by dgarcia
File size: 2886 byte(s)
First code commit
package eu.smartlm.abs.portal.security.login.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import eu.smartlm.abs.portal.security.login.dao.UserDao;
import eu.smartlm.abs.portal.security.login.model.User;

/**
 * This is the default implementation of the LoginService interface to access to all the users information
 * @author David García Pérez - CESGA
 *
 */
@Service(value="myLoginService")
public class LoginServiceImpl implements LoginService {
		
	@Autowired
	@Qualifier("userDao")
	private UserDao userDao;

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
	
	public LoginServiceImpl() {
		
	}
	
	/**
	 * If the user has valid credentials it gives back a <code>true</code> value
	 * @param user User credentials
	 * @return <code>true</code> if the User credentials are valid, <code>false</code> otherwise 
	 */
	public boolean isValidLogin(User user) {
		User userFromDatabase = userDao.getUser(user.getUsername());
		
		if(userFromDatabase != null ) return true;
		else return false;
	}

	/**
	 * Gets a list of all users that can log in into the server
	 * @return a list of all users
	 */
	public List<User> getUsers() {
		return userDao.getUsers();
	}

	/**
	 * Adds a user to the database
	 * @param user user to be added
	 * @return code if a user was successfully added or the error message
	 */
	public int addUser(User user) {
		if(user.getUsername() == null) {
			return LoginService.WRONG_USERNAME;
		} else if(user.getUsername().isEmpty()) {
			return LoginService.WRONG_USERNAME;
		} else	if(user.getPassword() == null) {
			return LoginService.WRONG_PASSWORD;
		} else if(user.getPassword().isEmpty()) {
			return LoginService.WRONG_PASSWORD;
		} else if(isValidLogin(user)) {
			return LoginService.USER_ALREADY_EXISTS;
		} else {
			int code = userDao.addUser(user);
			if(code == UserDao.USER_ADDED)
				return LoginService.USER_SUCCESSFULLY_ADDED;
			else return 0;
		}
	}

	/**
	 * Gets user by username
	 * @param username 
	 * @return
	 */
	public User getUser(String username) {
		
		return userDao.getUser(username);
	}

	/**
	 * Edits the data of an specific user
	 * @param userXedited username of the user to be edit
	 * @return code if a user was succesfully edited or the error message
	 */
	public int editUser(User user) {
		if(user.getPassword() == null) {
			return LoginService.WRONG_PASSWORD;
		} else if(user.getPassword().isEmpty()) {
			return LoginService.WRONG_PASSWORD;
		} else {
			userDao.editUser(user);
			return LoginService.USER_SUCCESSFULLY_EDITED;
		}
	}

	/**
	 * Removes a user vi its username
	 * @param username
	 */
	public void removeUser(String username) {
		if(userDao.getUser(username) != null)
			userDao.removeUser(username);
	}
}

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge