浏览代码

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
                 'email.notification.from.default_label.'
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
         self.EMAIL_NOTIFICATION_FROM_EMAIL = \
223
         self.EMAIL_NOTIFICATION_FROM_EMAIL = \
221
             tg.config.get('email.notification.from.email')
224
             tg.config.get('email.notification.from.email')
222
         self.EMAIL_NOTIFICATION_FROM_DEFAULT_LABEL = \
225
         self.EMAIL_NOTIFICATION_FROM_DEFAULT_LABEL = \

+ 27 - 1
tracim/tracim/controllers/admin/user.py 查看文件

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
 import uuid
2
 import uuid
3
+import random
3
 
4
 
4
 import pytz
5
 import pytz
5
 from tracim import model  as pm
6
 from tracim import model  as pm
7
 from sprox.tablebase import TableBase
8
 from sprox.tablebase import TableBase
8
 from sprox.formbase import EditableForm, AddRecordForm
9
 from sprox.formbase import EditableForm, AddRecordForm
9
 from sprox.fillerbase import TableFiller, EditFormFiller
10
 from sprox.fillerbase import TableFiller, EditFormFiller
11
+from tracim.config.app_cfg import CFG
10
 from tw2 import forms as tw2f
12
 from tw2 import forms as tw2f
11
 import tg
13
 import tg
12
 from tg import predicates
14
 from tg import predicates
326
             user.password = password
328
             user.password = password
327
         elif send_email:
329
         elif send_email:
328
             # Setup a random password to send email at user
330
             # Setup a random password to send email at user
329
-            password = str(uuid.uuid4())
331
+            password = UserRestController.generate_password()
330
             user.password = password
332
             user.password = password
331
 
333
 
332
         user.webdav_left_digest_response_hash = '%s:/:%s' % (email, password)
334
         user.webdav_left_digest_response_hash = '%s:/:%s' % (email, password)
351
         tg.flash(_('User {} created.').format(user.get_display_name()), CST.STATUS_OK)
353
         tg.flash(_('User {} created.').format(user.get_display_name()), CST.STATUS_OK)
352
         tg.redirect(self.url())
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
     @tg.expose('tracim.templates.admin.user_getone')
380
     @tg.expose('tracim.templates.admin.user_getone')
355
     def get_one(self, user_id):
381
     def get_one(self, user_id):
356
         current_user = tmpl_context.current_user
382
         current_user = tmpl_context.current_user