Skip to content
Snippets Groups Projects
Commit dfeb0ea9 authored by Daniel Gerhardt's avatar Daniel Gerhardt
Browse files

Move user account actions to seperate controller

parent 35d65187
Branches
Tags
No related merge requests found
......@@ -59,7 +59,6 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.RedirectView;
import de.thm.arsnova.entities.DbUser;
import de.thm.arsnova.entities.ServiceDescription;
import de.thm.arsnova.entities.Session;
import de.thm.arsnova.entities.User;
......@@ -293,39 +292,6 @@ public class LoginController extends AbstractController {
return services;
}
@RequestMapping(value = { "/auth/register" }, method = RequestMethod.POST)
public final void register(
@RequestParam final String username,
@RequestParam final String password,
final HttpServletRequest request,
final HttpServletResponse response
) {
if (null != userService.createDbUser(username, password)) {
return;
}
/* TODO: Improve error handling: send reason to client */
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
}
@RequestMapping(value = { "/auth/activate" }, method = {RequestMethod.POST, RequestMethod.GET})
public final void activate(
@RequestParam final String username,
@RequestParam final String key,
final HttpServletRequest request,
final HttpServletResponse response
) {
DbUser dbUser = userService.getDbUser(username);
if (null != dbUser && key.equals(dbUser.getActivationKey())) {
dbUser.setActivationKey(null);
userService.updateDbUser(dbUser);
return;
}
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
}
private Collection<GrantedAuthority> getAuthorities() {
List<GrantedAuthority> authList = new ArrayList<GrantedAuthority>();
authList.add(new SimpleGrantedAuthority("ROLE_USER"));
......
/*
* Copyright (C) 2012 THM webMedia
*
* This file is part of ARSnova.
*
* ARSnova is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ARSnova is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.thm.arsnova.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import de.thm.arsnova.entities.DbUser;
import de.thm.arsnova.services.IUserService;
import de.thm.arsnova.services.UserSessionService;
@Controller
@RequestMapping("/user")
public class UserController extends AbstractController {
@Value("${security.guest.enabled}")
private String guestEnabled;
@Value("${security.guest.lecturer.enabled}")
private String guestLecturerEnabled;
@Value("${security.cas.enabled}")
private String casEnabled;
@Value("${security.ldap.enabled}")
private String ldapEnabled;
@Value("${security.facebook.enabled}")
private String facebookEnabled;
@Value("${security.google.enabled}")
private String googleEnabled;
@Value("${security.twitter.enabled}")
private String twitterEnabled;
@Autowired
private DaoAuthenticationProvider daoProvider;
@Autowired
private IUserService userService;
@Autowired
private UserSessionService userSessionService;
public static final Logger LOGGER = LoggerFactory
.getLogger(UserController.class);
@RequestMapping(value = { "/register" }, method = RequestMethod.POST)
public final void register(@RequestParam final String username,
@RequestParam final String password,
final HttpServletRequest request, final HttpServletResponse response) {
if (null != userService.createDbUser(username, password)) {
return;
}
/* TODO: Improve error handling: send reason to client */
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
}
@RequestMapping(value = { "/activate" }, method = { RequestMethod.POST,
RequestMethod.GET })
public final void activate(@RequestParam final String username,
@RequestParam final String key, final HttpServletRequest request,
final HttpServletResponse response) {
DbUser dbUser = userService.getDbUser(username);
if (null != dbUser && key.equals(dbUser.getActivationKey())) {
dbUser.setActivationKey(null);
userService.updateDbUser(dbUser);
return;
}
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
}
}
......@@ -321,7 +321,7 @@ public class UserService implements IUserService {
public void sendActivationEmail(DbUser dbUser) {
SimpleMailMessage msg = new SimpleMailMessage(regMailTemplate);
String activationUrl = MessageFormat.format("{0}/auth/activate?username={1}&key={2}", arsnovaUrl, dbUser.getUsername(), dbUser.getActivationKey());
String activationUrl = MessageFormat.format("{0}/user/activate?username={1}&key={2}", arsnovaUrl, dbUser.getUsername(), dbUser.getActivationKey());
msg.setTo(dbUser.getUsername());
msg.setText(MessageFormat.format(msg.getText(), activationUrl));
LOGGER.debug("Activation mail body: {}", msg.getText());
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment