All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.formkiq.server.controller.IndexController Maven / Gradle / Ivy

/*
 * Copyright (C) 2016 FormKiQ Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.formkiq.server.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.formkiq.server.service.SpringSecurityService;
import com.formkiq.server.service.UserService;

/**
 * Static Content Controller.
 *
 */
@Controller
public class IndexController {

    /** User Service. */
    @Autowired
    private UserService userservice;

    /** SpringSecurityService. */
    @Autowired
    private SpringSecurityService securityService;

    /** User Count Cache. */
    private int userCount = -1;

    /**
     * Handle static admin page.
     * @return {@link String}
     */
    @RequestMapping(value = "/admin", method = RequestMethod.GET)
    public String admin() {
        return "redirect:/admin/users";
    }

    /**
     * Handle static Lost Password page.
     * @return {@link String}
     */
    @RequestMapping(value = "/403", method = RequestMethod.GET)
    public String error403() {
        return "403";
    }

    /**
     * @return int
     */
    private int getUserCount() {

        if (this.userCount < 1) {
            this.userCount = this.userservice.findUsers(null).getUsers().size();
        }

        return this.userCount;
    }

    /**
     * Handle static home page.
     * @return {@link String}
     */
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index() {

        if (getUserCount() < 1) {
            return "redirect:/setup";
        }

        return "index";
    }

    /**
     * Handle static login page.
     * @return {@link String}
     */
    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String login() {

        if (this.securityService.isAdmin()) {
            return "redirect:/admin";
        }

        return "login";
    }

    /**
     * Handle static Lost Password page.
     * @return {@link String}
     */
    @RequestMapping(value = "/lostpassword", method = RequestMethod.GET)
    public String lostpassword() {
        return "lostpassword";
    }

    /**
     * Handle static Reset Password page.
     * @param request {@link HttpServletRequest}
     * @return {@link String}
     */
    @RequestMapping(value = "/resetpassword", method = RequestMethod.GET)
    public String resetpassword(final HttpServletRequest request) {
        return "resetpassword";
    }

    /**
     * Handle static setup page.
     * @return {@link String}
     */
    @RequestMapping(value = "/setup", method = RequestMethod.GET)
    public String setup() {

        if (getUserCount() == 0) {
            return "setup";
        }

        return "redirect:/";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy