lista kursów
This commit is contained in:
parent
1d5744c16e
commit
2f164e7922
@ -8,7 +8,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
public class MvcConfig implements WebMvcConfigurer {
|
||||
|
||||
public void addViewControllers(ViewControllerRegistry registry) {
|
||||
registry.addViewController("/courses").setViewName("addCourse");
|
||||
registry.addViewController("/courses/addCourse").setViewName("addCourse");
|
||||
registry.addViewController("/").setViewName("start");
|
||||
registry.addViewController("/login").setViewName("login");
|
||||
registry.addViewController("/start").setViewName("start");
|
||||
|
@ -36,6 +36,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http.authorizeRequests()
|
||||
.antMatchers( "/", "/courses/**").authenticated()
|
||||
.antMatchers( "/courses").authenticated()
|
||||
.antMatchers("/", "/register").permitAll()
|
||||
.antMatchers("/", "/start").authenticated()
|
||||
//.anyRequest().authenticated()
|
||||
|
@ -12,18 +12,20 @@ import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/courses")
|
||||
public class CourseController {
|
||||
|
||||
@Autowired
|
||||
private CourseRepository courseRepository;
|
||||
|
||||
@GetMapping("/courses")
|
||||
@GetMapping("")
|
||||
public String listCourses() {
|
||||
|
||||
//model.addAttribute("message", name);
|
||||
|
@ -1,9 +1,12 @@
|
||||
package com.wmi.lti.controllers;
|
||||
|
||||
import com.wmi.lti.model.course.Course;
|
||||
import com.wmi.lti.model.course.CourseRepository;
|
||||
import com.wmi.lti.model.user.UserPrincipal;
|
||||
import org.imsglobal.lti.launch.LtiOauthSigner;
|
||||
import org.imsglobal.lti.launch.LtiSigner;
|
||||
import org.imsglobal.lti.launch.LtiSigningException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
@ -11,39 +14,39 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
public class StartController {
|
||||
|
||||
@PostMapping("/start")
|
||||
public String start(
|
||||
@RequestParam(name = "key", required = false, defaultValue = "")
|
||||
String key, @RequestParam(name = "secret", required = false, defaultValue = "")
|
||||
String secret, @RequestParam(name = "url", required = false, defaultValue = "")
|
||||
String url, Model model) {
|
||||
@Autowired
|
||||
private CourseRepository courseRepository;
|
||||
|
||||
@GetMapping("")
|
||||
public String start(Model model){
|
||||
List<Course> courses = courseRepository.findAll();
|
||||
List<Course> coursesToReturn = new ArrayList<>();
|
||||
for (Course course : courses) {
|
||||
LtiSigner signer = new LtiOauthSigner();
|
||||
Map<String, String> parameters = new HashMap<>();
|
||||
parameters.put("lti_message_type","basic-lti-launch-request");
|
||||
parameters.put("lti_message_type", "basic-lti-launch-request");
|
||||
parameters.put("lti_version", "LTI-1p0");
|
||||
parameters.put("resource_link_id", ((UserPrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername());
|
||||
try {
|
||||
Map<String, String> signedParameters = signer.signParameters(parameters, key, secret, url, "POST");
|
||||
String link = url + "?" + "oauth_nonce=" + signedParameters.get("oauth_nonce") + "&oauth_signature=" + signedParameters.get("oauth_signature") + "&oauth_consumer_key=" + signedParameters.get("oauth_consumer_key") + "&oauth_signature_method=" + signedParameters.get("oauth_signature_method") + "&oauth_timestamp=" + signedParameters.get("oauth_timestamp") + "&oauth_version=" + signedParameters.get("oauth_version") + "<i_message_type=" + signedParameters.get("lti_message_type") + "<i_version=" + signedParameters.get("lti_version") + "&resource_link_id=" + signedParameters.get("resource_link_id");
|
||||
model.addAttribute("parameters", signedParameters);
|
||||
model.addAttribute("launchUrl", link);
|
||||
Map<String, String> signedParameters = signer.signParameters(parameters, course.getCourse_key(), course.getSecret(), course.getUrl(), "POST");
|
||||
String link = course.getUrl() + "?" + "oauth_nonce=" + signedParameters.get("oauth_nonce") + "&oauth_signature=" + signedParameters.get("oauth_signature") + "&oauth_consumer_key=" + signedParameters.get("oauth_consumer_key") + "&oauth_signature_method=" + signedParameters.get("oauth_signature_method") + "&oauth_timestamp=" + signedParameters.get("oauth_timestamp") + "&oauth_version=" + signedParameters.get("oauth_version") + "<i_message_type=" + signedParameters.get("lti_message_type") + "<i_version=" + signedParameters.get("lti_version") + "&resource_link_id=" + signedParameters.get("resource_link_id");
|
||||
course.setSecret(null);
|
||||
course.setCourse_key(null);
|
||||
course.setUrl(link);
|
||||
coursesToReturn.add(course);
|
||||
} catch (LtiSigningException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//model.addAttribute("message", name);
|
||||
return "start"; //view
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("")
|
||||
public String start(){
|
||||
model.addAttribute("courses", coursesToReturn);
|
||||
return "start"; //view
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.wmi.lti.model.course;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
@ -11,6 +12,7 @@ import javax.persistence.Id;
|
||||
|
||||
@Entity
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Course {
|
||||
|
||||
@Id
|
||||
|
@ -1,11 +1,13 @@
|
||||
package com.wmi.lti.model.user;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@NoArgsConstructor
|
||||
public class User {
|
||||
|
||||
@Id
|
||||
|
@ -9,9 +9,12 @@
|
||||
<link rel="stylesheet" th:href="@{/css/main.css}"/>
|
||||
</head>
|
||||
<body>
|
||||
<form th:action="${launchUrl}" method="POST">
|
||||
<tr th:each="course : ${courses}">
|
||||
<form th:action="${course.url}" method="POST">
|
||||
<input type="submit">Launch Tool</input>
|
||||
</form>
|
||||
</form>
|
||||
</tr>
|
||||
|
||||
<br><br><br>
|
||||
<form th:action="@{/courses/addCourse}" method="GET">
|
||||
<div><input type="submit" value="Add new content"/></div>
|
||||
|
Loading…
Reference in New Issue
Block a user