Add signin module.
This commit is contained in:
@@ -82,4 +82,9 @@ public class AccountController {
|
|||||||
pResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
|
pResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/signin")
|
||||||
|
public UserDTO signin(@RequestBody final UserDTO pUser, final HttpServletResponse pResponse) throws IOException {
|
||||||
|
return accountService.signin(pUser, pResponse);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.codiki.account;
|
package org.codiki.account;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -121,4 +122,22 @@ public class AccountService {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UserDTO signin(final UserDTO pUser, final HttpServletResponse pResponse) throws IOException {
|
||||||
|
User user = new User();
|
||||||
|
|
||||||
|
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.setName(pUser.getName());
|
||||||
|
user.setEmail(pUser.getEmail());
|
||||||
|
user.setPassword(StringUtils.hashPassword(pUser.getPassword()));
|
||||||
|
user.setInscriptionDate(new Date());
|
||||||
|
userRepository.save(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new UserDTO(user);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import javax.persistence.Temporal;
|
|||||||
import javax.persistence.TemporalType;
|
import javax.persistence.TemporalType;
|
||||||
|
|
||||||
import org.codiki.core.entities.security.Token;
|
import org.codiki.core.entities.security.Token;
|
||||||
|
import org.hibernate.annotations.Generated;
|
||||||
|
import org.hibernate.annotations.GenerationTime;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="`user`")
|
@Table(name="`user`")
|
||||||
@@ -35,6 +37,8 @@ public class User implements Serializable {
|
|||||||
@SequenceGenerator(name="user_id_seq", sequenceName="user_id_seq", allocationSize=1)
|
@SequenceGenerator(name="user_id_seq", sequenceName="user_id_seq", allocationSize=1)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
// This annotation serves to fetch the attribute after an insert into db
|
||||||
|
@Generated(GenerationTime.ALWAYS)
|
||||||
private String key;
|
private String key;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|||||||
Reference in New Issue
Block a user