Skip to content

Commit e4536af

Browse files
committed
first commit: login,logout,create account,check accounts
1 parent 33a2b75 commit e4536af

32 files changed

Lines changed: 1144 additions & 47 deletions

.classpath

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,15 @@
2424
<attribute name="test" value="true"/>
2525
</attributes>
2626
</classpathentry>
27-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
28-
<attributes>
29-
<attribute name="maven.pomderived" value="true"/>
30-
</attributes>
31-
</classpathentry>
3227
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
3328
<attributes>
3429
<attribute name="maven.pomderived" value="true"/>
3530
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
3631
</attributes>
3732
</classpathentry>
38-
<classpathentry kind="src" path="target/generated-sources/annotations">
33+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
3934
<attributes>
40-
<attribute name="optional" value="true"/>
4135
<attribute name="maven.pomderived" value="true"/>
42-
<attribute name="ignore_optional_problems" value="true"/>
43-
<attribute name="m2e-apt" value="true"/>
44-
</attributes>
45-
</classpathentry>
46-
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
47-
<attributes>
48-
<attribute name="optional" value="true"/>
49-
<attribute name="maven.pomderived" value="true"/>
50-
<attribute name="ignore_optional_problems" value="true"/>
51-
<attribute name="m2e-apt" value="true"/>
52-
<attribute name="test" value="true"/>
5336
</attributes>
5437
</classpathentry>
5538
<classpathentry kind="output" path="target/classes"/>

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target/

.project

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
</arguments>
1717
</buildCommand>
1818
<buildCommand>
19-
<name>org.eclipse.m2e.core.maven2Builder</name>
19+
<name>org.eclipse.wst.validation.validationbuilder</name>
2020
<arguments>
2121
</arguments>
2222
</buildCommand>
2323
<buildCommand>
24-
<name>org.eclipse.wst.validation.validationbuilder</name>
24+
<name>org.eclipse.m2e.core.maven2Builder</name>
2525
<arguments>
2626
</arguments>
2727
</buildCommand>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
eclipse.preferences.version=1
22
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3-
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
4-
org.eclipse.jdt.core.compiler.compliance=1.5
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.compliance=1.8
55
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
66
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
77
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
88
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
99
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
1010
org.eclipse.jdt.core.compiler.processAnnotations=disabled
1111
org.eclipse.jdt.core.compiler.release=disabled
12-
org.eclipse.jdt.core.compiler.source=1.5
12+
org.eclipse.jdt.core.compiler.source=1.8
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
2-
<wb-module deploy-name="rocp-project-0.0.1-SNAPSHOT">
2+
3+
<wb-module deploy-name="RocpFirst-0.0.1-SNAPSHOT">
4+
35
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
6+
47
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
8+
59
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
10+
611
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
12+
713
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/annotations"/>
8-
<property name="context-root" value="rocp-project"/>
14+
915
<property name="java-output-path" value="/rocp-project/target/classes"/>
16+
<property name="context-root" value="RocpFirst"/>
17+
1018
</wb-module>
19+
1120
</project-modules>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<faceted-project>
33
<fixed facet="wst.jsdt.web"/>
4-
<installed facet="java" version="1.5"/>
54
<installed facet="jst.web" version="2.5"/>
65
<installed facet="wst.jsdt.web" version="1.0"/>
6+
<installed facet="java" version="1.8"/>
77
</faceted-project>

