1
0
フォーク 0
ミラー元 https://github.com/yweber/lodel2.git 同期済み 2025-12-17 07:16:55 +01:00

Authentification form in Webui interface

このコミットが含まれているのは:
prieto 2016-09-01 12:12:59 +02:00
コミット 33e65b1518
18個のファイルの変更66行の追加41行の削除

ファイルの表示

@ -400,7 +400,7 @@ user.new_field(
user.new_field(
'login', display_name = 'user login', help_text = 'login',
group = user_group, data_handler = 'varchar', uniq = True, internal = True)
group = user_group, data_handler = 'varchar', uniq = True, internal = False)
user.new_field(
'password', display_name = 'Password',

バイナリファイルは表示されません。

ファイルの表示

@ -1,8 +1,6 @@
[lodel2]
debug = False
sitename = noname
plugins_path = plugins
plugins = dummy, webui
[lodel2.logging.stderr]
level = ERROR

ファイルの表示

@ -3,12 +3,14 @@
import copy
import sys
import warnings
import inspect
from lodel.settings import Settings
from lodel import logger
from lodel.plugin.hooks import LodelHook
from lodel.plugin import SessionHandlerPlugin as SessionHandler
from .exceptions import *
from ..leapi.query import LeGetQuery
##@brief Class designed to handle sessions and its datas
class LodelSession(object):
@ -201,18 +203,19 @@ class Client(object, metaclass = ClientMetaclass):
def authenticate(self, login = None, password = None):
#Authenticate
for infos in self._infos_fields:
logger.debug(self._infos_fields)
login_cls = infos['login'][0]
pass_cls = infos['pass'][0]
pass_cls = infos['password'][0]
qfilter = "{passfname} = {passhash}"
uid_fname = login_cls.uid_fieldname()[0] #COMPOSED UID BROKEN
if login_cls == pass_cls:
#Same EmClass for login & pass
qfilter = qfilter.format(
passfname = infos['pass'][1],
passfname = infos['password'][1],
passhash = password)
else:
#Different EmClass, building a relational filter
passfname = "%s.%s" % (infos['login'][2], infos['pass'][1])
passfname = "%s.%s" % (infos['login'][2], infos['password'][1])
qfilter = qfilter.format(
passfname = passfname,
passhash = password)
@ -220,11 +223,10 @@ class Client(object, metaclass = ClientMetaclass):
field_list = [uid_fname], limit = 1)
req = getq.execute()
if len(req) == 1:
#Authenticated
self.__set_authenticated(infos['login'][0], req[uid_fname])
self.__set_authenticated(infos['login'][0],req[0][uid_fname])
break
if self.is_anon():
self.fail() #Security logging
if self.is_anonymous():
self.authentication_failure() #Security logging
##@brief Attempt to restore a session given a session token
#@param token mixed : a session token
@ -267,8 +269,8 @@ class Client(object, metaclass = ClientMetaclass):
#@return True if client is anonymous
@classmethod
def is_anonymous(cls):
cls._assert_instance()
return Client._instance
return cls._assert_instance()
#return Client._instance
##@brief Method to call on authentication failure
#@throw ClientAuthenticationFailure
@ -348,9 +350,10 @@ login EmClass '%s' and password EmClass '%s'. Abording..." % (
#@param leo LeObject child class : the LeObject the user is stored in
#@param uid str : uniq id (in leo)
#@return None
@classmethod
def __set_authenticated(self, leo, uid):
self.__user = {'classname': leo.__name__, 'uid': uid, 'leoclass': leo}
#Store auth infos in session
self.__session[self.__class__._AUTH_DATANAME] = copy.copy(self.__user)
self._instance.__session[self._instance.__class__._AUTH_DATANAME] = copy.copy(self.__user)

ファイルの表示

@ -114,4 +114,5 @@ class Concat(FormatString):
class Password(Varchar):
help = 'Handle passwords'
base_type = 'password'
pass

ファイルの表示

