Browse Source

Authentification form in Webui interface

prieto 7 years ago
parent
commit
33e65b1518

+ 1
- 1
em_test.py View File

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

BIN
examples/em_test.pickle View File


+ 0
- 2
globconf.d/lodel2.ini View File

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

+ 13
- 10
lodel/auth/client.py View File

@@ -3,12 +3,14 @@
3 3
 import copy
4 4
 import sys
5 5
 import warnings
6
+import inspect
6 7
 
7 8
 from lodel.settings import Settings
8 9
 from lodel import logger
9 10
 from lodel.plugin.hooks import LodelHook
10 11
 from lodel.plugin import SessionHandlerPlugin as SessionHandler
11 12
 from .exceptions import *
13
+from ..leapi.query import LeGetQuery
12 14
 
13 15
 ##@brief Class designed to handle sessions and its datas
14 16
 class LodelSession(object):
@@ -201,18 +203,19 @@ class Client(object, metaclass = ClientMetaclass):
201 203
     def authenticate(self, login = None, password = None):
202 204
         #Authenticate
203 205
         for infos in self._infos_fields:
206
+            logger.debug(self._infos_fields)
204 207
             login_cls = infos['login'][0]
205
-            pass_cls = infos['pass'][0]
208
+            pass_cls = infos['password'][0]
206 209
             qfilter = "{passfname} = {passhash}"
207 210
             uid_fname = login_cls.uid_fieldname()[0] #COMPOSED UID BROKEN
208 211
             if login_cls == pass_cls:
209 212
                 #Same EmClass for login & pass
210 213
                 qfilter = qfilter.format(
211
-                    passfname = infos['pass'][1],
214
+                    passfname = infos['password'][1],
212 215
                     passhash = password)
213 216
             else:
214 217
                 #Different EmClass, building a relational filter
215
-                passfname = "%s.%s" % (infos['login'][2], infos['pass'][1])
218
+                passfname = "%s.%s" % (infos['login'][2], infos['password'][1])
216 219
                 qfilter = qfilter.format(
217 220
                     passfname = passfname,
218 221
                     passhash = password)
@@ -220,11 +223,10 @@ class Client(object, metaclass = ClientMetaclass):
220 223
                 field_list = [uid_fname], limit = 1)
221 224
             req = getq.execute()
222 225
             if len(req) == 1:
223
-                #Authenticated
224
-                self.__set_authenticated(infos['login'][0], req[uid_fname])
226
+                self.__set_authenticated(infos['login'][0],req[0][uid_fname])
225 227
                 break
226
-        if self.is_anon():
227
-            self.fail() #Security logging
228
+        if self.is_anonymous():
229
+            self.authentication_failure() #Security logging
228 230
     
229 231
     ##@brief Attempt to restore a session given a session token
230 232
     #@param token mixed : a session token
@@ -267,8 +269,8 @@ class Client(object, metaclass = ClientMetaclass):
267 269
     #@return True if client is anonymous
268 270
     @classmethod
269 271
     def is_anonymous(cls):
270
-        cls._assert_instance()
271
-        return Client._instance
272
+        return cls._assert_instance()
273
+        #return Client._instance
272 274
 
273 275
     ##@brief Method to call on authentication failure
274 276
     #@throw ClientAuthenticationFailure
@@ -348,9 +350,10 @@ login EmClass '%s' and password EmClass '%s'. Abording..." % (
348 350
     #@param leo LeObject child class : the LeObject the user is stored in
349 351
     #@param uid str : uniq id (in leo)
350 352
     #@return None
353
+    @classmethod
351 354
     def __set_authenticated(self, leo, uid):
352 355
         self.__user = {'classname': leo.__name__, 'uid': uid, 'leoclass': leo}
353 356
         #Store auth infos in session
354
-        self.__session[self.__class__._AUTH_DATANAME] = copy.copy(self.__user)
357
+        self._instance.__session[self._instance.__class__._AUTH_DATANAME] = copy.copy(self.__user)
355 358
         
356 359
     

+ 1
- 0
lodel/leapi/datahandlers/datas.py View File

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

+ 1
- 1
lodel/leapi/leobject.py View File

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

+ 6
- 6
plugins/webui/interface/controllers/admin.py View File

@@ -59,12 +59,13 @@ def admin_update(request):
59 59
         logger.warning('Composed uids broken here')
60 60
         uid_field = target_leo.uid_fieldname()[0]
61 61
 
62
-    test_valid = uid_field in request.GET \
63
-        and len(request.GET[uid_field]) == 1
62
+    test_valid = 'lodel_id' in request.GET \
63
+        and len(request.GET['lodel_id']) == 1
64 64
 