pom.xml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,40 @@
11
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>com.revature</groupId>
4-
<artifactId>rocp-project</artifactId>
4+
<artifactId>RocpFirst</artifactId>
55
<version>0.0.1-SNAPSHOT</version>
66
<packaging>war</packaging>
7+
<name>RocpFirst</name>
8+
<description>final project of ROCP-1 training</description>
9+
10+
<properties>
11+
<maven.compiler.source>1.8</maven.compiler.source>
12+
<maven.compiler.target>1.8</maven.compiler.target>
13+
</properties>
14+
15+
<dependencies>
16+
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
17+
<dependency>
18+
<groupId>org.postgresql</groupId>
19+
<artifactId>postgresql</artifactId>
20+
<version>42.2.14</version>
21+
</dependency>
22+
23+
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
24+
<dependency>
25+
<groupId>javax.servlet</groupId>
26+
<artifactId>javax.servlet-api</artifactId>
27+
<version>4.0.1</version>
28+
<scope>provided</scope>
29+
</dependency>
30+
31+
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
32+
<dependency>
33+
<groupId>com.fasterxml.jackson.core</groupId>
34+
<artifactId>jackson-databind</artifactId>
35+
<version>2.11.1</version>
36+
</dependency>
37+
38+
</dependencies>
39+
740
</project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.revature.controllers;
2+
3+
import java.util.List;
4+
5+
import com.revature.services.AcountsService;
6+
import com.revature.models.Record;
7+
8+
public class AcountsController {
9+
10+
11+
private final AcountsService as = new AcountsService();
12+
public List<Record> findAll(int userid) {
13+
return as.findAll(userid);
14+
}
15+
16+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package com.revature.controllers;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
6+
import javax.servlet.http.HttpServletRequest;
7+
import javax.servlet.http.HttpServletResponse;
8+
import javax.servlet.http.HttpSession;
9+
10+
import com.fasterxml.jackson.databind.ObjectMapper;
11+
import com.revature.models.LoginDTO;
12+
import com.revature.services.LoginService;
13+
14+
public class LoginController {
15+
16+
private static final LoginService ls = new LoginService();
17+
private static final ObjectMapper om = new ObjectMapper();
18+
19+
public void login(HttpServletRequest req, HttpServletResponse res) throws IOException {
20+
21+
if(req.getMethod().equals("POST")) {
22+
BufferedReader reader = req.getReader();
23+
24+
StringBuilder s = new StringBuilder();
25+
26+
String line = reader.readLine();
27+
28+
while(line != null) {
29+
s.append(line);
30+
line=reader.readLine();
31+
}
32+
33+
String body = new String(s);
34+
35+
System.out.println(body);
36+
37+
LoginDTO l = om.readValue(body, LoginDTO.class);
38+
39+
// res.getWriter().println(l.username+" "+l.password);
40+
41+
42+
if(ls.login(l).yn) {
43+
//Note - the no args getSession method will create a new session if one does not already exist for this client.
44+
HttpSession ses = req.getSession();
45+
ses.setAttribute("user", l);
46+
ses.setAttribute("loggedin", true);
47+
res.setStatus(200);
48+
res.getWriter().println("Login Successful!");
49+
} else {
50+
//will only return a session if one is already associated with the request, will not create a new one.
51+
HttpSession ses = req.getSession(false);
52+
if(ses!=null) {
53+
//This will throw out the session, the client will no longer have a session associated with their cookie.
54+
ses.invalidate();
55+
}
56+
res.setStatus(401);
57+
res.getWriter().println("Login Failed");
58+
}
59+
} else if (req.getMethod().equals("GET")
60+
&&(req.getParameterMap().containsKey("username")
61+
&&(req.getParameterMap().containsKey("password")))) {
62+
63+
LoginDTO l = new LoginDTO();
64+
l.username = req.getParameter("username");
65+
l.password = req.getParameter("password");
66+
67+
if(ls.login(l).yn) {
68+
//Note - the no args getSession method will create a new session if one does not already exist for this client.
69+
HttpSession ses = req.getSession();
70+
ses.setAttribute("user", l);
71+
ses.setAttribute("loggedin", true);
72+
res.setStatus(200);
73+
res.getWriter().println("Login Successful!");
74+
} else {
75+
//will only return a session if one is already associated with the request, will not create a new one.
76+
HttpSession ses = req.getSession(false);
77+
if(ses!=null) {
78+
//This will throw out the session, the client will no longer have a session associated with their cookie.
79+
ses.invalidate();
80+
}
81+
res.setStatus(401);
82+
res.getWriter().println("Login Failed");
83+
}
84+
}
85+
}
86+
87+
public void logout(HttpServletRequest req, HttpServletResponse res) throws IOException {
88+
HttpSession ses = req.getSession(false);
89+
90+
if(ses!=null) {
91+
LoginDTO l = (LoginDTO) ses.getAttribute("user");
92+
ses.invalidate();
93+
res.setStatus(200);
94+
res.getWriter().println(l.username+" you logged out.");
95+
} else {
96+
res.setStatus(400);
97+
res.getWriter().println("You must be logged in to log out.");
98+
}
99+
100+
}
101+
102+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.revature.models;
2+
3+
public class Account {
4+
5+
private int accountId; // primary key
6+
7+
private AccountStatus status;
8+
private AccountType type;
9+
10+
11+
public Account(AccountStatus status, AccountType type) {
12+
super();
13+
this.status = status;
14+
this.type = type;
15+
accountId=type.getTypeId()+(status.getStatusId()-1)*2;
16+
}
17+
18+
19+
public AccountStatus getStatus() {
20+
return status;
21+
}
22+
public void setStatus(AccountStatus status) {
23+
this.status = status;
24+
}
25+
public AccountType getType() {
26+
return type;
27+
}
28+
public void setType(AccountType type) {
29+
this.type = type;
30+
}
31+
32+
public int getAccountId() {
33+
return accountId;
34+
}
35+
36+
public void setAccountId(int accountId) {
37+
this.accountId = accountId;
38+
}
39+
40+
41+
}

0 commit comments

Comments
 (0)