update pom and reformat code
This commit is contained in:
parent
deeb2b20f3
commit
457baf6015
@ -17,7 +17,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>br.com.caelum</groupId>
|
<groupId>br.com.caelum</groupId>
|
||||||
<artifactId>vraptor</artifactId>
|
<artifactId>vraptor</artifactId>
|
||||||
<version>4.2.0-RC3</version>
|
<version>4.2.0.Final</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -50,12 +50,14 @@ public class AuthController {
|
|||||||
|
|
||||||
validator.onErrorRedirectTo(this).registrationForm();
|
validator.onErrorRedirectTo(this).registrationForm();
|
||||||
|
|
||||||
if(!user.getPassword().equals(request.getParameter("password_confirmation"))) {
|
if(!user.getPassword()
|
||||||
|
.equals(request.getParameter("password_confirmation"))) {
|
||||||
result.include("error", "Passwords Do Not Match");
|
result.include("error", "Passwords Do Not Match");
|
||||||
result.redirectTo(this).registrationForm();
|
result.redirectTo(this).registrationForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
user.setPassword(BCrypt.hashpw(user.getPassword(), BCrypt.gensalt()));
|
user.setPassword(
|
||||||
|
BCrypt.hashpw(user.getPassword(), BCrypt.gensalt()));
|
||||||
|
|
||||||
Object resp = userDao.add(user);
|
Object resp = userDao.add(user);
|
||||||
|
|
||||||
@ -76,13 +78,16 @@ public class AuthController {
|
|||||||
@Post("/login")
|
@Post("/login")
|
||||||
public void login(HttpServletRequest request) {
|
public void login(HttpServletRequest request) {
|
||||||
|
|
||||||
if (request.getParameter("user.email").isEmpty() || request.getParameter("user.password").isEmpty()) {
|
String password = request.getParameter("user.password");
|
||||||
|
String email = request.getParameter("user.email");
|
||||||
|
|
||||||
|
if(email.isEmpty() || password.isEmpty()) {
|
||||||
result.include("error", "Email/Password is Required!");
|
result.include("error", "Email/Password is Required!");
|
||||||
result.redirectTo(AuthController.class).loginForm();
|
result.redirectTo(AuthController.class).loginForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
User user = userDao.findByEmail(request.getParameter("user.email"));
|
User user = userDao.findByEmail(email);
|
||||||
if (Objects.nonNull(user) && BCrypt.checkpw(request.getParameter("user.password"), user.getPassword())) {
|
if(user != null && BCrypt.checkpw(password, user.getPassword())) {
|
||||||
userInfo.setUser(user);
|
userInfo.setUser(user);
|
||||||
result.include("status", "Login Successful!");
|
result.include("status", "Login Successful!");
|
||||||
result.redirectTo(IndexController.class).index();
|
result.redirectTo(IndexController.class).index();
|
||||||
|
@ -48,7 +48,6 @@ public class PostController {
|
|||||||
|
|
||||||
@br.com.caelum.vraptor.Post("/post/add")
|
@br.com.caelum.vraptor.Post("/post/add")
|
||||||
public void add(Post post) {
|
public void add(Post post) {
|
||||||
|
|
||||||
post.setAuthor(userInfo.getUser());
|
post.setAuthor(userInfo.getUser());
|
||||||
validator.validate(post);
|
validator.validate(post);
|
||||||
if(validator.hasErrors())
|
if(validator.hasErrors())
|
||||||
@ -61,7 +60,8 @@ public class PostController {
|
|||||||
result.include("status", "Post Added Successfully");
|
result.include("status", "Post Added Successfully");
|
||||||
result.redirectTo(IndexController.class).index();
|
result.redirectTo(IndexController.class).index();
|
||||||
} else {
|
} else {
|
||||||
result.include("error", "There was an error creating the post. Try Again");
|
result.include(
|
||||||
|
"error", "There was an error creating the post. Try Again");
|
||||||
result.redirectTo(this).addForm();
|
result.redirectTo(this).addForm();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,6 @@ import java.util.logging.Logger;
|
|||||||
public class UserDao {
|
public class UserDao {
|
||||||
|
|
||||||
SessionFactory sessionFactory;
|
SessionFactory sessionFactory;
|
||||||
Logger logger = Logger.getLogger(getClass().getName());
|
|
||||||
|
|
||||||
public UserDao() {
|
public UserDao() {
|
||||||
this(null);
|
this(null);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user