Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/webContexts.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ public void update(Transaction transaction) {
public void delete(int index) {
//function 18
}

}
6 changes: 6 additions & 0 deletions src/main/java/controller/user/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@

public interface UserController extends GenericController<User> {
Collection<User> showAll();

void create(User user);

User showByIndex(int index);

void update(User user);

void delete(int index);
User login (String userName, String password);

}
36 changes: 35 additions & 1 deletion src/main/java/controller/user/UserControllerImpl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package controller.user;
import com.mysql.cj.AbstractQuery;
import model.User;

import javax.servlet.http.HttpSession;
import java.sql.*;
import java.time.LocalDate;
import java.util.Collection;
Expand All @@ -13,7 +16,9 @@ public class UserControllerImpl implements UserController{
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
private static final String UPDATE_USERS_SQL = "update user set user.login_name = ?, user.login_password = ?, user.email = ?," +
"user.picture_url = ?, user.gender = ?, user.user_name = ?, user.user_dob = ?, user.card_id = ?, user.phone = ?, user.address where user.id = ?;";
private static final String DELETE_USERS_SQL = "delete from user where user.id = ?;";
private static final String DELETE_USERS_SQL = "update user set user.disable=1 WHERE user.id=?;";
private static final String SELECT_USER = "select * from user where user.login_name = ? and user.login_password = ? ";


public UserControllerImpl() {
}
Expand Down Expand Up @@ -150,4 +155,33 @@ public void delete(int index) {
e.printStackTrace();
}
}

@Override
public User login(String login_name, String login_password) {
try ( Connection connection = connector.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(SELECT_USER);) {
preparedStatement.setString(1, login_name);
preparedStatement.setString(2, login_password);
ResultSet rs = preparedStatement.executeQuery();

while (rs.next()) {
return new User(rs.getInt(1),
rs.getString(2),
rs.getString(3),
rs.getString(4),
rs.getString(5),
rs.getBoolean(6),
rs.getString(7),
rs.getString(8),
rs.getString(9),
rs.getString(10),
rs.getString(11)

);
}
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
}
1 change: 1 addition & 0 deletions src/main/java/controller/wallet/WalletControllerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,5 @@ public void delete(int index) {
throw new RuntimeException(e);
}
}

}
43 changes: 39 additions & 4 deletions src/main/java/view/UserServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) {
case "delete":
deleteUser(request, response);
break;
case "login":
showFormLogin(request, response);
default:
showUserProfile(request, response);
break;
Expand All @@ -55,6 +57,17 @@ private void showUserProfile(HttpServletRequest request, HttpServletResponse res
}
}

private void showFormLogin(HttpServletRequest request, HttpServletResponse response){
RequestDispatcher dispatcher = request.getRequestDispatcher("userAction/login.jsp");
try {
dispatcher.forward(request, response);
} catch (ServletException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

private void deleteUser(HttpServletRequest request, HttpServletResponse response) {
int id = (int) request.getSession().getAttribute("id");
userControllerImpl.delete(id);
Expand Down Expand Up @@ -100,15 +113,37 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
case "editProfile":
updateUser(request, response);
break;

// case "view":
// showUserForm(request, response);
// break;
case "login":
loginProfile(request, response);
break;
}
}
private void loginProfile(HttpServletRequest request, HttpServletResponse response){
String login_name = request.getParameter("login_name");
String login_password = request.getParameter("login_password");
User user = userControllerImpl.login(login_name, login_password);

HttpSession session = request.getSession();
session.setAttribute("login_name", login_name);
session.setAttribute("login_password", login_password);

if(user == null){
try {
response.sendRedirect("userAction/login.jsp");
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
try {
response.sendRedirect("userAction/profile.jsp");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
private void updateUser(HttpServletRequest request, HttpServletResponse response) {
int id = (int) request.getSession().getAttribute("id");

String login_name = request.getParameter("login_name");
String login_password = request.getParameter("login_password");
String email = request.getParameter("email");
Expand Down
99 changes: 1 addition & 98 deletions src/main/webapp/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -9,106 +9,9 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<style>
/* Remove the navbar's default margin-bottom and rounded borders */
.navbar {
margin-bottom: 0;
border-radius: 0;
}

/* Set height of the grid so .sidenav can be 100% (adjust as needed) */
.row.content {height: 450px}

/* Set gray background color and 100% height */
.sidenav {
padding-top: 20px;
background-color: #f1f1f1;
height: 100%;
}

/* Set black background color, white text and some padding */
footer {
background-color: #555;
color: white;
padding: 15px;
}
img.profilepic{
max-height: 450px;
width:100%;
height: 100%;
max-width: 253.19px;
}
/* On small screens, set height to 'auto' for sidenav and grid */
@media screen and (max-width: 767px) {
.sidenav {
height: auto;
padding: 15px;
}
.row.content {height:auto;}

}
</style>
<title>Title</title>
</head>
<body>

<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Logo</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Projects</a></li>
<li><a href="#">Contact</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
</ul>
</div>
</div>
</nav>

<div class="container-fluid text-center">
<div class="row content">
<div class="col-sm-2 sidenav">
<img class="profilepic" src="https://msmobile.com.vn/upload_images/images/hinh-nen-powerpoint-tien-te-1.jpg">
<p><a href="#">Link</a></p>
<p><a href="#">Link</a></p>
</div>
<div class="col-sm-8 text-left">
<h1>Profile of </h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
<hr>
<h3>Test</h3>
<p>Lorem ipsum...</p>
</div>
<div class="col-sm-2 sidenav">
<div class="well">
<p>ADS</p>
</div>
<div class="well">
<p>ADS</p>
</div>
</div>
</div>
</div>

<footer class="container-fluid text-center">
<p>Footer Text</p>
</footer>

</body>
</html>
7 changes: 4 additions & 3 deletions src/main/webapp/userAction/editProfile.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@
<tr>
<th>Gender:</th>
<td>
<input type="text" name="name" size="45"
value="<c:out value='${user.gender}' />"
/>
<select name="gender" id="gender" value='${user.gender}'>*
<option value="1">Male</option>
<option value="0">Female</option>
</select>
</td>
</tr>
<tr>
Expand Down
Loading