Deal with the corner case of already created accounts

Polished everything a bit
This commit is contained in:
Leonel Câmara
2015-09-15 17:24:57 +01:00
parent 125cbd93a0
commit 36db9719ef
3 changed files with 30 additions and 9 deletions
@@ -17,18 +17,32 @@ def deploy():
return {} return {}
def crossdomainproxy(): def create_account():
""" Create a PythonAnywhere account """
if not request.vars: if not request.vars:
raise HTTP(400) raise HTTP(400)
if request.vars.username and request.vars.web2py_admin_password:
# Check if web2py is already there otherwise we get an error 500 too.
client = ServerProxy('https://%(username)s:%(web2py_admin_password)s@%(username)s.pythonanywhere.com/admin/webservices/call/jsonrpc' % request.vars)
try:
if client.login() is True:
return response.json({'status': 'ok'})
except ProtocolError as error:
pass
import urllib, urllib2 import urllib, urllib2
url = 'https://www.pythonanywhere.com/api/web2py/create_account' url = 'https://www.pythonanywhere.com/api/web2py/create_account'
data = urllib.urlencode(request.vars) data = urllib.urlencode(request.vars)
req = urllib2.Request(url, data) req = urllib2.Request(url, data)
try: try:
reply = urllib2.urlopen(req) reply = urllib2.urlopen(req)
except urllib2.HTTPError as error: except urllib2.HTTPError as error:
if error.code == 400: if error.code == 400:
reply = error reply = error
elif error.code == 500:
return response.json({'status':'error', 'errors':{'username': ['An App other than web2py is installed in the domain %(username)s.pythonanywhere.com' % request.vars]}})
else: else:
raise raise
response.headers['Content-Type'] = 'application/json' response.headers['Content-Type'] = 'application/json'
+6 -2
View File
@@ -183,6 +183,7 @@
'Hide/Show Translated strings': '', 'Hide/Show Translated strings': '',
'htmledit': 'htmledit', 'htmledit': 'htmledit',
'If the report above contains a ticket number it indicates a failure in executing the controller, before any attempt to execute the doctests. This is usually due to an indentation error or an error outside function code.\nA green title indicates that all tests (if defined) passed. In this case test results are not shown.': 'Se o relatório acima contém um número de ticket, isso indica uma falha no controlador em execução, antes de tantar executar os doctests. Isto acontece geralmente por erro de endentação ou erro fora do código da função.\r\nO titulo em verde indica que os testes (se definidos) passaram. Neste caso os testes não são mostrados.', 'If the report above contains a ticket number it indicates a failure in executing the controller, before any attempt to execute the doctests. This is usually due to an indentation error or an error outside function code.\nA green title indicates that all tests (if defined) passed. In this case test results are not shown.': 'Se o relatório acima contém um número de ticket, isso indica uma falha no controlador em execução, antes de tantar executar os doctests. Isto acontece geralmente por erro de endentação ou erro fora do código da função.\r\nO titulo em verde indica que os testes (se definidos) passaram. Neste caso os testes não são mostrados.',
'if your application uses a database other than sqlite you will then have to configure its DAL in pythonanywhere.': 'if your application uses a database other than sqlite you will then have to configure its DAL in pythonanywhere.',
'Import/Export': 'Importar/Exportar', 'Import/Export': 'Importar/Exportar',
'includes': 'inclui', 'includes': 'inclui',
'insert new': 'inserir novo', 'insert new': 'inserir novo',
@@ -219,11 +220,11 @@
'Login/Register': 'Login/Register', 'Login/Register': 'Login/Register',
'Logout': 'finalizar sessão', 'Logout': 'finalizar sessão',
'Lost Password': 'Senha perdida', 'Lost Password': 'Senha perdida',
'Manage': 'Manage',
'manage': 'gerenciar', 'manage': 'gerenciar',
'Manage': 'Manage',
'merge': 'juntar', 'merge': 'juntar',
'Models': 'Modelos',
'models': 'modelos', 'models': 'modelos',
'Models': 'Modelos',
'Modules': 'Módulos', 'Modules': 'Módulos',
'modules': 'módulos', 'modules': 'módulos',
'Name': 'Nome', 'Name': 'Nome',
@@ -271,6 +272,7 @@
'PythonAnywhere Password': 'PythonAnywhere Password', 'PythonAnywhere Password': 'PythonAnywhere Password',
'Query:': 'Consulta:', 'Query:': 'Consulta:',
'Rapid Search': 'Rapid Search', 'Rapid Search': 'Rapid Search',
'Read': 'Read',
'record': 'registro', 'record': 'registro',
'record does not exist': 'o registro não existe', 'record does not exist': 'o registro não existe',
'record id': 'id do registro', 'record id': 'id do registro',
@@ -394,6 +396,7 @@
'view': 'visão', 'view': 'visão',
'Views': 'Visões', 'Views': 'Visões',
'views': 'visões', 'views': 'visões',
'Warning!': 'Warning!',
'Web Framework': 'Web Framework', 'Web Framework': 'Web Framework',
'web2py Admin Password': 'web2py Admin Password', 'web2py Admin Password': 'web2py Admin Password',
'web2py is up to date': 'web2py está atualizado', 'web2py is up to date': 'web2py está atualizado',
@@ -401,4 +404,5 @@
'web2py upgraded; please restart it': 'web2py atualizado; favor reiniciar', 'web2py upgraded; please restart it': 'web2py atualizado; favor reiniciar',
'Welcome to web2py': 'Bem-vindo ao web2py', 'Welcome to web2py': 'Bem-vindo ao web2py',
'YES': 'SIM', 'YES': 'SIM',
'You only need these if you have already registered': 'You only need these if you have already registered',
} }
@@ -9,7 +9,7 @@
<div class="control-group" id="username__row"> <div class="control-group" id="username__row">
<label class="control-label" for="username">{{=T('Username')}}</label> <label class="control-label" for="username">{{=T('Username')}}</label>
<div class="controls"> <div class="controls">
<input type="text" name="username" id="username"> <input type="text" name="username" id="username"><span class="help-inline">*</span>
<span class="help-block"></span> <span class="help-block"></span>
</div> </div>
</div> </div>
@@ -33,7 +33,7 @@
<div class="control-group" id="web2py_admin_password__row"> <div class="control-group" id="web2py_admin_password__row">
<label class="control-label" for="web2py_admin_password">{{=T('web2py Admin Password')}}</label> <label class="control-label" for="web2py_admin_password">{{=T('web2py Admin Password')}}</label>
<div class="controls"> <div class="controls">
<input type="password" name="web2py_admin_password" id="web2py_admin_password"> <input type="password" name="web2py_admin_password" id="web2py_admin_password"><span class="help-inline">*</span>
<span class="help-block"></span> <span class="help-block"></span>
</div> </div>
</div> </div>
@@ -41,7 +41,7 @@
<div class="control-group" id="accepts_terms__row"> <div class="control-group" id="accepts_terms__row">
<div class="controls"> <div class="controls">
<label class="checkbox"> <label class="checkbox">
<input type="checkbox" name="accepts_terms" id="accepts_terms"> {{=T('Accept Terms')}} <input type="checkbox" name="accepts_terms" id="accepts_terms"><a target="_blank" href="https://www.pythonanywhere.com/terms/">{{=T('Accept Terms')}}</a>
</label> </label>
<span class="help-block"></span> <span class="help-block"></span>
</div> </div>
@@ -54,6 +54,7 @@
</div> </div>
</form> </form>
<p>* {{=T('You only need these if you have already registered')}}</p>
</div> </div>
<div class="row-fluid" id="app_manager" style="display:none;"> <div class="row-fluid" id="app_manager" style="display:none;">
@@ -65,6 +66,10 @@
</select> </select>
<input type="submit" value="Deploy" id="deploy_button" class="btn btn-primary"> <input type="submit" value="Deploy" id="deploy_button" class="btn btn-primary">
</form> </form>
<div class="alert alert-info">
<strong>{{=T('Warning!')}}</strong> {{=T('if your application uses a database other than sqlite you will then have to configure its DAL in pythonanywhere.')}}
</div>
</div> </div>
<div class="span6"> <div class="span6">
<h3>{{=T('PythonAnywhere Apps')}}</h3> <h3>{{=T('PythonAnywhere Apps')}}</h3>
@@ -84,12 +89,11 @@ $(document).ready(function() {
$.web2py.disableElement($('#submit_palogin')); $.web2py.disableElement($('#submit_palogin'));
$.web2py.disableFormElements($('#palogin')); $.web2py.disableFormElements($('#palogin'));
$.ajax({ $.ajax({
url: '{{=URL("pythonanywhere", "crossdomainproxy")}}', url: '{{=URL("pythonanywhere", "create_account")}}',
type: 'POST', type: 'POST',
data: data, data: data,
dataType: 'json', dataType: 'json',
}).done(function(data, textStatus, jqXHR) { }).done(function(data, textStatus, jqXHR) {
console.log(data);
$('#palogin .error').removeClass('error'); $('#palogin .error').removeClass('error');
$('#palogin .help-block').text(''); $('#palogin .help-block').text('');
if(data.status == 'error') { if(data.status == 'error') {
@@ -124,7 +128,6 @@ $(document).ready(function() {
data: {username: $('#username').val(), password: $('#web2py_admin_password').val(), apps: $('#local').val()}, data: {username: $('#username').val(), password: $('#web2py_admin_password').val(), apps: $('#local').val()},
dataType: 'json', dataType: 'json',
}).done(function(data, textStatus, jqXHR) { }).done(function(data, textStatus, jqXHR) {
console.log(data);
refresh_apps(); refresh_apps();
$.web2py.enableElement($('#deploy_button')); $.web2py.enableElement($('#deploy_button'));
}).fail(function(){ }).fail(function(){