Commit fd53ea00 authored by Dave McCormick's avatar Dave McCormick
Browse files

code tidy up

parent e1016431
......@@ -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);
}
}
......
......@@ -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];
......
......@@ -3,9 +3,7 @@ package model;
public class Session {
String id;
String ipAddress;
long since;
public Session(String id, String ipAddress, long since) {
......
......@@ -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()]);
......
......@@ -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> getChitterCollection() {
return getDB().getCollection("chitterUser");
protected MongoCollection<Document> getHawkEyeCollection() {
return getDB().getCollection("hawkEyeUser");
}
/**
......@@ -54,10 +47,9 @@ public class UserService {
}
}
public User registerUser(User u) {
// Let's first check the user isn't already registered
if (getChitterCollection().find(new Document("email", u.getEmail())).first() != null) {
if (getHawkEyeCollection().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 = getChitterCollection().find(new Document("_id", new ObjectId(id))).first();
Document d = getHawkEyeCollection().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 = getChitterCollection().find(new Document("email", email)).first();
Document d = getHawkEyeCollection().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 = getChitterCollection().find(new Document("sessions._id", new ObjectId(sessionId))).first();
Document d = getHawkEyeCollection().find(new Document("sessions._id", new ObjectId(sessionId))).first();
return userFromBson(d);
}
......@@ -152,11 +144,11 @@ public class UserService {
}
protected void insert(User u) {
getChitterCollection().insertOne(userToBson(u));
getHawkEyeCollection().insertOne(userToBson(u));
}
public void update(User u) {
getChitterCollection().replaceOne(new Document("_id", new ObjectId(u.getId())), userToBson(u));
getHawkEyeCollection().replaceOne(new Document("_id", new ObjectId(u.getId())), userToBson(u));
}
}
\ No newline at end of file
......@@ -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>
......
......@@ -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>
......
......@@ -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 = [];
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment