Skip to content

Commit

Permalink
로그인 실패 시 플로우 및, 로그인 전용 페이지 추가.
Browse files Browse the repository at this point in the history
  • Loading branch information
m0er committed Dec 31, 2012
1 parent 6115ea0 commit e111f97
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 18 deletions.
52 changes: 41 additions & 11 deletions src/com/raptoz/user/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.google.common.base.Strings;
import com.raptoz.tag.TagService;

@Slf4j
Expand All @@ -23,8 +25,8 @@ public class UserController {

@RequestMapping(value="/signup", method=RequestMethod.POST)
public String signup(User user, @RequestParam("profileImage") MultipartFile profileImage) {
log.info(user.toString());
log.info("File '" + profileImage.getOriginalFilename() + "' uploaded successfully");
log.info("signup user info: {}", user.toString());
log.info("File '{}' uploaded successfully", profileImage.getOriginalFilename());

userService.add(user, profileImage);
tagService.upsert(user.getTags());
Expand All @@ -33,17 +35,45 @@ public String signup(User user, @RequestParam("profileImage") MultipartFile prof
}

@RequestMapping("/login")
public String login(User user, @RequestHeader("referer") String referer, Model model) {
log.info("login() - " + user.toString());
log.info(referer);
public String login(User user, @RequestHeader("referer") String referer, String redirectUrl, HttpSession session, RedirectAttributes redirectAttr) {
log.info("login(): {}", user.toString());
log.info("referer: {}", referer);
log.info("redirectUrl: {}", redirectUrl);

user = userService.login(user);
if (user != null) {
model.addAttribute("loginUser", user);
log.info("login success - " + user);
User savedUser = userService.login(user);
if (savedUser != null) {
session.setAttribute("loginUser", savedUser);
log.info("login success - {}", savedUser);

if (!Strings.isNullOrEmpty(redirectUrl)) {
return "redirect:" + redirectUrl;
} else {
return "redirect:" + referer;
}
} else {
User userByEmail = userService.getByEmail(user.getEmail());

String emailIncorrectMessage = "";
String passwordIncorrectMessage = "";
if (userByEmail == null) {
emailIncorrectMessage = "check your email";
} else {
passwordIncorrectMessage = "check your password";
}

redirectAttr.addFlashAttribute("redirectUrl", referer)
.addFlashAttribute("emailIncorrectMessage", emailIncorrectMessage)
.addFlashAttribute("passwordIncorrectMessage", passwordIncorrectMessage)
.addFlashAttribute("email", user.getEmail())
.addFlashAttribute("password", user.getPassword());

return "redirect:/user/login/failure";
}

return "redirect:" + referer;
}

@RequestMapping({"/login/failure", "/login/form"})
public String loginFailure(Model model) {
return "login/form";
}

@RequestMapping("/logout")
Expand Down
2 changes: 1 addition & 1 deletion src/com/raptoz/user/UserRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public interface UserRepository extends MongoRepository<User, ObjectId> {
@Query(value = "{}", fields = "{password: 0}")
List<User> findAllSimplePageable(Pageable pageable);

@Query(value = "{}", fields = "{password: 0}")
@Query(value = "{ 'email' : ?0 }", fields = "{password: 0}")
User findOneByEmail(String email);

@Query(value = "{ 'role' : ?0 }", fields = "{password: 0}")
Expand Down
42 changes: 42 additions & 0 deletions web/WEB-INF/view/login/form.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Raptoz Login Form</title>
<link rel="stylesheet" type="text/css" href="<c:url value="/css/overcast/jquery-ui.css"/>">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/bootstrap.css"/>"/>
<link rel="stylesheet" type="text/css" href="<c:url value="/css/raptoz-base.css"/>"/>
<link rel="stylesheet" type="text/css" href="<c:url value="/css/raptoz-login-form.css"/>"/>
</head>
<body>
<div class="container" id="resultContainer">
<form class="well form-horizontal" id="loginForm" action="<c:url value="/user/login"/>" method="post">
<fieldset>
<h2>Raptoz Sign in</h2>
<input type="hidden" name="redirectUrl" value="${redirectUrl}">
<div class="control-group ${not empty emailIncorrectMessage ? "error" : ""}">
<label class="control-label" for="inputEmail">Email</label>
<div class="controls">
<input type="text" name="email" placeholder="Email address" value="${email}">
<span class="help-inline">${emailIncorrectMessage}</span>
</div>
</div>
<div class="control-group ${not empty passwordIncorrectMessage ? "error" : ""}">
<label class="control-label" for="inputPassword">Password</label>
<div class="controls">
<input type="password" name="password" placeholder="Password" value="">
<span class="help-inline">${passwordIncorrectMessage}</span>
</div>
</div>
<div class="control-group">
<div class="controls">
<input type="submit" class="btn btn-primary" value="Submit">
</div>
</div>
</fieldset>
</form>
</div>
</body>
</html>
24 changes: 24 additions & 0 deletions web/css/raptoz-login-form.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@CHARSET "UTF-8";

body {
padding-top: 40px;
padding-bottom: 40px;
background-color: #f5f5f5;
}

h2 {
text-align: center;
}

#loginForm {
max-width: 500px;
margin: 0 auto;
margin-top: 10%;
background-color: #fff;
}

#loginForm input {
height: auto;
font-size: 16px;
padding: 7px 9px;
}
6 changes: 0 additions & 6 deletions web/css/raptoz-mypage.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
@CHARSET "UTF-8";

body {padding-top: 70px;}
textarea {resize: none;}
.popover {z-index: 1030;}
.visible {visibility: visible;}
.not.visible {visibility: hidden;}

/* Select2 placeholder fix */
#mypageInfo .select2-container {width: 100% !important; margin-bottom: 10px;}

Expand Down

0 comments on commit e111f97

Please sign in to comment.