SwellRT / swellrt

SwellRT main project. Server, JavaScript and Java clients
http://swellrt.org/
Apache License 2.0
234 stars 34 forks source link

Return register error as JSON #103

Closed atd closed 8 years ago

atd commented 8 years ago

Currently the registration error body is HTML

<html dir="ltr"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="/static/auth.css">
<title>Register a New Account - Wave in a Box</title>
<link rel="shortcut icon" href="/static/favicon.ico">
</head>
<body onload="init()"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" style="margin-top: 15px"><tr><td valign="top" style="padding-left: 20px; padding-right: 10px"><img src="/static/logo.png" border="0" width="45px" height="30" align="left" vspace="10" alt="Wave in a Box logo"></td>
<td width="95%"><table width="100%" align="right" cellspacing="0" bgcolor="#C3D9FF" dir="ltr"><tr><td class="bubble" style="font-family: arial; text-align: left; font-weight: bold; padding-right: 10px;" dir="ltr"><span><b>Wave in a Box - Register a New Account</b> @local.net</span></td></tr></table></td></tr></table>
<table border="0" width="100%" cellpadding="1" cellspacing="1" style="margin-top: 10px; padding-left: 20px;"><tr><td align="left" style="height: 20px; padding-right: 10;"><label id="messageLbl" style="display: none;"></label><span id="loginLink" style="display: none;">&nbsp;Please <a href="/auth/signin">sign in</a>.</span></td></tr>
<tr><td id="wiab_loginbox_td" valign="top" align="center">
<form id="regForm" name="regForm" method="post" action=""><table align="left"><tr><td><table class="form-noindent" align="center" cellspacing="5" cellpadding="5" width="100%" border="0"><tbody><tr><td>Username:</td>
<td><input id="address" name="address" class="wiab le val" tabindex="1" value="" type="text" style="padding-bottom: 0px;"></td></tr>
<tr><td style="padding: 0px; margin: 0px"></td>
<td align="right" style="color: #444444; font-size: 75%; overflow: hidden; padding-top: 0px; margin-top: 0px; vertical-align: top;" dir="ltr">@local.net</td></tr>
<tr><td><label for="password">Password:</label></td>
<td><input id="password" name="password" tabindex="2" autocomplete="OFF" type="password" class="wiab le val"></td></tr>
<tr><td><label for="verifypass">Re-enter
Password:</label></td>
<td><input id="verifypass" name="verifypass" tabindex="3" autocomplete="OFF" type="password" class="wiab le val"></td></tr></tbody></table>
<table><tbody><tr><td align="center"><input class="wiab le button" value="Cancel" id="buttonStyle" onclick="history.go(-1)" tabindex="4" type="button"></td>
<td align="center"><input class="wiab le button" value="Register" id="buttonStyle" tabindex="5" type="button" onclick="validate()"></td></tr></tbody></table></td></tr></table></form></td></tr></table>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" style="margin-top: 10px"><tr><td width="95%"><table width="100%" align="right" cellspacing="0" dir="ltr"><tr><td class="bubble" style="font-family: arial; text-align: left; font-weight: bold; padding-right: 10px;" dir="ltr"></td></tr></table></td></tr></table>
<script type="text/javascript">
    var RESPONSE_STATUS_NONE = "NONE";
    var RESPONSE_STATUS_FAILED = "FAILED";
    var RESPONSE_STATUS_SUCCESS = "SUCCESS";

    var message = "Account already exists";
    var responseType =  "FAILED";
    var domain = "local.net";
       ....

It would be nicer if those errors were returned in JSON, so developers do not need to parse the HTML

atfornes commented 8 years ago

@atd, @pablojan, integrated in Teem by https://github.com/P2Pvalue/teem/commit/7d1ec7593ec9c69aafa8d6abc5b0cd7e1402677e

atfornes commented 8 years ago

@pablojan, when repeating an username using the old SwellRT.register method I got "INVALID_USERNAME_EXCEPTION" instead of the expected "ACCOUNT_ALREADY_EXISTS"

atfornes commented 8 years ago

@pablojan, when using the new SwellRT.createUser I got a CORS problem: Solicitud desde otro origen bloqueada: la política de mismo origen impide leer el recurso remoto en http://swellrt:9898/swell/account (razón: falta la cabecera CORS 'Access-Control-Allow-Origin').

pablojan commented 8 years ago

SwellRT.registerUser is deprectated. You shouldn't use it to check if an account already exists. About the CORS problem, it was a mistake during the commit. Fixing it now.