Reworked login and register screen.
This commit is contained in:
@@ -60,7 +60,7 @@ public class CachedPlayerDAO implements PlayerDAO, Cached {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerUser(String login, String password, String remoteAddr) throws SQLException {
|
||||
public boolean registerUser(String login, String password, String remoteAddr) throws SQLException, LoginInvalidException {
|
||||
boolean registered = _delegate.registerUser(login, password, remoteAddr);
|
||||
if (registered)
|
||||
_playerByName.remove(login);
|
||||
|
||||
@@ -104,7 +104,7 @@ public class DbPlayerDAO implements PlayerDAO {
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized boolean registerUser(String login, String password, String remoteAddr) throws SQLException {
|
||||
public synchronized boolean registerUser(String login, String password, String remoteAddr) throws SQLException, LoginInvalidException {
|
||||
boolean result = validateLogin(login);
|
||||
if (!result)
|
||||
return false;
|
||||
@@ -127,13 +127,13 @@ public class DbPlayerDAO implements PlayerDAO {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean validateLogin(String login) throws SQLException {
|
||||
private boolean validateLogin(String login) throws SQLException, LoginInvalidException {
|
||||
if (login.length() < 2 || login.length() > 10)
|
||||
return false;
|
||||
throw new LoginInvalidException();
|
||||
for (int i = 0; i < login.length(); i++) {
|
||||
char c = login.charAt(i);
|
||||
if (!validLoginChars.contains("" + c))
|
||||
return false;
|
||||
throw new LoginInvalidException();
|
||||
}
|
||||
|
||||
String lowerCase = login.toLowerCase();
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.gempukku.lotro.db;
|
||||
|
||||
public class LoginInvalidException extends Exception {
|
||||
}
|
||||
@@ -15,7 +15,7 @@ public interface PlayerDAO {
|
||||
|
||||
public boolean updateLastReward(Player player, int previousReward, int currentReward) throws SQLException;
|
||||
|
||||
public boolean registerUser(String login, String password, String remoteAddr) throws SQLException;
|
||||
public boolean registerUser(String login, String password, String remoteAddr) throws SQLException, LoginInvalidException;
|
||||
|
||||
public void updateLastLoginIp(String login, String remoteAddr) throws SQLException;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.gempukku.lotro.server;
|
||||
|
||||
import com.gempukku.lotro.chat.ChatServer;
|
||||
import com.gempukku.lotro.db.LoginInvalidException;
|
||||
import com.gempukku.lotro.db.PlayerStatistic;
|
||||
import com.gempukku.lotro.db.vo.GameHistoryEntry;
|
||||
import com.gempukku.lotro.game.*;
|
||||
@@ -52,7 +53,7 @@ public class ServerResource extends AbstractResource {
|
||||
@Path("/login")
|
||||
@POST
|
||||
@Produces("text/html")
|
||||
public String login(
|
||||
public void login(
|
||||
@FormParam("login") String login,
|
||||
@FormParam("password") String password,
|
||||
@Context HttpServletRequest request) throws Exception {
|
||||
@@ -60,12 +61,11 @@ public class ServerResource extends AbstractResource {
|
||||
if (player != null) {
|
||||
if (player.getType().contains("u")) {
|
||||
logUser(request, login);
|
||||
return "<script>location.href='hall.html';</script>";
|
||||
} else {
|
||||
return "You were banned. If you think it was a mistake, please write an e-mail to marcins78@gmail.com";
|
||||
throw new WebApplicationException(Response.Status.FORBIDDEN);
|
||||
}
|
||||
} else {
|
||||
return "Invalid login or password. Please try again.<br/>" + getLoginHTML();
|
||||
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,30 +79,21 @@ public class ServerResource extends AbstractResource {
|
||||
@Path("/register")
|
||||
@POST
|
||||
@Produces("text/html")
|
||||
public String register(
|
||||
public void register(
|
||||
@FormParam("login") String login,
|
||||
@FormParam("password") String password,
|
||||
@Context HttpServletRequest request) throws Exception {
|
||||
if (_playerDao.registerUser(login, password, request.getRemoteAddr())) {
|
||||
logUser(request, login);
|
||||
return "<script>location.href='hall.html';</script>";
|
||||
} else {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("User with this name already exists or your login is invalid.<br/>");
|
||||
sb.append("Login must be between 2-10 characters long, contain only<br/>english letters, numbers or _ (underscore) and - (dash) characters.<br/>");
|
||||
sb.append("Try to <button id='clickToRegister'>register</button> again.");
|
||||
return sb.toString();
|
||||
@Context HttpServletRequest request) throws SQLException {
|
||||
try {
|
||||
if (_playerDao.registerUser(login, password, request.getRemoteAddr())) {
|
||||
logUser(request, login);
|
||||
} else {
|
||||
throw new WebApplicationException(Response.Status.CONFLICT);
|
||||
}
|
||||
} catch (LoginInvalidException exp) {
|
||||
throw new WebApplicationException(Response.Status.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
private String getLoginHTML() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Login: <input id='login' type='text'><br/>");
|
||||
sb.append("Password: <input id='password' type='password'><br/>");
|
||||
sb.append("<button id='loginButton'>Login</button>");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Path("/replay/{replayId}")
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_XML)
|
||||
@@ -195,19 +186,12 @@ public class ServerResource extends AbstractResource {
|
||||
@QueryParam("participantId") String participantId,
|
||||
@Context HttpServletRequest request) throws ParserConfigurationException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
participantId = getUserNameIfLogged(request);
|
||||
if (participantId != null) {
|
||||
sb.append("<script>location.href='hall.html';</script>");
|
||||
} else {
|
||||
sb.append("You are not logged in, log in below or <button id='clickToRegister'>register</button>.");
|
||||
int day = 1000 * 60 * 60 * 24;
|
||||
int week = 1000 * 60 * 60 * 24 * 7;
|
||||
sb.append("<div class='status'>Tables count: ").append(_hallServer.getTablesCount()).append(", players in hall: ").append(_chatServer.getChatRoom("Game Hall").getUsersInRoom().size())
|
||||
.append(", games played in last 24 hours: ").append(_gameHistoryService.getGamesPlayedCount(System.currentTimeMillis() - day, day))
|
||||
.append(",<br/> active players in last week: ").append(_gameHistoryService.getActivePlayersCount(System.currentTimeMillis() - week, week))
|
||||
.append("</div>");
|
||||
sb.append(getLoginHTML());
|
||||
}
|
||||
|
||||
int day = 1000 * 60 * 60 * 24;
|
||||
int week = 1000 * 60 * 60 * 24 * 7;
|
||||
sb.append("Tables count: ").append(_hallServer.getTablesCount()).append(", players in hall: ").append(_chatServer.getChatRoom("Game Hall").getUsersInRoom().size())
|
||||
.append(", games played in last 24 hours: ").append(_gameHistoryService.getGamesPlayedCount(System.currentTimeMillis() - day, day))
|
||||
.append(",<br/> active players in last week: ").append(_gameHistoryService.getActivePlayersCount(System.currentTimeMillis() - week, week));
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ response.setDateHeader ("Expires", -1);
|
||||
</style>
|
||||
|
||||
<%@ include file="js.inc" %>
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
jQuery.fn.center = function () {
|
||||
this.css("position", "absolute");
|
||||
@@ -35,59 +35,109 @@ response.setDateHeader ("Expires", -1);
|
||||
alert("Unable to contact the server");
|
||||
});
|
||||
|
||||
function processResponse(html) {
|
||||
$("#message").append(html).center();
|
||||
attachEvents();
|
||||
}
|
||||
|
||||
$(document).ready(
|
||||
function () {
|
||||
comm.getStatus(processResponse);
|
||||
});
|
||||
|
||||
function attachEvents() {
|
||||
var loginButton = $("#loginButton");
|
||||
if (loginButton != null) {
|
||||
loginButton.button().click(
|
||||
function () {
|
||||
var login = $("#login").val();
|
||||
var password = $("#password").val();
|
||||
$("#message").html("");
|
||||
comm.login(login, password, processResponse);
|
||||
});
|
||||
}
|
||||
|
||||
var registerButton = $("#registerButton");
|
||||
if (registerButton != null) {
|
||||
registerButton.button().click(
|
||||
function () {
|
||||
var login = $("#login").val();
|
||||
var password = $("#password").val();
|
||||
var password2 = $("#password2").val();
|
||||
if (password != password2) {
|
||||
alert("Password and Password repeated are different!");
|
||||
} else {
|
||||
$("#message").html("");
|
||||
comm.register(login, password, processResponse);
|
||||
function register() {
|
||||
var login = $("#login").val();
|
||||
var password = $("#password").val();
|
||||
var password2 = $("#password2").val();
|
||||
if (password != password2) {
|
||||
$(".error").html("Password and Password repeated are different! Try again");
|
||||
} else {
|
||||
comm.register(login, password, function() {
|
||||
location.href="/gemp-lotr/hall.html";
|
||||
},
|
||||
{
|
||||
"0": function() {
|
||||
alert("Unable to connect to server, either server is down or there is a problem" +
|
||||
" with your internet connection");
|
||||
},
|
||||
"400":function() {
|
||||
$(".error").html("Login is invalid. Login must be between 2-10 characters long, and contain only<br/>"+
|
||||
+" english letters, numbers or _ (underscore) and - (dash) characters.");
|
||||
},
|
||||
"409": function() {
|
||||
$(".error").html("User with this login already exists in the system. Try a different one.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var clickToRegisterButton = $("#clickToRegister");
|
||||
if (clickToRegisterButton != null) {
|
||||
clickToRegisterButton.button().click(
|
||||
function () {
|
||||
$("#message").html("");
|
||||
comm.getRegistrationForm(processResponse);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function registrationScreen() {
|
||||
comm.getRegistrationForm(
|
||||
function(html) {
|
||||
$(".error").html();
|
||||
$(".interaction").html(html);
|
||||
$("#registerButton").click(
|
||||
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
function login() {
|
||||
var login = $("#login").val();
|
||||
var password = $("#password").val();
|
||||
comm.login(login, password, function() {
|
||||
location.href = "/gemp-lotr/hall.html";
|
||||
},
|
||||
{
|
||||
"0": function() {
|
||||
alert("Unable to connect to server, either server is down or there is a problem" +
|
||||
" with your internet connection");
|
||||
},
|
||||
"401":function() {
|
||||
$(".error").html("Invalid username or password. Try again.");
|
||||
loginScreen();
|
||||
},
|
||||
"403": function() {
|
||||
$(".error").html("You have been banned. If you think it was a mistake, please write an e-mail to <a href='mailto:marcins78@gmail.com>marcins78@gmail.com</a>");
|
||||
$(".interaction").html("");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function loginScreen() {
|
||||
$(".error").html("");
|
||||
$(".interaction").html("");
|
||||
$(".interaction").append("Login below, or ");
|
||||
var registerButton = $("<div>Register</div>").button();
|
||||
registerButton.click(registrationScreen);
|
||||
|
||||
$(".interaction").append(registerButton);
|
||||
$(".interaction").append("<br/>Login: <input id='login' type='text'><br/>Password: <input id='password' type='password'><br/>");
|
||||
|
||||
var loginButton = $("<div>Login</div>").button();
|
||||
loginButton.click(login);
|
||||
|
||||
$("#password").keypress(function (e) {
|
||||
if (e.which == 13) {
|
||||
login();
|
||||
e.preventDefault();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
$(".interaction").append(loginButton);
|
||||
}
|
||||
|
||||
$(document).ready(
|
||||
function () {
|
||||
comm.getStatus(
|
||||
function(html) {
|
||||
$(".status").append(html);
|
||||
});
|
||||
$(".centerContainer").center();
|
||||
loginScreen();
|
||||
});
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body bgcolor="#000000">
|
||||
<div style="float: left;height: 98%"><img src="images/troll.png" height="98%"/></div>
|
||||
<div style="float: right;height: 98%"><img src="images/man.png" height="98%"/></div>
|
||||
<div id="message" style="color:#ffffff;"></div>
|
||||
<div class="centerContainer">
|
||||
<div class="status" style="color:#ffffff;"></div>
|
||||
<div class="error" style="color: #ff0000;"></div>
|
||||
<div class="interaction" style="color: #ffffff;"></div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -615,6 +615,7 @@ var GempLotrCommunication = Class.extend({
|
||||
type:"POST",
|
||||
url:this.url + "/login",
|
||||
cache:false,
|
||||
async:false,
|
||||
data:{
|
||||
login:login,
|
||||
password:password,
|
||||
@@ -643,6 +644,7 @@ var GempLotrCommunication = Class.extend({
|
||||
type:"POST",
|
||||
url:"/gemp-lotr/includes/registrationForm.html",
|
||||
cache:false,
|
||||
async:false,
|
||||
data:{
|
||||
participantId:getUrlParam("participantId")},
|
||||
success:this.deliveryCheck(callback),
|
||||
|
||||
Reference in New Issue
Block a user