Archived
Add signin component.
This commit is contained in:
@@ -76,8 +76,8 @@ public class AccountController {
|
||||
}
|
||||
|
||||
@PostMapping("/signin")
|
||||
public UserDTO signin(@RequestBody final UserDTO pUser, final HttpServletResponse pResponse) throws IOException {
|
||||
return accountService.signin(pUser, pResponse);
|
||||
public void signin(@RequestBody final User pUser, final HttpServletResponse pResponse) throws IOException {
|
||||
accountService.signin(pUser, pResponse);
|
||||
}
|
||||
|
||||
@PutMapping("/")
|
||||
|
||||
@@ -112,22 +112,20 @@ public class AccountService {
|
||||
return result;
|
||||
}
|
||||
|
||||
public UserDTO signin(final UserDTO pUser, final HttpServletResponse pResponse) throws IOException {
|
||||
User user = new User();
|
||||
|
||||
public void signin(final User pUser, final HttpServletResponse pResponse) throws IOException {
|
||||
if(pUser.getName() == null || pUser.getEmail() == null || pUser.getPassword() == null || "".equals(pUser.getPassword().trim())) {
|
||||
pResponse.sendError(HttpServletResponse.SC_BAD_REQUEST);
|
||||
} else if(userRepository.findByEmail(pUser.getEmail()).isPresent()) {
|
||||
pResponse.sendError(HttpServletResponse.SC_CONFLICT);
|
||||
} else {
|
||||
User user = new User();
|
||||
|
||||
user.setName(pUser.getName());
|
||||
user.setEmail(pUser.getEmail());
|
||||
user.setPassword(StringUtils.hashPassword(pUser.getPassword()));
|
||||
user.setInscriptionDate(new Date());
|
||||
userRepository.save(user);
|
||||
}
|
||||
|
||||
return new UserDTO(user);
|
||||
}
|
||||
|
||||
public void updateUser(final UserDTO pUser, final HttpServletRequest pRequest,
|
||||
|
||||
@@ -36,7 +36,11 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http.authorizeRequests()
|
||||
.antMatchers("/api/account/login", "/api/account/logout").permitAll()
|
||||
.antMatchers(
|
||||
"/api/account/login",
|
||||
"/api/account/logout",
|
||||
"/api/account/signin"
|
||||
).permitAll()
|
||||
.antMatchers(
|
||||
"/api/images/uploadAvatar",
|
||||
"/api/images/myImages",
|
||||
@@ -50,7 +54,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
||||
"/api/categories/**",
|
||||
"/api/images/**",
|
||||
"/api/posts/**"
|
||||
).permitAll()
|
||||
).permitAll()
|
||||
.anyRequest().authenticated()
|
||||
.and()
|
||||
// Allow to avoid login form at authentication failure from Angular app
|
||||
|
||||
Reference in New Issue
Block a user