forked from lutfialquraan/literatum-lutfi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5d0136
commit 178c3a2
Showing
19 changed files
with
382 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
create table license | ||
( | ||
id int not null, | ||
email varchar not null, | ||
license varchar | ||
); | ||
|
||
create unique index license_id_uindex | ||
on license (id); | ||
|
||
alter table license_table | ||
add constraint license_pk | ||
primary key (id); | ||
|
||
create sequence license_id_seq; | ||
|
||
alter table license_table alter column id set default nextval('public.license_id_seq'); | ||
|
||
alter sequence license_id_seq owned by license.id; | ||
|
||
alter table license_table alter column license type date using license::date; | ||
|
||
|
53 changes: 53 additions & 0 deletions
53
src/main/java/controller/actions/admin/license/AddLicenseAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package controller.actions.admin.users; | ||
|
||
import at.favre.lib.crypto.bcrypt.BCrypt; | ||
import controller.actions.IAction; | ||
import model.database.DAO; | ||
import model.database.LicenseDAO; | ||
import model.database.UsersDAO; | ||
import model.enums.Role; | ||
import model.license.License; | ||
import model.users.AbstractBaseUser; | ||
import model.users.Admin; | ||
import model.users.BasicUser; | ||
import model.users.SuperAdmin; | ||
import utilities.AccessControl; | ||
|
||
import javax.servlet.RequestDispatcher; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.time.LocalDate; | ||
|
||
public class AddLicenseAction implements IAction { | ||
@Override | ||
public void doPost(HttpServletRequest request, HttpServletResponse response) throws Exception { | ||
|
||
Role role = (Role) request.getSession().getAttribute("role"); | ||
if (AccessControl.isLoggedIn(request) && (AccessControl.isAdmin(role) || AccessControl.isSuperAdmin(role))) { | ||
String email = request.getParameter("email"); | ||
LocalDate date = LocalDate.now(); | ||
date = date.plusDays(Integer.parseInt(request.getParameter("date"))); | ||
|
||
License license = new License(email,date); | ||
|
||
DAO licenseDAO = new LicenseDAO(); | ||
licenseDAO.insert(license); | ||
response.sendRedirect("/admin/showLicense"); | ||
} else { | ||
response.sendRedirect("/admin"); | ||
} | ||
} | ||
|
||
@Override | ||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws Exception { | ||
|
||
Role role = (Role) request.getSession().getAttribute("role"); | ||
if (AccessControl.isLoggedIn(request) && (AccessControl.isAdmin(role) || AccessControl.isSuperAdmin(role))) { | ||
RequestDispatcher requestDispatcher = request.getRequestDispatcher("jsp/admin/license/add-license.jsp"); | ||
requestDispatcher.forward(request, response); | ||
} else { | ||
response.sendRedirect("/admin"); | ||
} | ||
|
||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/controller/actions/admin/license/ShowHomeLicenseAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package controller.actions.admin.license; | ||
|
||
import controller.actions.IAction; | ||
import model.enums.Role; | ||
import utilities.AccessControl; | ||
|
||
import javax.servlet.RequestDispatcher; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
public class ShowHomeLicenseAction implements IAction { | ||
@Override | ||
public void doPost(HttpServletRequest request, HttpServletResponse response) throws Exception { | ||
doGet(request,response); | ||
} | ||
|
||
@Override | ||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws Exception { | ||
Role role = (Role) request.getSession().getAttribute("role"); | ||
if (AccessControl.isLoggedIn(request) && (AccessControl.isAdmin(role) || AccessControl.isSuperAdmin(role))) { | ||
RequestDispatcher requestDispatcher = request.getRequestDispatcher("jsp/admin/license/admin-license-home.jsp"); | ||
requestDispatcher.forward(request, response); | ||
} else { | ||
response.sendRedirect("/admin"); | ||
} | ||
|
||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/controller/actions/admin/license/ShowLicensesAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package controller.actions.admin.license; | ||
|
||
import controller.actions.IAction; | ||
import model.contents.ContentMeta; | ||
import model.database.ContentMetaDAO; | ||
import model.database.DAO; | ||
import model.database.LicenseDAO; | ||
import model.enums.Role; | ||
import model.license.License; | ||
import utilities.AccessControl; | ||
|
||
import javax.servlet.RequestDispatcher; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.util.List; | ||
|
||
public class ShowLicensesAction implements IAction { | ||
@Override | ||
public void doPost(HttpServletRequest request, HttpServletResponse response) throws Exception { | ||
doGet(request,response); | ||
} | ||
|
||
@Override | ||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws Exception { | ||
Role role = (Role) request.getSession().getAttribute("role"); | ||
if (AccessControl.isLoggedIn(request) && (AccessControl.isAdmin(role) || AccessControl.isSuperAdmin(role))) { | ||
DAO licenseDAO = new LicenseDAO(); | ||
List<License> license = (List<License>) (List<?>) licenseDAO.selectAll(); | ||
request.setAttribute("license", license); | ||
RequestDispatcher requestDispatcher = request.getRequestDispatcher("jsp/admin/license/show-licenses.jsp"); | ||
requestDispatcher.forward(request, response); | ||
} else { | ||
response.sendRedirect("/admin"); | ||
} | ||
|
||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../controller/actions/user/LogInAction.java → ...ller/actions/user/access/LogInAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...controller/actions/user/LogoutAction.java → ...ler/actions/user/access/LogoutAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...controller/actions/user/SignUpAction.java → ...ler/actions/user/access/SignUpAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ller/actions/user/ShowArticlesAction.java → ...ions/user/preview/ShowArticlesAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ntroller/actions/user/ShowHomeAction.java → .../actions/user/preview/ShowHomeAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package controller.actions.user; | ||
package controller.actions.user.preview; | ||
|
||
import controller.actions.IAction; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,105 @@ | ||
package model.database; | ||
|
||
import model.license.License; | ||
|
||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.Statement; | ||
import java.time.LocalDate; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class LicenseDAO extends DAO { | ||
@Override | ||
public void insert(Object object) { | ||
|
||
try { | ||
License license = (License) object; | ||
String sql = "insert into license_table (email,license) values (?,?)"; | ||
PreparedStatement preparedStatement = connectionPool.getConnection().prepareStatement(sql); | ||
preparedStatement.setString(1, license.getEmail()); | ||
preparedStatement.setObject(2, license.getDate()); | ||
preparedStatement.execute(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public void delete(Object object) { | ||
|
||
try { | ||
String email = (String) object; | ||
String sql = "delete from license_table where email = ? "; | ||
PreparedStatement preparedStatement = connectionPool.getConnection().prepareStatement(sql); | ||
preparedStatement.setString(1, email); | ||
preparedStatement.execute(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public void update(Object object) { | ||
|
||
try { | ||
License license = (License) object; | ||
String sql = "update license_table set license =? where id = ? ;"; | ||
PreparedStatement preparedStatement = connectionPool.getConnection().prepareStatement(sql); | ||
preparedStatement.setObject(1,license.getDate()); | ||
preparedStatement.setInt(2, license.getId()); | ||
preparedStatement.execute(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public List<Object> selectAll() { | ||
return null; | ||
List<Object> licenses = new ArrayList<>(); | ||
Statement myStat; | ||
ResultSet myRes; | ||
try { | ||
String sql = "select * from license_table order by id"; | ||
myStat = connectionPool.getConnection().createStatement(); | ||
myRes = myStat.executeQuery(sql); | ||
licenses = getLicense(myRes); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
return licenses; | ||
} | ||
|
||
@Override | ||
public Object select(Object object) { | ||
return null; | ||
License license = null; | ||
PreparedStatement myStat; | ||
String email = (String) object; | ||
ResultSet myRes = null; | ||
try { | ||
String sql = "select * from license_table where email = ?"; | ||
myStat = connectionPool.getConnection().prepareStatement(sql); | ||
myStat.setString(1, email); | ||
myRes = myStat.executeQuery(); | ||
license = (License) getLicense(myRes).get(0); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
return license; | ||
} | ||
|
||
private List<Object> getLicense(ResultSet resultSet) { | ||
List<Object> licenses = new ArrayList<>(); | ||
License theLicense = null; | ||
try { | ||
while (resultSet.next()) { | ||
|
||
String email = resultSet.getString("email"); | ||
LocalDate license = resultSet.getObject("license",LocalDate.class); | ||
int id = resultSet.getInt("id"); | ||
theLicense = new License(id,email,license); | ||
licenses.add(theLicense); | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
return licenses; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,44 @@ | ||
package model.license; | ||
|
||
import java.time.LocalDate; | ||
|
||
public class License { | ||
private int id; | ||
private String email; | ||
private LocalDate date; | ||
|
||
public License(int id, String email, LocalDate date) { | ||
this.id = id; | ||
this.email = email; | ||
this.date = date; | ||
} | ||
|
||
public License(String email, LocalDate date) { | ||
this.email = email; | ||
this.date = date; | ||
} | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
public String getEmail() { | ||
return email; | ||
} | ||
|
||
public void setEmail(String email) { | ||
this.email = email; | ||
} | ||
|
||
public LocalDate getDate() { | ||
return date; | ||
} | ||
|
||
public void setDate(LocalDate date) { | ||
this.date = date; | ||
} | ||
} |
Oops, something went wrong.