Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
dmccormi
project-base
Commits
fd53ea00
Commit
fd53ea00
authored
Sep 19, 2016
by
Dave McCormick
Browse files
code tidy up
parent
e1016431
Changes
8
Hide whitespace changes
Inline
Side-by-side
app/controllers/TweetWebSocketActor.java
View file @
fd53ea00
...
...
@@ -38,8 +38,6 @@ public class TweetWebSocketActor extends UntypedActor {
this
.
topic
=
topic
;
this
.
out
=
out
;
System
.
out
.
println
(
"HERE IS YOUR TOPIC"
+
topic
);
/*
Our TweetListener, written as a Java 8 Lambda.
Whenever we receive a tweet, if it matches our topic, convert it to a JSON string, and send it to the client.
...
...
@@ -64,9 +62,8 @@ public class TweetWebSocketActor extends UntypedActor {
public
void
onReceive
(
Object
message
)
throws
Exception
{
if
(
message
instanceof
String
)
{
String
newTopic
=
message
.
toString
();
if
(
message
.
toString
().
isEmpty
()){
newTopic
=
".*"
;
System
.
out
.
println
(
"Received empty"
);
}
if
(
message
.
toString
().
isEmpty
()){
newTopic
=
".*"
;}
this
.
topic
=
newTopic
;
System
.
out
.
println
(
"Set topic to"
+
this
.
topic
);
}
}
...
...
app/controllers/UserController.java
View file @
fd53ea00
...
...
@@ -44,8 +44,6 @@ public class UserController extends Controller {
String
email
;
String
password
;
// We're doing this very basically, as Play forms are not in scope for the course
// (The unit prefers to teach things that are a little closer to the HTTP, rather than convenience wrappers)
try
{
email
=
request
().
body
().
asFormUrlEncoded
().
get
(
"email"
)[
0
];
password
=
request
().
body
().
asFormUrlEncoded
().
get
(
"password"
)[
0
];
...
...
@@ -72,8 +70,6 @@ public class UserController extends Controller {
String
email
;
String
password
;
// We're doing this very basically, as Play forms are not in scope for the course
// (The unit prefers to teach things that are a little closer to the HTTP, rather than convenience wrappers)
try
{
email
=
request
().
body
().
asFormUrlEncoded
().
get
(
"email"
)[
0
];
password
=
request
().
body
().
asFormUrlEncoded
().
get
(
"password"
)[
0
];
...
...
app/model/Session.java
View file @
fd53ea00
...
...
@@ -3,9 +3,7 @@ package model;
public
class
Session
{
String
id
;
String
ipAddress
;
long
since
;
public
Session
(
String
id
,
String
ipAddress
,
long
since
)
{
...
...
app/model/User.java
View file @
fd53ea00
...
...
@@ -6,12 +6,9 @@ import java.util.concurrent.ConcurrentHashMap;
public
class
User
{
String
id
;
String
email
;
String
hash
;
/**
* We need to hold the user's active sessions; this stands in for our database table
*/
...
...
@@ -35,13 +32,6 @@ public class User {
return
hash
;
}
/**
* Is a particular session active on this user?
*/
public
boolean
hasSession
(
String
sessionId
)
{
return
activeSessions
.
containsKey
(
sessionId
);
}
public
Session
[]
getSessions
()
{
Collection
<
Session
>
values
=
activeSessions
.
values
();
return
values
.
toArray
(
new
Session
[
values
.
size
()]);
...
...
app/model/UserService.java
View file @
fd53ea00
...
...
@@ -3,18 +3,12 @@ package model;
import
com.mongodb.MongoClient
;
import
com.mongodb.client.MongoCollection
;
import
com.mongodb.client.MongoDatabase
;
import
org.bson.BsonDocument
;
import
org.bson.BsonWriter
;
import
org.bson.Document
;
import
org.bson.types.ObjectId
;
import
org.mindrot.jbcrypt.BCrypt
;
import
sun.reflect.generics.reflectiveObjects.NotImplementedException
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.concurrent.ConcurrentHashMap
;
public
class
UserService
{
...
...
@@ -26,12 +20,11 @@ public class UserService {
}
protected
MongoDatabase
getDB
()
{
// TODO: Change your database name, to avoid clashing with others on turing
return
mongoClient
.
getDatabase
(
"comp560_dmccormi"
);
}
protected
MongoCollection
<
Document
>
get
Chitter
Collection
()
{
return
getDB
().
getCollection
(
"
chitter
User"
);
protected
MongoCollection
<
Document
>
get
HawkEye
Collection
()
{
return
getDB
().
getCollection
(
"
hawkEye
User"
);
}
/**
...
...
@@ -54,10 +47,9 @@ public class UserService {
}
}
public
User
registerUser
(
User
u
)
{
// Let's first check the user isn't already registered
if
(
get
Chitter
Collection
().
find
(
new
Document
(
"email"
,
u
.
getEmail
())).
first
()
!=
null
)
{
if
(
get
HawkEye
Collection
().
find
(
new
Document
(
"email"
,
u
.
getEmail
())).
first
()
!=
null
)
{
throw
new
IllegalArgumentException
(
"That email address has already been registered"
);
}
...
...
@@ -67,7 +59,7 @@ public class UserService {
}
public
User
getUser
(
String
id
)
{
Document
d
=
get
Chitter
Collection
().
find
(
new
Document
(
"_id"
,
new
ObjectId
(
id
))).
first
();
Document
d
=
get
HawkEye
Collection
().
find
(
new
Document
(
"_id"
,
new
ObjectId
(
id
))).
first
();
if
(
d
!=
null
)
{
return
userFromBson
(
d
);
}
else
{
...
...
@@ -79,7 +71,7 @@ public class UserService {
* Get the user by email and password, returning null if they don't exist (or the password is wrong)
*/
public
User
getUser
(
String
email
,
String
password
)
{
Document
d
=
get
Chitter
Collection
().
find
(
new
Document
(
"email"
,
email
)).
first
();
Document
d
=
get
HawkEye
Collection
().
find
(
new
Document
(
"email"
,
email
)).
first
();
// I wrote userFromBson to accept nulls
User
u
=
userFromBson
(
d
);
...
...
@@ -94,7 +86,7 @@ public class UserService {
* Get the user who is logged in with this session, if there is one
*/
public
User
getUserFromSession
(
String
sessionId
)
{
Document
d
=
get
Chitter
Collection
().
find
(
new
Document
(
"sessions._id"
,
new
ObjectId
(
sessionId
))).
first
();
Document
d
=
get
HawkEye
Collection
().
find
(
new
Document
(
"sessions._id"
,
new
ObjectId
(
sessionId
))).
first
();
return
userFromBson
(
d
);
}
...
...
@@ -152,11 +144,11 @@ public class UserService {
}
protected
void
insert
(
User
u
)
{
get
Chitter
Collection
().
insertOne
(
userToBson
(
u
));
get
HawkEye
Collection
().
insertOne
(
userToBson
(
u
));
}
public
void
update
(
User
u
)
{
get
Chitter
Collection
().
replaceOne
(
new
Document
(
"_id"
,
new
ObjectId
(
u
.
getId
())),
userToBson
(
u
));
get
HawkEye
Collection
().
replaceOne
(
new
Document
(
"_id"
,
new
ObjectId
(
u
.
getId
())),
userToBson
(
u
));
}
}
\ No newline at end of file
app/views/application/login.scala.html
View file @
fd53ea00
...
...
@@ -19,9 +19,11 @@
<!-- Custom styles for this template -->
<link
href=
"/assets/bootstrap/css/cover.css"
rel=
"stylesheet"
>
<style>
button
,
input
{
color
:
black
;
}
</style>
</head>
<body>
<h2>
Log in
</h2>
...
...
app/views/application/register.scala.html
View file @
fd53ea00
...
...
@@ -19,7 +19,9 @@
<!-- Custom styles for this template -->
<link
href=
"/assets/bootstrap/css/cover.css"
rel=
"stylesheet"
>
<style>
button
,
input
{
color
:
black
;
}
</style>
</head>
<body>
...
...
public/javascript/dynamicHeatMap.js
View file @
fd53ea00
...
...
@@ -51,7 +51,7 @@ angular.module("myApp", ['uiGmapgoogle-maps'])
showHeat
:
true
};
var
ws
=
new
WebSocket
(
"
ws://127.0.0.1:9000/websocket?topic=
Day
"
);
var
ws
=
new
WebSocket
(
"
ws://127.0.0.1:9000/websocket?topic=
"
);
// binding model for the UI
$scope
.
messages
=
[];
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment