소스 검색

Merge pull request #204 from herawo/master

Tracim 8 년 전
부모
커밋
a17843ec19
1개의 변경된 파일25개의 추가작업 그리고 1개의 파일을 삭제
  1. 25 1
      tracim/tracim/controllers/admin/user.py

+ 25 - 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
273
     profile = UserProfileAdminRestController()
275
     profile = UserProfileAdminRestController()
274
     workspaces = UserWorkspaceRestController()
276
     workspaces = UserWorkspaceRestController()
275
 
277
 
278
+    PASSWORD_LENGTH = 12
279
+    PASSWORD_CHARACTERS = '0123456789' \
280
+                          'abcdefghijklmonpqrstuvwxyz' \
281
+                          'ABCDEFGHIJKLMONPQRSTUVWXYZ'
282
+
276
     @classmethod
283
     @classmethod
277
     def current_item_id_key_in_context(cls):
284
     def current_item_id_key_in_context(cls):
278
         return 'user_id'
285
         return 'user_id'
326
             user.password = password
333
             user.password = password
327
         elif send_email:
334
         elif send_email:
328
             # Setup a random password to send email at user
335
             # Setup a random password to send email at user
329
-            password = str(uuid.uuid4())
336
+            password = self.generate_password()
330
             user.password = password
337
             user.password = password
331
 
338
 
332
         user.webdav_left_digest_response_hash = '%s:/:%s' % (email, password)
339
         user.webdav_left_digest_response_hash = '%s:/:%s' % (email, password)
351
         tg.flash(_('User {} created.').format(user.get_display_name()), CST.STATUS_OK)
358
         tg.flash(_('User {} created.').format(user.get_display_name()), CST.STATUS_OK)
352
         tg.redirect(self.url())
359
         tg.redirect(self.url())
353
 
360
 
361
+    @classmethod
362
+    def generate_password(
363
+            cls,
364
+            password_length = PASSWORD_LENGTH,
365
+            password_chars = PASSWORD_CHARACTERS
366
+            ):
367
+
368
+        # character list that will be contained into the password
369
+        char_list = []
370
+
371
+        for j in range(0, password_length):
372
+            # This puts a random char from the list above inside
373
+            # the list of chars and then merges them into a String
374
+            char_list.append(random.choice(password_chars))
375
+            password = ''.join(char_list)
376
+        return password
377
+
354
     @tg.expose('tracim.templates.admin.user_getone')
378
     @tg.expose('tracim.templates.admin.user_getone')
355
     def get_one(self, user_id):
379
     def get_one(self, user_id):
356
         current_user = tmpl_context.current_user
380
         current_user = tmpl_context.current_user