@ -498,7 +498,7 @@ construction and consitency when datas are not complete\n")
@classmethod
def make_consistency(cls, datas, type_query = 'insert'):
for fname, dh in cls._fields.items():
ret = dh.make_consistency(cls, fname, datas, type_query)
ret = dh.make_consistency(fname, datas, type_query)
## @brief Add a new instance of LeObject
# @return a new uid en case of success, False otherwise

ファイルの表示

@ -59,12 +59,13 @@ def admin_update(request):
logger.warning('Composed uids broken here')
uid_field = target_leo.uid_fieldname()[0]
test_valid = uid_field in request.GET \
and len(request.GET[uid_field]) == 1
test_valid = 'lodel_id' in request.GET \
and len(request.GET['lodel_id']) == 1
if test_valid:
try:
lodel_id = request.GET[uid_field][0]
dh = target_leo.field(uid_field)
lodel_id = dh.cast_type(request.GET['lodel_id'][0])
except (ValueError, TypeError):
test_valid = False
@ -73,11 +74,10 @@ def admin_update(request):
else:
query_filters = list()
query_filters.append((uid_field,'=',lodel_id))
obj = dyncode.Object.get(query_filters)
obj = target_leo.get(query_filters)
if len(obj) == 0:
raise HttpException(404)
return get_response('admin/admin_edit.html', target=target_leo, uidfield = uid_field, lodel_id =lodel_id)
return get_response('admin/admin_edit.html', target=target_leo, lodel_id =lodel_id)
def admin_create(request):
classname = None

ファイルの表示

@ -40,13 +40,14 @@ def show_object(request):
logger.warning('Composed uids broken here')
uid_field = target_leo.uid_fieldname()[0]
test_valid = uid_field in request.GET \
and len(request.GET[uid_field]) == 1
test_valid = 'lodel_id' in request.GET \
and len(request.GET['lodel_id']) == 1
if test_valid:
try:
lodel_id = int(request.GET[uid_field][0])
dh = target_leo.field(uid_field)
lodel_id = dh.cast_type(request.GET['lodel_id'][0])
except (ValueError, TypeError):
test_valid = False
@ -55,8 +56,8 @@ def show_object(request):
else:
query_filters = list()
query_filters.append((uid_field,'=',lodel_id))
obj = dyncode.Object.get(query_filters)
obj = target_leo.get(query_filters)
if len(obj) == 0:
raise HttpException(404)
return get_response('listing/show_object.html', lodel_id=lodel_id, uidfield = uid_field, classname=classname)
return get_response('listing/show_object.html', lodel_id=lodel_id, classname=classname)

ファイルの表示

@ -1,13 +1,15 @@
# -*- coding: utf-8 -*-
from .base import get_response
from ...exceptions import *
from ...client import WebUiClient as WebUiClient
from lodel import logger
import leapi_dyncode as dyncode
def signin(request):
msg=''
if request.method == 'POST':
print('Welcome')
WebUiClient.authenticate(request.form['inputLogin'], request.form['inputPassword'])
return get_response('users/welcome.html')
else:
return get_response('users/signin.html')

ファイルの表示

@ -116,8 +116,10 @@ def application(env, start_response):
session_token = None
#next line is for testing purpose
WebUiClient['last_request'] = time.time()
try:
controller = get_controller(request)
logger.debug(controller)
response = controller(request)
except HttpException as e:
try:

ファイルの表示

@ -20,8 +20,8 @@
</div>
{% endfor %}
<p>&nbsp;</p>
<button type="submit" class="btn btn-default">Save</button>
<a class="btn btn-primary" href="object_create">Return</a>
<button type="submit" class="btn btn-primary">Save</button>
<a class="btn btn-default" href="object_create">Return</a>
</form>
<div>
</div>

ファイルの表示

@ -1,6 +1,6 @@
{% extends "base_backend.html" %}
{% import "admin/editable_component.html" as edit %}
{% set objects = target.get(('lodel_id = %s') % (lodel_id)) %}
{% set uidfield = target.uid_fieldname()[0] %}
{% set objects = target.get(('%s = %s') % (uidfield, lodel_id)) %}
{% set obj = objects.pop() %}
{% block title %}Edit Object{% endblock %}

ファイルの表示

