Package business

Examples of business.User


        String forwardUrl;
        String pageTitle;
        String action = RequestHelper.getString( "action", request );
        RequestDispatcher dispatcher;
        HashMap<String, String> formErrors;
        User authUser = bzb.getAuthenticatedUser( request );

        /* Load necessary lexicons */
        bzb.getLexicon().load( "global" );
        bzb.getLexicon().load( "subject" );
        bzb.getLexicon().load( "register" );
View Full Code Here


        return errors;
    }

    private User saveUser( HttpServletRequest request ) {
        User authUser = bzb.getAuthenticatedUser( request, true );
       
        authUser.init( bzb.getDriver() );
        authUser.setAddress( RequestHelper.getString( "address", request ) );
        authUser.setBirthDate( util.Util.parseDate( RequestHelper.getString( "birthDate", request ) ) );
        authUser.setCity( RequestHelper.getString( "city", request ) );
        authUser.setFirstName( RequestHelper.getString( "firstName", request ) );
        authUser.setLastName( RequestHelper.getString( "lastName", request ) );
        authUser.setPhone( RequestHelper.getString( "phone", request ) );
        authUser.setPostalCode( RequestHelper.getString( "postalCode", request ) );
        authUser.setState( RequestHelper.getString( "state", request ) );

        if( !RequestHelper.getString( "newEmail", request ).isEmpty() ) {
            authUser.setEmail( RequestHelper.getString( "newEmail", request ) );
        }
        if( !RequestHelper.getString( "newPassword", request ).isEmpty() ) {
            authUser.setPassword( DigestHelper.md5( RequestHelper.getString( "newPassword", request ) ) );
        }

        authUser.save();

        return authUser;
    }
View Full Code Here

    @Override
    protected void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
        bzb = new BooksZenBooks( "en", dbConfigResource ); // @TODO language should be a request param
        String forwardUrl = jspPath + "home";
        RequestDispatcher dispatcher;
        User user = bzb.getAuthenticatedUser( request );

        /* Load necessary lexicons */
        bzb.getLexicon().load( "global" );
        bzb.getLexicon().load( "checkout" );
        bzb.getLexicon().load( "subject" );
