Renamed pages
This commit is contained in:
parent
cfb77bae46
commit
ea45675d56
3 changed files with 69 additions and 70 deletions
|
@ -1,49 +1,49 @@
|
||||||
package io.github.norbipeti.chat.server.page;
|
package io.github.norbipeti.chat.server.page;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.mindrot.jbcrypt.BCrypt;
|
import org.mindrot.jbcrypt.BCrypt;
|
||||||
|
|
||||||
import com.sun.net.httpserver.HttpExchange;
|
import com.sun.net.httpserver.HttpExchange;
|
||||||
|
|
||||||
import io.github.norbipeti.chat.server.IOHelper;
|
import io.github.norbipeti.chat.server.IOHelper;
|
||||||
import io.github.norbipeti.chat.server.db.DataProvider;
|
import io.github.norbipeti.chat.server.db.DataProvider;
|
||||||
import io.github.norbipeti.chat.server.db.domain.User;
|
import io.github.norbipeti.chat.server.db.domain.User;
|
||||||
|
|
||||||
public class LoginPage extends Page {
|
public class LoginAjaxPage extends Page {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handlePage(HttpExchange exchange) throws IOException {
|
public void handlePage(HttpExchange exchange) throws IOException {
|
||||||
JSONObject post = IOHelper.GetPOSTJSON(exchange);
|
JSONObject post = IOHelper.GetPOSTJSON(exchange);
|
||||||
if (post == null || !post.has("email") || !post.has("pass")) {
|
if (post == null || !post.has("email") || !post.has("pass")) {
|
||||||
IOHelper.Redirect("/", exchange);
|
IOHelper.Redirect("/", exchange);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try (DataProvider provider = new DataProvider()) {
|
try (DataProvider provider = new DataProvider()) {
|
||||||
User loginuser = null;
|
User loginuser = null;
|
||||||
for (User user : provider.getUsers()) {
|
for (User user : provider.getUsers()) {
|
||||||
if (user.getEmail().equals(post.get("email"))) {
|
if (user.getEmail().equals(post.get("email"))) {
|
||||||
loginuser = user;
|
loginuser = user;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (loginuser == null || !BCrypt.checkpw(post.getString("pass"), loginuser.getPassword())) {
|
if (loginuser == null || !BCrypt.checkpw(post.getString("pass"), loginuser.getPassword())) {
|
||||||
IOHelper.SendResponse(200, (doc) -> {
|
IOHelper.SendResponse(200, (doc) -> {
|
||||||
doc.appendElement("p").text("The username or password is invalid.");
|
doc.appendElement("p").text("The username or password is invalid.");
|
||||||
return doc;
|
return doc;
|
||||||
}, exchange);
|
}, exchange);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
IOHelper.LoginUser(exchange, loginuser, provider);
|
IOHelper.LoginUser(exchange, loginuser, provider);
|
||||||
IOHelper.SendResponse(200, "Success", exchange);
|
IOHelper.SendResponse(200, "Success", exchange);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String GetName() {
|
public String GetName() {
|
||||||
return "login";
|
return "login";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,19 @@
|
||||||
package io.github.norbipeti.chat.server.page;
|
package io.github.norbipeti.chat.server.page;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import com.sun.net.httpserver.HttpExchange;
|
import com.sun.net.httpserver.HttpExchange;
|
||||||
|
|
||||||
public class MessageAjaxPage extends Page {
|
public class MessageAjaxPage extends Page {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String GetName() {
|
public String GetName() {
|
||||||
return "message";
|
return "message";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handlePage(HttpExchange exchange) throws IOException {
|
public void handlePage(HttpExchange exchange) throws IOException {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ import io.github.norbipeti.chat.server.IOHelper;
|
||||||
import io.github.norbipeti.chat.server.db.DataProvider;
|
import io.github.norbipeti.chat.server.db.DataProvider;
|
||||||
import io.github.norbipeti.chat.server.db.domain.User;
|
import io.github.norbipeti.chat.server.db.domain.User;
|
||||||
|
|
||||||
public class RegisterPage extends Page {
|
public class RegisterAjaxPage extends Page {
|
||||||
@Override
|
@Override
|
||||||
public void handlePage(HttpExchange exchange) throws IOException {
|
public void handlePage(HttpExchange exchange) throws IOException {
|
||||||
JSONObject post = IOHelper.GetPOSTJSON(exchange);
|
JSONObject post = IOHelper.GetPOSTJSON(exchange);
|
||||||
|
|
Loading…
Reference in a new issue