@ -2,9 +2,10 @@
<label for="field_input_{{fieldname}}" class="col-sm-2 control-label">{{fieldname}}</label>
<div class="col-xs-6">
{% if field.base_type == 'bool' %}
<input id="field_input_{{fieldname}}" class="form-control" name="field_input_{{fieldname}}" type="checkbox" checked="{% if value %}checked{% endif %}" >
{% elif field.base_type == 'char' or field.base_type == 'int' %}
{% elif field.base_type == 'password' %}
<input id="{{fieldname}}" name="field_input_{{fieldname}}" class="form-control" type="password" value="{{sval}}" >
{% elif field.base_type == 'char' or field.base_type == 'int' %}
<input id="{{fieldname}}" class="form-control" name="field_input_{{fieldname}}" type="text" value="{{value}}" >
{% elif field.base_type == 'ref' %}
{% if value is iterable %}

ファイルの表示

@ -32,8 +32,8 @@
<li><a href="list_classes">All types</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li id="backend-nav"><a href="admin" class="btn btn-link disabled">Back-end</a></li>
<li id="backend-nav"><a href="admin" class="btn btn-link">Back-end</a></li>
<li id="backend-nav"><a href="/lodel_i/admin" class="btn btn-link disabled">Back-end</a></li>
<li id="backend-nav"><a href="/lodel_i/admin" class="btn btn-link">Back-end</a></li>
<li id="signin-nav"><a href="signin">Sign In</a></li>
<li id="signout-nav" style="display: none;"><a href="signout">Logout</a>
</ul>

ファイルの表示

@ -31,7 +31,7 @@
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="/lodel_i/">Front-End</a></li>
<li id="signin-nav"><a href="signin">Sign In</a></li>
<li id="signin-nav"><a href="/lodel_i/signin">Sign In</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>

ファイルの表示

@ -1,6 +1,7 @@
{% extends "base.html" %}
{% import 'components/components.html' as components %}
{% set my_class = leapi.name2class(classname) %}
{% set uidfield = my_class.uid_fieldname()[0] %}
{% set objects = my_class.get(('%s = %s') % (uidfield, lodel_id)) %}
{% set obj = objects.pop() %}
{% if my_class.is_abstract() %}
@ -28,7 +29,6 @@
{% set l_classe = fieldvalue.allowed_classes[0] %}
<ul>
{% for rel in obj.data(fieldname) %}
<!-- Uid for linked_classes is casted to int....not good...but for a while.... -->
{% set casttype = l_classe.data_handler(l_classe.uid_fieldname()[0]).cast_type %}
{% set rel2 = casttype(rel) %}
<li><a href="show_object?classname={{ l_classe.__name__ }}&lodel_id={{ rel2 }}" target="_blank">{{ rel2 }}</a></li>

ファイルの表示

@ -7,17 +7,17 @@
{% block content %}
<div class="container">
<h1>Lodel2 - Sign In</h1>
<form class="form-horizontal">
<form class="form-horizontal" method="POST" action="">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Email</label>
<label for="inputLogin" class="col-sm-2 control-label">Login</label>
<div class="col-xs-4">
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">
<input type="text" class="form-control" id="inputLogin" name="inputLogin" placeholder="Login">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Password</label>
<label for="inputPassword" class="col-sm-2 control-label">Password</label>
<div class="col-xs-4">
<input type="password" class="form-control" id="inputPassword3" placeholder="Password">
<input type="password" class="form-control" id="inputPassword" name="inputPassword" placeholder="Password">
</div>
</div>
<div class="form-group">

17
plugins/webui/templates/users/welcome.html ノーマルファイル
ファイルの表示

@ -0,0 +1,17 @@
{% extends "base.html" %}
{% block title %}Lodel 2 - Welcom{% endblock %}
<!-- Custom styles for this template -->
{% block style %}
<link href="http://127.0.0.1/css/signin.css" rel="stylesheet">
{% endblock %}
{% block content %}
<div class="container">
<h1>Lodel2 - Welcome</h1>
<div class="row">
<div class="col-md-6"></div>
<div class="col-md-6">You are successfully login...</div>
</div>
</div> <!-- /container -->
{% endblock %}