65 65
     if test_valid:
66 66
         try:
67
-            lodel_id = request.GET[uid_field][0]
67
+            dh = target_leo.field(uid_field)
68
+            lodel_id = dh.cast_type(request.GET['lodel_id'][0])
68 69
         except (ValueError, TypeError):
69 70
             test_valid = False
70 71
 
@@ -73,11 +74,10 @@ def admin_update(request):
73 74
     else:
74 75
         query_filters = list()
75 76
         query_filters.append((uid_field,'=',lodel_id))
76
-        obj = dyncode.Object.get(query_filters)
77
+        obj = target_leo.get(query_filters)
77 78
         if len(obj) == 0:
78 79
             raise HttpException(404)
79
-
80
-    return get_response('admin/admin_edit.html', target=target_leo, uidfield = uid_field, lodel_id =lodel_id)
80
+    return get_response('admin/admin_edit.html', target=target_leo, lodel_id =lodel_id)
81 81
 
82 82
 def admin_create(request):
83 83
     classname = None

+ 7
- 6
plugins/webui/interface/controllers/listing.py View File

@@ -40,13 +40,14 @@ def show_object(request):
40 40
     
41 41
     logger.warning('Composed uids broken here')
42 42
     uid_field = target_leo.uid_fieldname()[0]
43
-    
44
-    test_valid = uid_field in request.GET \
45
-        and len(request.GET[uid_field]) == 1
43
+
44
+    test_valid = 'lodel_id' in request.GET \
45
+        and len(request.GET['lodel_id']) == 1
46 46
 
47 47
     if test_valid:
48 48
         try:
49
-            lodel_id = int(request.GET[uid_field][0])
49
+            dh = target_leo.field(uid_field)
50
+            lodel_id = dh.cast_type(request.GET['lodel_id'][0])
50 51
         except (ValueError, TypeError):
51 52
             test_valid = False
52 53
 
@@ -55,8 +56,8 @@ def show_object(request):
55 56
     else:
56 57
         query_filters = list()
57 58
         query_filters.append((uid_field,'=',lodel_id))
58
-        obj = dyncode.Object.get(query_filters)
59
+        obj = target_leo.get(query_filters)
59 60
         if len(obj) == 0:
60 61
             raise HttpException(404)
61 62
 
62
-    return get_response('listing/show_object.html', lodel_id=lodel_id, uidfield = uid_field, classname=classname)
63
+    return get_response('listing/show_object.html', lodel_id=lodel_id, classname=classname)

+ 3
- 1
plugins/webui/interface/controllers/users.py View File

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

+ 2
- 0
plugins/webui/run.py View File

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

+ 2
- 2
plugins/webui/templates/admin/admin_create.html View File

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

+ 1
- 1
plugins/webui/templates/admin/admin_edit.html View File

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

+ 3
- 2
plugins/webui/templates/admin/editable_component.html View File

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

+ 2
- 2
plugins/webui/templates/base.html View File

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

+ 1
- 1
plugins/webui/templates/base_backend.html View File

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

+ 1
- 1
plugins/webui/templates/listing/show_object.html View File

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

+ 5
- 5
plugins/webui/templates/users/signin.html View File

@@ -7,17 +7,17 @@
7 7
 {% block content %} 
8 8
 <div class="container">
9 9
     <h1>Lodel2 - Sign In</h1>
10
-<form class="form-horizontal">
10
+<form class="form-horizontal" method="POST" action="">
11 11
   <div class="form-group">
12
-    <label for="inputEmail3" class="col-sm-2 control-label">Email</label>
12
+    <label for="inputLogin" class="col-sm-2 control-label">Login</label>
13 13
     <div class="col-xs-4">
14
-      <input type="email" class="form-control" id="inputEmail3" placeholder="Email">
14
+      <input type="text" class="form-control" id="inputLogin" name="inputLogin" placeholder="Login">
15 15
     </div>
16 16
   </div>
17 17
   <div class="form-group">
18
-    <label for="inputPassword3" class="col-sm-2 control-label">Password</label>
18
+    <label for="inputPassword" class="col-sm-2 control-label">Password</label>
19 19
     <div class="col-xs-4">
20
-      <input type="password" class="form-control" id="inputPassword3" placeholder="Password">
20
+      <input type="password" class="form-control" id="inputPassword" name="inputPassword" placeholder="Password">
21 21
     </div>
22 22
   </div>
23 23
   <div class="form-group">

+ 17
- 0
plugins/webui/templates/users/welcome.html View File

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

Loading…
Cancel
Save