ads = new ArrayList<>();
+ while (rs.next()) {
+ ads.add(extractAd(rs));
+ }
+ return ads;
+ }
+
+}
diff --git a/src/main/java/com/codeup/adlister/dao/MySQLUsersDao.java b/src/main/java/com/codeup/adlister/dao/MySQLUsersDao.java
new file mode 100644
index 0000000000..4e69e57044
--- /dev/null
+++ b/src/main/java/com/codeup/adlister/dao/MySQLUsersDao.java
@@ -0,0 +1,66 @@
+package com.codeup.adlister.dao;
+
+import com.codeup.adlister.models.User;
+import com.mysql.cj.jdbc.Driver;
+
+import java.sql.*;
+
+public class MySQLUsersDao implements Users {
+ private Connection connection;
+
+ public MySQLUsersDao(Config config) {
+ try {
+ DriverManager.registerDriver(new Driver());
+ connection = DriverManager.getConnection(
+ config.getUrl(),
+ config.getUser(),
+ config.getPassword()
+ );
+ } catch (SQLException e) {
+ throw new RuntimeException("Error connecting to the database!", e);
+ }
+ }
+
+
+ @Override
+ public User findByUsername(String username) {
+ String query = "SELECT * FROM users WHERE username = ? LIMIT 1";
+ try {
+ PreparedStatement stmt = connection.prepareStatement(query);
+ stmt.setString(1, username);
+ return extractUser(stmt.executeQuery());
+ } catch (SQLException e) {
+ throw new RuntimeException("Error finding a user by username", e);
+ }
+ }
+
+ @Override
+ public Long insert(User user) {
+ String query = "INSERT INTO users(username, email, password) VALUES (?, ?, ?)";
+ try {
+ PreparedStatement stmt = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
+ stmt.setString(1, user.getUsername());
+ stmt.setString(2, user.getEmail());
+ stmt.setString(3, user.getPassword());
+ stmt.executeUpdate();
+ ResultSet rs = stmt.getGeneratedKeys();
+ rs.next();
+ return rs.getLong(1);
+ } catch (SQLException e) {
+ throw new RuntimeException("Error creating new user", e);
+ }
+ }
+
+ private User extractUser(ResultSet rs) throws SQLException {
+ if (! rs.next()) {
+ return null;
+ }
+ return new User(
+ rs.getLong("id"),
+ rs.getString("username"),
+ rs.getString("email"),
+ rs.getString("password")
+ );
+ }
+
+}
diff --git a/src/main/java/com/codeup/adlister/dao/Users.java b/src/main/java/com/codeup/adlister/dao/Users.java
new file mode 100644
index 0000000000..c434147497
--- /dev/null
+++ b/src/main/java/com/codeup/adlister/dao/Users.java
@@ -0,0 +1,8 @@
+package com.codeup.adlister.dao;
+
+import com.codeup.adlister.models.User;
+
+public interface Users {
+ User findByUsername(String username);
+ Long insert(User user);
+}
diff --git a/src/main/java/com/codeup/adlister/models/Ad.java b/src/main/java/com/codeup/adlister/models/Ad.java
new file mode 100644
index 0000000000..bdc8b6c92d
--- /dev/null
+++ b/src/main/java/com/codeup/adlister/models/Ad.java
@@ -0,0 +1,117 @@
+package com.codeup.adlister.models;
+
+public class Ad {
+ private long id;
+ private long userId;
+ private String title;
+ private String description;
+ private String img_url;
+ private String gender;
+ private double price;
+ private int age;
+
+
+ public Ad(long id, long userId, String title, String description) {
+ this.id = id;
+ this.userId = userId;
+ this.title = title;
+ this.description = description;
+ }
+
+ public Ad(long userId, String title, String description) {
+ this.userId = userId;
+ this.title = title;
+ this.description = description;
+ }
+
+
+ // constructor with everything on it for extract DAO method
+ public Ad(long id, long userId, String title, String description, String img_url, String gender, double price, int age)
+ {
+ this.id = id;
+ this.userId = userId;
+ this.title = title;
+ this.description = description;
+ this.img_url = img_url;
+ this.gender = gender;
+ this.price = price;
+ this.age = age;
+ }
+
+ // additional features constructor
+ public Ad(long userId, String title, String description, String img_url, String gender, double price, int age)
+ {
+ this.userId = userId;
+ this.title = title;
+ this.description = description;
+ this.img_url = img_url;
+ this.gender = gender;
+ this.price = price;
+ this.age = age;
+ }
+
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public long getUserId() {
+ return userId;
+ }
+
+ public void setUserId(long userId) {
+ this.userId = userId;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getImg_url() {
+ return img_url;
+ }
+
+ public void setImg_url(String img_url) {
+ this.img_url = img_url;
+ }
+
+ public String getGender() {
+ return gender;
+ }
+
+ public void setGender(String gender) {
+ this.gender = gender;
+ }
+
+ public double getPrice() {
+ return price;
+ }
+
+ public void setPrice(double price) {
+ this.price = price;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+}
diff --git a/src/main/java/com/codeup/adlister/models/User.java b/src/main/java/com/codeup/adlister/models/User.java
new file mode 100644
index 0000000000..e43bc0dc81
--- /dev/null
+++ b/src/main/java/com/codeup/adlister/models/User.java
@@ -0,0 +1,57 @@
+package com.codeup.adlister.models;
+
+import com.codeup.adlister.util.Password;
+
+public class User {
+ private long id;
+ private String username;
+ private String email;
+ private String password;
+
+ public User() {}
+
+ public User(String username, String email, String password) {
+ this.username = username;
+ this.email = email;
+ setPassword(password);
+ }
+
+ public User(long id, String username, String email, String password) {
+ this.id = id;
+ this.username = username;
+ this.email = email;
+ this.password = password;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = Password.hash(password);
+ }
+}
diff --git a/src/main/java/com/codeup/adlister/util/Password.java b/src/main/java/com/codeup/adlister/util/Password.java
new file mode 100644
index 0000000000..1ca33b20dd
--- /dev/null
+++ b/src/main/java/com/codeup/adlister/util/Password.java
@@ -0,0 +1,15 @@
+package com.codeup.adlister.util;
+
+import org.mindrot.jbcrypt.BCrypt;
+
+public class Password {
+ private static final int ROUNDS = 12;
+
+ public static String hash(String password) {
+ return BCrypt.hashpw(password, BCrypt.gensalt(ROUNDS));
+ }
+
+ public static boolean check(String password, String hash) {
+ return BCrypt.checkpw(password, hash);
+ }
+}
diff --git a/src/main/webapp/WEB-INF/ads/create.jsp b/src/main/webapp/WEB-INF/ads/create.jsp
new file mode 100644
index 0000000000..da4194cd05
--- /dev/null
+++ b/src/main/webapp/WEB-INF/ads/create.jsp
@@ -0,0 +1,45 @@
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/webapp/WEB-INF/ads/index.jsp b/src/main/webapp/WEB-INF/ads/index.jsp
new file mode 100644
index 0000000000..4684b9863c
--- /dev/null
+++ b/src/main/webapp/WEB-INF/ads/index.jsp
@@ -0,0 +1,38 @@
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Adlister
+
+
+
+
${ad.title}
+
${ad.description}
+
+
+
+
+
+
+
diff --git a/src/main/webapp/WEB-INF/editProfile.jsp b/src/main/webapp/WEB-INF/editProfile.jsp
new file mode 100644
index 0000000000..bab6857d89
--- /dev/null
+++ b/src/main/webapp/WEB-INF/editProfile.jsp
@@ -0,0 +1,16 @@
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+
+
+
+
+
+
+
+
+
+
Edit your profile below ${sessionScope.user.username}!
+
+
+
+
diff --git a/src/main/webapp/WEB-INF/login.jsp b/src/main/webapp/WEB-INF/login.jsp
new file mode 100644
index 0000000000..8cf2a99a9b
--- /dev/null
+++ b/src/main/webapp/WEB-INF/login.jsp
@@ -0,0 +1,28 @@
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/webapp/WEB-INF/logout.jsp b/src/main/webapp/WEB-INF/logout.jsp
new file mode 100644
index 0000000000..7bb5cff87b
--- /dev/null
+++ b/src/main/webapp/WEB-INF/logout.jsp
@@ -0,0 +1,28 @@
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%
+ request.getSession().removeAttribute("user");
+ request.getSession().invalidate();
+%>
+
+
+
+
+
+
+
+
+
+
+
You have been logged out
+ Redirecting to login page
+
+
+
+
diff --git a/src/main/webapp/WEB-INF/partials/head.jsp b/src/main/webapp/WEB-INF/partials/head.jsp
new file mode 100644
index 0000000000..5bc6b167b5
--- /dev/null
+++ b/src/main/webapp/WEB-INF/partials/head.jsp
@@ -0,0 +1,2 @@
+${param.title}
+
\ No newline at end of file
diff --git a/src/main/webapp/WEB-INF/partials/navbar.jsp b/src/main/webapp/WEB-INF/partials/navbar.jsp
new file mode 100644
index 0000000000..8cf38cf3e1
--- /dev/null
+++ b/src/main/webapp/WEB-INF/partials/navbar.jsp
@@ -0,0 +1,12 @@
+
+
+
+
diff --git a/src/main/webapp/WEB-INF/partials/style.jsp b/src/main/webapp/WEB-INF/partials/style.jsp
new file mode 100644
index 0000000000..698f93e71f
--- /dev/null
+++ b/src/main/webapp/WEB-INF/partials/style.jsp
@@ -0,0 +1,18 @@
+
\ No newline at end of file
diff --git a/src/main/webapp/WEB-INF/partials/userNavbar.jsp b/src/main/webapp/WEB-INF/partials/userNavbar.jsp
new file mode 100644
index 0000000000..3a5584b5c4
--- /dev/null
+++ b/src/main/webapp/WEB-INF/partials/userNavbar.jsp
@@ -0,0 +1,12 @@
+
+
+
diff --git a/src/main/webapp/WEB-INF/profile.jsp b/src/main/webapp/WEB-INF/profile.jsp
new file mode 100644
index 0000000000..3d1617cc3d
--- /dev/null
+++ b/src/main/webapp/WEB-INF/profile.jsp
@@ -0,0 +1,41 @@
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Welcome, ${sessionScope.user.username}!
+
+
+ ${sessionScope.user.email}!
+
+
+
+
+<%-- --%>
+<%--
Welcome, ${sessionScope.user.username}! --%>
+<%-- --%>
+
+
+
+
+
+<%--//TODO The profile page should display the username and email of the logged-in user and a list of links to all the ads a user has created in the AdLister.–%>--%>
+
+<%--//TODO When a user logs in the user should be redirected to their profile page.--%>
+<%--done--%>
+
+<%--//TODO The profile view should only be accessible to users that are logged in.--%>
+<%--done--%>
\ No newline at end of file
diff --git a/src/main/webapp/WEB-INF/register.jsp b/src/main/webapp/WEB-INF/register.jsp
new file mode 100644
index 0000000000..422478d7e4
--- /dev/null
+++ b/src/main/webapp/WEB-INF/register.jsp
@@ -0,0 +1,34 @@
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp
new file mode 100644
index 0000000000..1615c6e907
--- /dev/null
+++ b/src/main/webapp/index.jsp
@@ -0,0 +1,16 @@
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+
+
+
+
+
+
+
+
+
+
Welcome to the Adlister!
+
+
+