Marcin Kuzminski  committed 9ddbfae

API: allowed password field to be null when used with ldap_dn ref #362
- added errors about non unique email to create_user api function

  • Participants
  • Parent commits 324ac36

Comments (0)

Files changed (1)

File rhodecode/controllers/api/

 import traceback
 import logging
-from sqlalchemy.orm.exc import NoResultFound
 from rhodecode.controllers.api import JSONRPCController, JSONRPCError
 from rhodecode.lib.auth import HasPermissionAllDecorator, \
-    HasPermissionAnyDecorator
+    HasPermissionAnyDecorator, PasswordGenerator
 from rhodecode.model.meta import Session
 from rhodecode.model.scm import ScmModel
 from rhodecode.model.db import User, UsersGroup, RepoGroup, Repository
 from rhodecode.model.repo import RepoModel
 from rhodecode.model.user import UserModel
-from rhodecode.model.repo_permission import RepositoryPermissionModel
 from rhodecode.model.users_group import UsersGroupModel
 from rhodecode.model.repos_group import ReposGroupModel
         return result
-    def create_user(self, apiuser, username, password, email, firstname=None,
+    def create_user(self, apiuser, username, email, password, firstname=None,
                     lastname=None, active=True, admin=False, ldap_dn=None):
         Create new user
         if User.get_by_username(username):
             raise JSONRPCError("user %s already exist" % username)
+        if User.get_by_email(email, case_insensitive=True):
+            raise JSONRPCError("email %s already exist" % email)
+        if ldap_dn:
+            # generate temporary password if ldap_dn
+            password = PasswordGenerator().gen_password(length=8)
             usr = UserModel().create_or_update(
                 username, password, email, firstname,