2 Copyright 2009 senju@users.sourceforge.jp
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
17 package jp.sourceforge.rabbitBTS.controllers;
19 import java.util.logging.Level;
21 import javax.servlet.http.HttpServletRequest;
23 import jp.sourceforge.rabbitBTS.Sht;
24 import jp.sourceforge.rabbitBTS.exceptions.NotRegisteredException;
25 import jp.sourceforge.rabbitBTS.exceptions.RabbitBTSException;
26 import jp.sourceforge.rabbitBTS.models.Account;
27 import jp.sourceforge.rabbitBTS.services.AccountServices;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.stereotype.Controller;
31 import org.springframework.ui.ModelMap;
32 import org.springframework.validation.BindingResult;
33 import org.springframework.validation.Validator;
34 import org.springframework.web.bind.annotation.RequestMapping;
35 import org.springframework.web.bind.annotation.RequestMethod;
38 public class RegisterController implements IController {
39 private static final String REDIRECT_HOME_HTML = "redirect:/home.html";
42 private AccountServices accountServices;
45 private Validator validator;
50 * ユーザーがgoogleにログインしていない場合、googleのログイン画面にリダイレクトする。
51 * ユーザーがアカウントを持っている場合、ユーザーホームにリダイレクトする。
52 * ユーザーがgoogleにログイン済みでかつアカウントを持っていない時だけ、画面を表示する。
58 @RequestMapping(method = RequestMethod.GET)
59 public String index(HttpServletRequest req, ModelMap map) {
62 final Account up = this.accountServices.fetchAccount();
65 Sht.log(this).finer("ログインが必要");
66 ret = "redirect:" + Sht.loginUrl(req);
68 // すでに登録済みの場合ホームへリダイレクト
69 Sht.log(this).finer("既に登録済み");
70 ret = REDIRECT_HOME_HTML;
72 } catch (final NotRegisteredException e) {
74 map.addAttribute(new Account());
93 * <li>バリデートに失敗した場合、エラーメッセージ
94 * <li>UserProfile登録に失敗した場合(二重登録等)、ロールバック、エラーメッセージ
101 @RequestMapping(method = RequestMethod.POST)
102 public String index(Account user, BindingResult result, ModelMap map) {
103 this.validator.validate(user, result);
104 if (result.hasErrors()) {
105 Sht.log(this).finer("ユーザ登録画面にてバリデートに失敗");
110 this.accountServices.registAccount(user);
111 } catch (final RabbitBTSException e) {
112 Sht.log(this).log(Level.WARNING, "ユーザー登録で例外発生", e);
113 map.addAttribute("errorMessage", "登録に失敗しました。再度やりなおしてください。");
116 return REDIRECT_HOME_HTML;