Преглед изворни кода

issue #188 generate more common password at user creation

Alexis CLEMENT пре 8 година
родитељ
комит
36cb00592e
2 измењених фајлова са 30 додато и 1 уклоњено
  1. 3 0
      tracim/tracim/config/app_cfg.py
  2. 27 1
      tracim/tracim/controllers/admin/user.py

+ 3 - 0
tracim/tracim/config/app_cfg.py Прегледај датотеку

@@ -217,6 +217,9 @@ class CFG(object):
217 217
                 'email.notification.from.default_label.'
218 218
             )
219 219
 
220
+        self.AUTO_GENERATED_PASSWORD_LENGTH = tg.config.get(
221
+            'tracim.password.length')
222
+
220 223
         self.EMAIL_NOTIFICATION_FROM_EMAIL = \
221 224
             tg.config.get('email.notification.from.email')
222 225
         self.EMAIL_NOTIFICATION_FROM_DEFAULT_LABEL = \

+ 27 - 1
tracim/tracim/controllers/admin/user.py Прегледај датотеку

@@ -1,5 +1,6 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 import uuid
3
+import random
3 4
 
4 5
 import pytz
5 6
 from tracim import model  as pm
@@ -7,6 +8,7 @@ from tracim import model  as pm
7 8
 from sprox.tablebase import TableBase
8 9
 from sprox.formbase import EditableForm, AddRecordForm
9 10
 from sprox.fillerbase import TableFiller, EditFormFiller
11
+from tracim.config.app_cfg import CFG
10 12
 from tw2 import forms as tw2f
11 13
 import tg
12 14
 from tg import predicates
@@ -326,7 +328,7 @@ class UserRestController(TIMRestController):
326 328
             user.password = password
327 329
         elif send_email:
328 330
             # Setup a random password to send email at user
329
-            password = str(uuid.uuid4())
331
+            password = UserRestController.generate_password()
330 332
             user.password = password
331 333
 
332 334
         user.webdav_left_digest_response_hash = '%s:/:%s' % (email, password)
@@ -351,6 +353,30 @@ class UserRestController(TIMRestController):
351 353
         tg.flash(_('User {} created.').format(user.get_display_name()), CST.STATUS_OK)
352 354
         tg.redirect(self.url())
353 355
 
356
+    @staticmethod
357
+    def generate_password():
358
+        # Characters available to generate a password
359
+        characters = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
360
+
361
+                      'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
362
+                      'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
363
+                      'u', 'v', 'w', 'x', 'y', 'z',
364
+
365
+                      'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
366
+                      'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
367
+                      'U', 'V', 'W', 'X', 'Y', 'Z']
368
+
369
+        # character list that will be contained into the password
370
+        list_char = []
371
+
372
+        pass_length = int(CFG.get_instance().AUTO_GENERATED_PASSWORD_LENGTH)
373
+        for j in range(0, pass_length):
374
+            # This puts a random char from the list above inside
375
+            # the list of chars and then merges them into a String
376
+            list_char.append(random.choice(characters))
377
+            password = ''.join(list_char)
378
+        return password
379
+
354 380
     @tg.expose('tracim.templates.admin.user_getone')
355 381
     def get_one(self, user_id):
356 382
         current_user = tmpl_context.current_user