Package org.mapache.ui.admin

Source Code of org.mapache.ui.admin.AdminUserManagementBean

package org.mapache.ui.admin;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import javax.servlet.http.HttpSession;

import org.mapache.business.BusinessController;
import org.mapache.business.MapacheException;
import org.mapache.business.user.User;
import org.mapache.ui.common.MapacheUIUtils;

public class AdminUserManagementBean {
    private BusinessController _bcControl;
    private String _username,_password;
    private boolean _loggedIn;
   
    public AdminUserManagementBean() {
    }
    private BusinessController getBusinessController(){
        if(_bcControl==null)
            _bcControl = new BusinessController();
        return _bcControl;
    }

    public void setUsername(String username) {
        this._username = username;
    }

    public String getUsername() {
        return _username;
    }

    public void setPassword(String password) {
        this._password = password;
    }

    public String getPassword() {
        return _password;
    }

    public String login() {
        User user = new User();
        user.setNickname(_username);
        user.setPassword(_password);
        try {
            _loggedIn = getBusinessController().authenticateUser(user);
        } catch (MapacheException e) {
             FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_ERROR,MapacheUIUtils.getTranslation("error_login",null),MapacheUIUtils.getTranslation("error_login",null)));
        }
        if(_loggedIn){
            return "loginSucces";   
        }
        FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_ERROR,MapacheUIUtils.getTranslation("error_login",null),MapacheUIUtils.getTranslation("error_login",null)));
        return "loginFailed";
    }
    public String logout(){
        ((HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(true)).invalidate();
        _loggedIn = false;
        return "logoutSucces";
    }

    public boolean isloggedIn() {
        return _loggedIn;
    }
}
TOP

Related Classes of org.mapache.ui.admin.AdminUserManagementBean

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.