Fixes in autologin

This commit is contained in:
Antonio de la Rosa 2015-12-14 04:49:25 +01:00
parent f8e92f9285
commit e2eee21600
10 changed files with 210 additions and 165 deletions

View file

@ -21,7 +21,7 @@
url: "${make_url('admin/login')}",
method: "POST",
dataType: "json",
data: {'username': $('#username_form').val(), 'password': $('#password_form').val()}
data: {'username': $('#username_form').val(), 'password': $('#password_form').val(), 'remember_login': $('#remember_login').val()}
}).done(function(data) {
if(data.error==0)
@ -56,6 +56,7 @@
${lang('admin', 'login', 'Paramecio Login')}
</div>
${forms|n}
<div class="form">${lang('admin', 'remember_login', 'Remember login?')} <input type="checkbox" id="remember_login" name="remember_login" value="1"></div>
<div id="submit_block">
<input type="submit" value="${lang('common', 'login', 'Login')}" class="submit" id="login_submit"/>
<span id="loading">&nbsp;</span>

View file

@ -15,6 +15,7 @@ class UserModel(WebModel):
self.email_field='email'
self.username_field='username'
self.yes_repeat_password=True
self.check_user=True
def create_forms(self, arr_fields={}):
@ -56,6 +57,8 @@ class UserModel(WebModel):
return False
if self.check_user==True:
# Check if passwords matches
if self.password_field in dict_values:
@ -92,6 +95,8 @@ class UserModel(WebModel):
pass
get_id=int(get_id)
sql_id=''
original_conditions=self.conditions

View file

@ -632,7 +632,9 @@ class WebModel:
self.fields[k].error=False
if (self.fields[k].protected==None or self.fields[k].protected==False or external_agent==False) and k in self.valid_fields:
if (self.fields[k].protected==None or self.fields[k].protected==False or external_agent==False):
if k in self.valid_fields:
self.fields[k].update=updated_field[errors_set]
@ -660,6 +662,13 @@ class WebModel:
values.append(final_value)
update_values.append(f_update(k, final_value))
else:
self.num_errors+=1
self.fields_errors[k].append("Error: "+self.fields[k].label+" is not in valid fields")
self.fields[k].error=True
self.fields[k].txt_error="Error: "+self.fields[k].label+" is not in valid fields"
error=True
else:
self.num_errors+=1
@ -702,7 +711,7 @@ class WebModel:
for k, v in self.fields.items():
self.required_save[k]=self.fields[k].required
self.fields[k].required=0
self.fields[k].required=False
#Reload the require field in fields
@ -777,9 +786,9 @@ class PhangoField:
self.size=size
# Protected, if this value != None, cannot use it in insert or update.
# Protected, if this value != False, cannot use it in insert or update.
self.protected=None
self.protected=False
# $quote_open is used if you need a more flexible sql sentence,
# @warning USE THIS FUNCTION IF YOU KNOW WHAT YOU ARE DOING

View file

@ -2,19 +2,19 @@
from paramecio.citoplasma.i18n import I18n
I18n.l['admin']['users_admin']='User's Admin'
I18n.l['admin']['applications']='Applications'
I18n.l['admin']['administrator']='Administrator'
I18n.l['admin']['selected_privileges']='Selected privileges'
I18n.l['admin']['users_admin']='User\'s Admin'
I18n.l['admin']['login']='Paramecio Login'
I18n.l['admin']['sign_up']='Paramecio Sign up'
I18n.l['admin']['welcome_to_paramecio']='Welcome to Paramecio Admin!!!'
I18n.l['admin']['login']='Paramecio Login'
I18n.l['admin']['without_privileges']='Without privileges'
I18n.l['admin']['welcome_to_paramecio']='Welcome to Paramecio Admin!!!'
I18n.l['admin']['selected_privileges']='Selected privileges'

View file

@ -2,41 +2,41 @@
from paramecio.citoplasma.i18n import I18n
I18n.l['common']['edit']='Edit'
I18n.l['common']['search']='Search'
I18n.l['common']['error_username_or_password_exists']='Error: username or email exists in database'
I18n.l['common']['repeat_password']='Repeat Password'
I18n.l['common']['error_passwords_no_match']='Error: passwords doesn\'t match'
I18n.l['common']['add_new_item']='Add new item'
I18n.l['common']['home']='Home'
I18n.l['common']['login']='Login'
I18n.l['common']['no']='No'
I18n.l['common']['edit_new_item']='Edit item'
I18n.l['common']['password_no_match']='Passwords doesn\'t match'
I18n.l['common']['sign_up']='Sign up'
I18n.l['common']['yes']='Yes'
I18n.l['common']['error_login']='Error, wrong username or password'
I18n.l['common']['task_successful']='Task successful'
I18n.l['common']['delete']='Delete'
I18n.l['common']['error_login']='Error, wrong username or password'
I18n.l['common']['add_item']='Add new item'
I18n.l['common']['edit']='Edit'
I18n.l['common']['edit_new_item']='Edit item'
I18n.l['common']['error_username_or_password_exists']='Error: username or email exists in database'
I18n.l['common']['last']='Last'
I18n.l['common']['no']='No'
I18n.l['common']['add_new_item']='Add new item'
I18n.l['common']['yes']='Yes'
I18n.l['common']['options']='Options'
I18n.l['common']['password_no_match']='Passwords doesn't match'
I18n.l['common']['login']='Login'
I18n.l['common']['error_passwords_no_match']='Error: passwords doesn't match'
I18n.l['common']['sign_up']='Sign up'
I18n.l['common']['task_successful']='Task successful'
I18n.l['common']['repeat_password']='Repeat Password'
I18n.l['common']['home']='Home'

View file

@ -2,19 +2,19 @@
from paramecio.citoplasma.i18n import I18n
I18n.l['admin']['users_admin']='Usuarios de administración'
I18n.l['admin']['applications']='Applications'
I18n.l['admin']['administrator']='Administrador'
I18n.l['admin']['selected_privileges']='Selected privileges'
I18n.l['admin']['users_admin']='Usuarios de administración'
I18n.l['admin']['login']='Entrar en Paramecio'
I18n.l['admin']['sign_up']='Entrar en Paramecio'
I18n.l['admin']['welcome_to_paramecio']='Bienvenido a la administración de este site!!'
I18n.l['admin']['login']='Entrar en Paramecio'
I18n.l['admin']['without_privileges']='Without privileges'
I18n.l['admin']['welcome_to_paramecio']='Bienvenido a la administración de este site!!'
I18n.l['admin']['selected_privileges']='Selected privileges'

View file

@ -2,41 +2,41 @@
from paramecio.citoplasma.i18n import I18n
I18n.l['common']['edit']='Edit'
I18n.l['common']['search']='Search'
I18n.l['common']['error_username_or_password_exists']='Error: username or email exists in database'
I18n.l['common']['repeat_password']='Repeat Password'
I18n.l['common']['error_passwords_no_match']='Error: passwords doesn\'t match'
I18n.l['common']['add_new_item']='Add new item'
I18n.l['common']['home']='Home'
I18n.l['common']['login']='Login'
I18n.l['common']['no']='No'
I18n.l['common']['edit_new_item']='Edit item'
I18n.l['common']['password_no_match']='Passwords doesn\'t match'
I18n.l['common']['sign_up']='Sign up'
I18n.l['common']['yes']='Yes'
I18n.l['common']['error_login']='Error, wrong username or password'
I18n.l['common']['task_successful']='Task successful'
I18n.l['common']['delete']='Delete'
I18n.l['common']['error_login']='Error, wrong username or password'
I18n.l['common']['add_item']='Add new item'
I18n.l['common']['edit']='Edit'
I18n.l['common']['edit_new_item']='Edit item'
I18n.l['common']['error_username_or_password_exists']='Error: username or email exists in database'
I18n.l['common']['last']='Last'
I18n.l['common']['no']='No'
I18n.l['common']['add_new_item']='Add new item'
I18n.l['common']['yes']='Yes'
I18n.l['common']['options']='Options'
I18n.l['common']['password_no_match']='Passwords doesn't match'
I18n.l['common']['login']='Login'
I18n.l['common']['error_passwords_no_match']='Error: passwords doesn't match'
I18n.l['common']['sign_up']='Sign up'
I18n.l['common']['task_successful']='Task successful'
I18n.l['common']['repeat_password']='Repeat Password'
I18n.l['common']['home']='Home'

View file

@ -5,7 +5,7 @@ from paramecio.modules.admin.models.admin import UserAdmin
from paramecio.citoplasma.i18n import load_lang, I18n
from paramecio.citoplasma.urls import make_url, add_get_parameters
from paramecio.citoplasma.sessions import get_session
from bottle import get,post
from bottle import get,post,response
from settings import config
from settings import config_admin
from paramecio.citoplasma.lists import SimpleList
@ -16,6 +16,9 @@ from paramecio.cromosoma.coreforms import PasswordForm
from importlib import import_module, reload
from bottle import redirect
from collections import OrderedDict
from time import time
from hashlib import sha512
from os import urandom
#from citoplasma.login import LoginClass
# Check login
@ -118,8 +121,8 @@ def login():
GetPostFiles.obtain_post()
GetPostFiles.post.get('username', '')
GetPostFiles.post.get('password', '')
GetPostFiles.post['username']=GetPostFiles.post.get('username', '')
GetPostFiles.post['password']=GetPostFiles.post.get('password', '')
username=user_admin.fields['username'].check(GetPostFiles.post['username'])
@ -142,6 +145,31 @@ def login():
s['login']=1
s['privileges']=arr_user['privileges']
remember_login=GetPostFiles.post.get('remember_login', '0')
if remember_login=='1':
timestamp=time()+315360000
random_text=sha512(urandom(10)).hexdigest()
#Update user with autologin token
user_admin.check_user=False
user_admin.conditions=['WHERE username=%s', [username]]
user_admin.valid_fields=['token_login']
user_admin.reset_require()
if user_admin.update({'token_login': random_text}):
response.set_cookie('remember_login', random_text, expires=timestamp)
else:
print(user_admin.query_error)
return {'error': 0}
else:
return {'error': 1}

View file

@ -23,7 +23,7 @@ body {
}
input {
input[type="text"], input[type="password"] {
width:100%;
border: solid #bcbcbc 1px;

View file

@ -40,6 +40,8 @@ class UserAdmin(UserModel):
self.register(corefields.CharField('token_recovery'))
self.register(corefields.CharField('token_login'))
self.register(PrivilegesField('privileges'))
"""