View Full Code Here

    protected void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
        bzb = new BooksZenBooks( "en", dbConfigResource ); // @TODO language should be a request param
        String action = RequestHelper.getString( "action", request );
        String forwardUrl;
        RequestDispatcher dispatcher;
        User user;

        /* Load necessary lexicons */
        bzb.getLexicon().load( "global" );
        bzb.getLexicon().load( "register" );
        bzb.getLexicon().load( "subject" );

        /* Handle logout request */
        if( action.equals( "logout" ) ) {
            forwardUrl = jspPath + "/loggedOut.jsp";

            endSession( request, response );
        }
        /* Handle login request */
        else if( action.equals( "login" ) ) {
            /* Already logged in? */
            if( bzb.getAuthenticatedUser( request ) != null ) {
                forwardUrl = "/home";
            }
            else {
                /* Verify email and password */
                user = checkCredentials( request );

                /* No matching user */
                if( user == null ) {
                    forwardUrl = jspPath + "login.jsp";

                    request.setAttribute( "pageTitle", bzb.getLexicon().get( "logIn" ) );
                    request.setAttribute( "formError", bzb.getLexicon().get( "invalidLogin" ) );
                }
                /* Not validated yet */
                else if( !user.isValidated() ) {
                    forwardUrl = jspPath + "login.jsp";

                    request.setAttribute( "pageTitle", bzb.getLexicon().get( "logIn" ) );
                    request.setAttribute( "formError", bzb.getLexicon().get( "notValidated" ) );
                }
View Full Code Here

     * @param bzb The BooksZenBooks class.
     * @return The matching User if one is found, null otherwise.
     */
    public User checkCredentials( HttpServletRequest request ) {
        ResultSet result;
        User user = null;
        String email = RequestHelper.getString( "email", request );
        String password = RequestHelper.getString( "password", request );
        String where = "email = '" + email + "' AND password = '" + DigestHelper.md5( password ) + "'";

        /* Query for matching user */
        result = bzb.getDriver().select( "user", null, where );

        try {
            /* Make sure there's a result */
            if( result.next() ) {
                user = new User();

                user.init( bzb.getDriver() );
                user.populate( result );
            }
        } catch( SQLException e ) {

        }

View Full Code Here

        String pageTitle;
        String action = RequestHelper.getString( "action", request );
        RequestDispatcher dispatcher;
        HashMap<String, String> formErrors;
        BookListing listing = getListing( RequestHelper.getInt( "listId", request ) );
        User authUser = bzb.getAuthenticatedUser( request );

        /* Load necessary lexicons */
        bzb.getLexicon().load( "global" );
        bzb.getLexicon().load( "subject" );
        bzb.getLexicon().load( "book" );
        bzb.getLexicon().load( "listing" );

        if( listing == null ) {
            bzb.getLexicon().load( "error" );

            forwardUrl = jspPath + "404.jsp";
            pageTitle = bzb.getLexicon().get( "listingNotFound" );

            request.setAttribute( "customError", bzb.getLexicon().get( "listingNotFoundDesc" ) );
        }
        else if( authUser == null || authUser.getUserId() != listing.getUserId() ) {
            bzb.getLexicon().load( "error" );
            bzb.getLexicon().load( "register" );

            forwardUrl = jspPath + "401.jsp";
            pageTitle = bzb.getLexicon().get( "unauthorized" );
View Full Code Here

        bzb = new BooksZenBooks( "en", dbConfigResource ); // @TODO language should be a request param
        String action = RequestHelper.getString( "action", request );
        String forwardUrl;
        RequestDispatcher dispatcher;
        HashMap<String, String> formErrors;
        User user;
       
        /* Load necessary lexicons */
        bzb.getLexicon().load( "global" );
        bzb.getLexicon().load( "register" );
        bzb.getLexicon().load( "subject" );

        /* Already logged in? */
        if( bzb.getAuthenticatedUser( request ) != null ) {
            forwardUrl = "/index";
        }
        /* Handle registration request */
        else if( action.equals( "register" ) ) {
            formErrors = checkRegistration( request );

            /* No form errors, create the user and display validation page */
            if( formErrors.isEmpty() ) {
                user = createUser( request );

                sendValidationEmail( user );

                // @TODO remove below after email is working
                request.setAttribute( "confirmCode", user.getValidationCode() );
               
                forwardUrl = jspPath + "validationCode.jsp";
            }
            /* Show form errors */
            else {
                forwardUrl = jspPath + "register.jsp";

                request.setAttribute( "formErrors", formErrors );
                request.setAttribute( "countries", getCountries() );
            }
        }
        /* Confirming an account */
        else if( action.equals( "confirm" ) ) {
            /* No email entered - display the form */
            if( request.getParameter( "email" ) == null ) {
                forwardUrl = jspPath + "validationCode.jsp";

                request.setAttribute( "pageTitle", bzb.getLexicon().get( "confirmAccount" ) );
            }
            /* Code and email match - update user and display success */
            else if( ( user = checkValidationCode( request ) ) != null ) {
                forwardUrl = jspPath + "registerSuccess.jsp";

                user.setValidated( true );
                user.save();

                request.setAttribute( "pageTitle", bzb.getLexicon().get( "registerSuccess" ) );
            }
            /* Show validation page with errors */
            else {
View Full Code Here

     * @param request
     * @param driver
     * @return
     */
    private User createUser( HttpServletRequest request ) {
        User user = new User();

        user.init( bzb.getDriver() );
        user.setEmail( RequestHelper.getString( "email", request ) );
        user.setPassword( DigestHelper.md5( RequestHelper.getString( "password", request ) ) );
        user.setFirstName( RequestHelper.getString( "firstName", request ) );
        user.setLastName( RequestHelper.getString( "lastName", request ) );
        user.setAddress( RequestHelper.getString( "address", request ) );
        user.setCity( RequestHelper.getString( "city", request ) );
        user.setState( RequestHelper.getString( "state", request ) );
        user.setPostalCode( RequestHelper.getString( "postalCode", request ) );
        user.setCountry( RequestHelper.getString( "country", request ) );
        user.setPhone( RequestHelper.getString( "phone", request ) );
        user.setBirthDate( util.Util.parseDate( RequestHelper.getString( "birthDate", request ) ) );
        user.setJoinDate( new Date() );
        user.setValidationCode( generateCode() );
        user.setValidated( false );
        user.setSuperUser( false );

        if( user.save() ) {
            return user;
        }

        return null;
    }
View Full Code Here

    private User checkValidationCode( HttpServletRequest request ) {
        String email = RequestHelper.getString( "email", request );
        String code = RequestHelper.getString( "confirmCode", request );
        String where = "email = '" + email + "' AND validationCode = '" + code + "'";
        ResultSet result = bzb.getDriver().select( "user", null, where );
        User user = null;

        try {
            if( result.next() ) {
                user = new User();
                user.init( bzb.getDriver() );
                user.populate( result );
            }
        } catch( SQLException e ) {

        }
View Full Code Here

        return getAuthenticatedUser( request, false );
    }

    public synchronized User getAuthenticatedUser( HttpServletRequest request, boolean forceReload ) {
        ResultSet result;
        User authUser;
        String where;
        String email = CookieCutter.getCookie( request.getCookies(), "email" );
        String password = CookieCutter.getCookie( request.getCookies(), "password" );
        User sessionUser = ( User ) request.getSession().getAttribute( "authUser" );

        if( forceReload || ( user == null && email != null && password != null ) ) {
            authUser = new User();
           
            authUser.init( getDriver() );
            authUser.setEmail( email );
            authUser.setPassword( password );
View Full Code Here

TOP

Related Classes of business.User

Copyright © 2018 www.massapicom. 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.