minor changes

This commit is contained in:
DOHA 2015-03-04 18:09:01 +02:00
parent d86a6a43b6
commit e86cc290fe
6 changed files with 42 additions and 33 deletions

View File

@ -7,6 +7,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpSession;
import org.baeldung.persistence.dao.PostRepository;
import org.baeldung.persistence.dao.UserRepository;
import org.baeldung.persistence.model.Post;
@ -22,6 +24,7 @@ import org.springframework.ui.Model;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.fasterxml.jackson.databind.JsonNode;
@ -43,15 +46,15 @@ public class RedditController {
private PostRepository postReopsitory;
@RequestMapping("/info")
public final String getInfo(final Model model) {
public final String getInfo(HttpSession session) {
final JsonNode node = redditRestTemplate.getForObject("https://oauth.reddit.com/api/v1/me", JsonNode.class);
final String name = node.get("name").asText();
addUser(name, redditRestTemplate.getAccessToken());
model.addAttribute("info", name);
session.setAttribute("username", name);
return "reddit";
}
@RequestMapping("/submit")
@RequestMapping(value = "/submit", method = RequestMethod.POST)
public final String submit(final Model model, @RequestParam final Map<String, String> formParams) {
final MultiValueMap<String, String> param1 = constructParams(formParams);
@ -83,7 +86,7 @@ public class RedditController {
return "schedulePostForm";
}
@RequestMapping("/schedule")
@RequestMapping(value = "/schedule", method = RequestMethod.POST)
public final String schedule(final Model model, @RequestParam final Map<String, String> formParams) throws ParseException {
logger.info("User scheduling Post with these parameters: " + formParams.entrySet());
final User user = userReopsitory.findByAccessToken(redditRestTemplate.getAccessToken().getValue());
@ -182,6 +185,7 @@ public class RedditController {
user.setTokenExpiration(token.getExpiration());
userReopsitory.save(user);
}
}
}

View File

@ -19,15 +19,17 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="info">Spring Security OAuth</a>
<a class="navbar-brand" href="#">Schedule to Reddit</a>
</div>
<p class="navbar-text navbar-right">Logged in as <b><c:out value="${username}"/></b>&nbsp;&nbsp;&nbsp;</p>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">My Scheduled Posts</a></li>
<li><a href="post">Submit Post</a></li>
<li><a href="postSchedule">Schedule Post</a></li>
<li class="active"><a href="posts">My Scheduled Posts</a></li>
<li><a href="post">Post to Reddit</a></li>
<li><a href="postSchedule">Schedule Post to Reddit</a></li>
</ul>
</div><!-- /.navbar-collapse -->

View File

@ -17,32 +17,29 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Spring Security OAuth</a>
<a class="navbar-brand" href="#">Schedule to Reddit</a>
</div>
<p class="navbar-text navbar-right">Logged in as <b><c:out value="${username}"/></b>&nbsp;&nbsp;&nbsp;</p>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="posts">My Scheduled Posts</a></li>
<li><a href="post">Submit Post</a></li>
<li><a href="postSchedule">Schedule Post</a></li>
<li><a href="post">Post to Reddit</a></li>
<li><a href="postSchedule">Schedule Post to Reddit</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<div class="container">
<c:choose>
<c:when test="${info != null}">
<h1>Welcome, <small>${info}</small></h1>
<a href="post" class="btn btn-primary">Submit to Reddit</a>
</c:when>
<c:otherwise>
<b>Sorry, error occurred</b>
<br><br>
<div>${error}</div>
</c:otherwise>
</c:choose>
<h1>Welcome, <small><c:out value="${username}"/></small></h1>
<br>
<a href="posts" class="btn btn-primary">My Scheduled Posts</a>
<a href="post" class="btn btn-primary">Post to Reddit</a>
<a href="postSchedule" class="btn btn-primary">Schedule Post to Reddit</a>
</div>
</body>
</html>

View File

@ -20,22 +20,24 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Spring Security OAuth</a>
<a class="navbar-brand" href="#">Schedule to Reddit</a>
</div>
<p class="navbar-text navbar-right">Logged in as <b><c:out value="${username}"/></b>&nbsp;&nbsp;&nbsp;</p>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="posts">My Scheduled Posts</a></li>
<li><a href="post">Submit Post</a></li>
<li class="active"><a href="#">Schedule Post</a></li>
<li><a href="post">Post to Reddit</a></li>
<li class="active"><a href="postSchedule">Schedule Post to Reddit</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<div class="container">
<h1>Schedule Post</h1>
<h1>Schedule Post to Reddit</h1>
<form action="schedule" method="post">
<div class="row">
<div class="form-group">

View File

@ -17,22 +17,24 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Spring Security OAuth</a>
<a class="navbar-brand" href="#">Schedule to Reddit</a>
</div>
<p class="navbar-text navbar-right">Logged in as <b><c:out value="${username}"/></b>&nbsp;&nbsp;&nbsp;</p>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="posts">My Scheduled Posts</a></li>
<li class="active"><a href="#">Submit Post</a></li>
<li><a href="postSchedule">Schedule Post</a></li>
<li class="active"><a href="post">Post to Reddit</a></li>
<li><a href="postSchedule">Schedule Post to Reddit</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<div class="container">
<h1>Submit to Reddit</h1>
<h1>Post to Reddit</h1>
<form action="submit" method="post">
<div class="row">
<div class="form-group">

View File

@ -17,15 +17,17 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Spring Security OAuth</a>
<a class="navbar-brand" href="#">Schedule to Reddit</a>
</div>
<p class="navbar-text navbar-right">Logged in as <b><c:out value="${username}"/></b>&nbsp;&nbsp;&nbsp;</p>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="posts">My Scheduled Posts</a></li>
<li><a href="post">Submit Post</a></li>
<li><a href="postSchedule">Schedule Post</a></li>
<li><a href="post">Post to Reddit</a></li>
<li><a href="postSchedule">Schedule Post to Reddit</a></li>
</ul>
</div><!-- /.navbar-collapse -->