Skip to content

Commit

Permalink
Deal with the corner case of already created accounts
Browse files Browse the repository at this point in the history
Polished everything a bit
  • Loading branch information
leonelcamara committed Sep 15, 2015
1 parent 125cbd9 commit 36db971
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
16 changes: 15 additions & 1 deletion applications/admin/controllers/pythonanywhere.py
Expand Up @@ -17,18 +17,32 @@ def deploy():
return {}


def crossdomainproxy():
def create_account():
""" Create a PythonAnywhere account """
if not request.vars:
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
url = 'https://www.pythonanywhere.com/api/web2py/create_account'
data = urllib.urlencode(request.vars)
req = urllib2.Request(url, data)

try:
reply = urllib2.urlopen(req)
except urllib2.HTTPError as error:
if error.code == 400:
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:
raise
response.headers['Content-Type'] = 'application/json'
Expand Down
8 changes: 6 additions & 2 deletions applications/admin/languages/pt.py
Expand Up @@ -183,6 +183,7 @@
'Hide/Show Translated strings': '',
'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 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',
'includes': 'inclui',
'insert new': 'inserir novo',
Expand Down Expand Up @@ -219,11 +220,11 @@
'Login/Register': 'Login/Register',
'Logout': 'finalizar sessão',
'Lost Password': 'Senha perdida',
'Manage': 'Manage',
'manage': 'gerenciar',
'Manage': 'Manage',
'merge': 'juntar',
'Models': 'Modelos',
'models': 'modelos',
'Models': 'Modelos',
'Modules': 'Módulos',
'modules': 'módulos',
'Name': 'Nome',
Expand Down Expand Up @@ -271,6 +272,7 @@
'PythonAnywhere Password': 'PythonAnywhere Password',
'Query:': 'Consulta:',
'Rapid Search': 'Rapid Search',
'Read': 'Read',
'record': 'registro',
'record does not exist': 'o registro não existe',
'record id': 'id do registro',
Expand Down Expand Up @@ -394,11 +396,13 @@
'view': 'visão',
'Views': 'Visões',
'views': 'visões',
'Warning!': 'Warning!',
'Web Framework': 'Web Framework',
'web2py Admin Password': 'web2py Admin Password',
'web2py is up to date': 'web2py está atualizado',
'web2py Recent Tweets': 'Tweets Recentes de @web2py',
'web2py upgraded; please restart it': 'web2py atualizado; favor reiniciar',
'Welcome to web2py': 'Bem-vindo ao web2py',
'YES': 'SIM',
'You only need these if you have already registered': 'You only need these if you have already registered',
}
15 changes: 9 additions & 6 deletions applications/admin/views/pythonanywhere/deploy.html
Expand Up @@ -9,7 +9,7 @@ <h3>{{=T('Login/Register')}}</h3>
<div class="control-group" id="username__row">
<label class="control-label" for="username">{{=T('Username')}}</label>
<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>
</div>
</div>
Expand All @@ -33,15 +33,15 @@ <h3>{{=T('Login/Register')}}</h3>
<div class="control-group" id="web2py_admin_password__row">
<label class="control-label" for="web2py_admin_password">{{=T('web2py Admin Password')}}</label>
<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>
</div>
</div>

<div class="control-group" id="accepts_terms__row">
<div class="controls">
<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>
<span class="help-block"></span>
</div>
Expand All @@ -54,6 +54,7 @@ <h3>{{=T('Login/Register')}}</h3>
</div>

</form>
<p>* {{=T('You only need these if you have already registered')}}</p>
</div>

<div class="row-fluid" id="app_manager" style="display:none;">
Expand All @@ -65,6 +66,10 @@ <h3>{{=T('Local Apps')}}</h3>
</select>
<input type="submit" value="Deploy" id="deploy_button" class="btn btn-primary">
</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 class="span6">
<h3>{{=T('PythonAnywhere Apps')}}</h3>
Expand All @@ -84,12 +89,11 @@ <h3>{{=T('PythonAnywhere Apps')}}</h3>
$.web2py.disableElement($('#submit_palogin'));
$.web2py.disableFormElements($('#palogin'));
$.ajax({
url: '{{=URL("pythonanywhere", "crossdomainproxy")}}',
url: '{{=URL("pythonanywhere", "create_account")}}',
type: 'POST',
data: data,
dataType: 'json',
}).done(function(data, textStatus, jqXHR) {
console.log(data);
$('#palogin .error').removeClass('error');
$('#palogin .help-block').text('');
if(data.status == 'error') {
Expand Down Expand Up @@ -124,7 +128,6 @@ <h3>{{=T('PythonAnywhere Apps')}}</h3>
data: {username: $('#username').val(), password: $('#web2py_admin_password').val(), apps: $('#local').val()},
dataType: 'json',
}).done(function(data, textStatus, jqXHR) {
console.log(data);
refresh_apps();
$.web2py.enableElement($('#deploy_button'));
}).fail(function(){
Expand Down

0 comments on commit 36db971

Please sign in to comment.