package cz.beranek.projekt;
import java.io.Console;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.channel.ChannelService;
import com.google.appengine.api.channel.ChannelServiceFactory;
import com.google.appengine.api.users.UserServiceFactory;
import cz.beranek.model.Hra;
@Controller
public class TestController {
//@RequestMapping(value="/hra.do")
public String test(Model model){
String userId = new String("aaa");
String token = new String("token");
final UserService userService = UserServiceFactory.getUserService();
final ChannelService channelService = ChannelServiceFactory.getChannelService();
//vytvoreni ID pro uzivatele
if(!userService.isUserLoggedIn()){
model.addAttribute("link", userService.createLoginURL("/hra.do"));
return "login";
}
else {
if(userService != null) {
userId = userService.getCurrentUser().getUserId();
}
//asi vytvoreni kanalu a prirazeni tokenu
if (channelService != null){
token = channelService.createChannel(userId);
}
String login = userService.getCurrentUser().getNickname();
String email = userService.getCurrentUser().getEmail();
//ted musime predat token do stranky uzivatele (asi :-) )
//v googlu vemou obsah indexu a tam si daji nejaky tag ktery pak nahradi tim tokenem
//viz index=index.replaceAll("\\{\\{ token \\}\\}",token);
//pak nasleduje odeslani predelane stranky s tokenemn
//resp.setContentType("text/html")
//resp.getWriter().write(index);
model.addAttribute("usrKey", "'"+token+"'");
model.addAttribute("login", login);
model.addAttribute("email", email);
System.out.println("Testik");
/*
Hra.addHrac(userId, userId);
System.out.println("vypis hracu");
for (String s : Hra.getHraci().keySet()) {
System.out.println(s);
}
*/
return "hra";
}
}
}