Skip to content

Commit

Permalink
Aggiunta della index [WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
brunano21 committed May 9, 2014
1 parent 5119d31 commit 8d9d30e
Show file tree
Hide file tree
Showing 68 changed files with 12,183 additions and 6 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@
<artifactId>json-simple</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-remote-shell</artifactId>
<version>1.0.0.RELEASE</version>
</dependency>
</dependencies>

<repositories>
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/ai/server/controller/HomeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ public ModelAndView home(HttpServletRequest request,@ModelAttribute("error")Stri
Map <String,Object> map = new HashMap<String, Object>();
map.put("dati",dati);
map.put("error", error);
return new ModelAndView("home",map);
System.out.println("home");
return new ModelAndView("index",map);
}else{
System.out.println("fatto2");
return new ModelAndView("home","dati",dati);
return new ModelAndView("index","dati",dati);
}
}
}
27 changes: 25 additions & 2 deletions src/main/java/ai/server/controller/LoginController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,56 @@

import java.security.Principal;
import java.util.HashMap;
import java.util.Map;

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 org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import dati.Dati;
import hibernate.Profilo;

@Controller
public class LoginController {

@Autowired
private Dati dati;

public void setDati(Dati dati){
this.dati=dati;
}

@RequestMapping(value="/welcome",method = RequestMethod.GET)
public ModelAndView printWelcome(Principal principal){
/*
System.out.println(principal);
String name = principal.getName();
HashMap<String, String> map = new HashMap<String, String>();
map.put("name", name);
map.put("message", "Spring Security Custom Form example");
return new ModelAndView("hello",map);
*/
Map <String, Object> userModel = new HashMap<String, Object>();
userModel.put("username", dati.getUtenti().get(principal.getName()).getNickname());

Profilo profilo = (Profilo) dati.getUtenti().get(principal.getName()).getProfilos().iterator().next();
userModel.put("creditiPendenti", profilo.getCreditiPendenti());
userModel.put("creditiAcquisiti", profilo.getCreditiAcquisiti());
userModel.put("reputazione", profilo.getReputazione());

return new ModelAndView("userlogged", userModel);
}

@RequestMapping(value="/login",method = RequestMethod.GET)
public String login(Principal principal,RedirectAttributes attributes){
if(principal != null){
attributes.addFlashAttribute("error", "you're already logged");
System.out.println("Redirect");
return "redirect:/";
}else{
System.out.println("Login");
return "login";
}
}
Expand All @@ -40,7 +63,7 @@ public ModelAndView loginerror(){

@RequestMapping(value="/logout",method = RequestMethod.GET)
public ModelAndView logout(){
return new ModelAndView("login");
return new ModelAndView("index");
}

}
2 changes: 1 addition & 1 deletion src/main/java/hibernate/Utente.hbm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
</key>
<one-to-many class="hibernate.Inserzione"/>
</set>
<set fetch="select" inverse="true" lazy="true" name="profilos"
<set fetch="select" inverse="true" lazy="false" name="profilos"
sort="unsorted" table="profilo">
<key>
<column name="ID_Utente" not-null="true" unique="true"/>
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/spring-security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@
<sec:intercept-url pattern="/register" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
<sec:intercept-url pattern="/registersuccess" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
<sec:intercept-url pattern="/confirmregistration" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
<sec:intercept-url pattern="/loginfailed" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
<sec:intercept-url pattern="/login" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
<sec:intercept-url pattern="/" access="IS_AUTHENTICATED_ANONYMOUSLY"/>

<intercept-url pattern="/resources/**" access="ROLE_ANONYMOUS,ROLE_USER"/>

<sec:intercept-url pattern="/**" access="ROLE_USER"/>
<sec:form-login always-use-default-target="false" login-page="/login" default-target-url="/welcome" authentication-failure-url="/loginfailed"/>


<sec:logout logout-success-url="/logout"/>
<sec:session-management>
<sec:concurrency-control max-sessions="1" error-if-maximum-exceeded="true"/>
Expand Down
Loading

0 comments on commit 8d9d30e

Please sign in to comment.