Skip to content

completed all tasks but 6 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
13 changes: 0 additions & 13 deletions .classpath

This file was deleted.

31 changes: 0 additions & 31 deletions .project

This file was deleted.

12 changes: 0 additions & 12 deletions .settings/.jsdtscope

This file was deleted.

2 changes: 0 additions & 2 deletions .settings/org.eclipse.core.resources.prefs

This file was deleted.

2 changes: 0 additions & 2 deletions .settings/org.eclipse.core.runtime.prefs

This file was deleted.

15 changes: 0 additions & 15 deletions .settings/org.eclipse.jdt.core.prefs

This file was deleted.

8 changes: 0 additions & 8 deletions .settings/org.eclipse.wst.common.component

This file was deleted.

10 changes: 0 additions & 10 deletions .settings/org.eclipse.wst.common.project.facet.core.xml

This file was deleted.

1 change: 0 additions & 1 deletion .settings/org.eclipse.wst.jsdt.ui.superType.container

This file was deleted.

1 change: 0 additions & 1 deletion .settings/org.eclipse.wst.jsdt.ui.superType.name

This file was deleted.

111 changes: 111 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<name>demo Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>

<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts-core</artifactId>
<version>1.3.10</version>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.2.224</version>
</dependency>

<dependency>
<groupId>org.tinylog</groupId>
<artifactId>tinylog-api</artifactId>
<version>2.3.1</version>
</dependency>

<dependency>
<groupId>org.tinylog</groupId>
<artifactId>tinylog-impl</artifactId>
<version>2.3.1</version>
</dependency>

</dependencies>

<build>
<finalName>demo</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
6 changes: 3 additions & 3 deletions src/main/java/com/my_app/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,17 @@ private void initDbCountriesAndCities(Connection conn) throws SQLException {
private void initDbUsers(Connection conn) throws SQLException {
try (final Statement stmt = conn.createStatement()) {
stmt.executeUpdate(
"CREATE TABLE \"USER\" (ID IDENTITY NOT NULL PRIMARY KEY, USERNAME VARCHAR(255) UNIQUE NOT NULL, PASSWORD VARCHAR(255) NOT NULL, CITY_ID BIGINT NOT NULL, FOREIGN KEY (CITY_ID) REFERENCES CITY(ID))");
"CREATE TABLE \"USER\" (ID IDENTITY NOT NULL PRIMARY KEY, USERNAME VARCHAR(255) UNIQUE NOT NULL, PASSWORD VARCHAR(255) NOT NULL, EMAIL VARCHAR(255) NOT NULL, CITY_ID BIGINT NOT NULL, FOREIGN KEY (CITY_ID) REFERENCES CITY(ID))");
}

final CityRepository cityRepository = new CityRepositoryImpl(conn, new CountryRepositoryImpl(conn));
final UserRepository userRepository = new UserRepositoryImpl(conn, cityRepository);

userRepository.save(new User("admin", "admin", cityRepository.findById((long) this.random.nextInt(49) + 1)));
userRepository.save(new User("admin", "admin", "admin@example.com",cityRepository.findById((long) this.random.nextInt(49) + 1)));

for (int i = 1; i < 11; i++) {
userRepository.save(
new User("user" + i, "user" + i, cityRepository.findById((long) this.random.nextInt(49) + 1)));
new User("user" + i, "user" + i, "user" + i + "@example.com", cityRepository.findById((long) this.random.nextInt(49) + 1)));
}

Logger.debug("All users created: {}", userRepository.findAll());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.apache.struts.action.ActionMapping;

import com.google.gson.Gson;

import com.my_app.model.City;
import com.my_app.service.CityService;
import com.my_app.service.factory.CityServiceFactory;
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/com/my_app/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,26 @@ public class User {
private String username;
private String password;
private City city;
private String email;

public User() {
}

public User(String username, String password, City city) {
public User(String username, String password, String email, City city) {
super();
this.username = username;
this.password = password;
this.city = city;
this.email = email;
}

public User(Long id, String username, String password, City city) {
public User(Long id, String username, String password, String email, City city) {
super();
this.id = id;
this.username = username;
this.password = password;
this.city = city;
this.email = email;
}

public Long getId() {
Expand Down Expand Up @@ -60,9 +63,19 @@ public boolean isNew() {
return this.id == null;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

@Override
public String toString() {
return String.format("User [id=%s, username=%s, password=%s, city=%s]", id, username, password, city);
return String.format("User [id=%s, username=%s, password=%s, email=%s, city=%s]", id, username, password, email,
city);

}

}
27 changes: 27 additions & 0 deletions src/main/java/com/my_app/page/logout/LogoutAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.my_app.page.logout;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class LogoutAction extends Action {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {

// Get the current session associated with this request
HttpSession session = request.getSession(false);

// If there's a session, invalidate it
if (session != null) {
session.invalidate();
}

return mapping.findForward("loginPage");
}
}
26 changes: 26 additions & 0 deletions src/main/java/com/my_app/page/privateArea/privateAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.my_app.page.privateArea;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.my_app.utils.LoginUtils;

public class privateAction extends Action {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm actionForm, HttpServletRequest req,
HttpServletResponse res) throws Exception {

if (LoginUtils.isUserLoggedIn(req.getSession())) {
return mapping.findForward("privatePage");
} else {
return mapping.findForward("actionLoginRedir");
}
}

}
9 changes: 9 additions & 0 deletions src/main/java/com/my_app/page/user/save/UserSaveForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class UserSaveForm extends BaseActionForm {
private Long userId;
private String username;
private String password;
private String email;
private Long countryId;
private Long cityId;

Expand Down Expand Up @@ -79,4 +80,12 @@ public static long getSerialversionuid() {
return serialVersionUID;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public User toUser(UserSaveForm form) {
final City city = new City(form.getCityId());

return new User(Long.valueOf(0).equals(form.getUserId()) ? null : form.getUserId(), form.getUsername(),
form.getPassword(), city);
form.getPassword(), form.getEmail(), city);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ public UserSaveForm mapTo(User user, UserSaveForm form) {

form.setUserId(user.getId());
form.setUsername(user.getUsername());
form.setEmail(user.getEmail());
form.setCountryId(user.getCity().getCountry().getId());
form.setCityId(user.getCity().getId());


return form;
}

Expand Down
Loading