aboutsummaryrefslogtreecommitdiff
path: root/juick-spring-www/src/main/java/com/juick/www/controllers/LoginController.java
blob: 8827d9486577c685aad4d61cbbf997d52dbff6a5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.juick.www.controllers;

import com.juick.User;
import com.juick.service.UserService;
import com.juick.util.UserUtils;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.inject.Inject;
import java.security.Principal;

/**
 * Created by vitalyster on 09.12.2016.
 */
@Controller
public class LoginController {
    @Inject
    private UserService userService;
    @Inject
    private Environment env;

    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String getLoginForm(Principal principal) {
        String name = UserUtils.getUsername(principal, null);
        User visitor = userService.getUserByName(name);

        if (visitor.getUid() > 0)
            return "redirect:/login";

        return "views/login";
    }
}