示例#1
0
    def registration(cls, login, email, password, is_superuser=False,
                     first_name=None, last_name=None, role=None):
        """
        регистрация пользователя в системе

        :param login - логин
        :param email
        :param password
        :param is_superuser
        :param first_name
        :param last_name
        :param role - роли в системе (список строк ролей)

        :return User
        """

        if not cls.check_duplicate(login):
            raise UserService.DuplicateError(
                u"В системе есть пользователь с логином - '%s'" % login)

        role = role or ['user']
        user = user_datastore.create_user(
            login=login, email=email, is_superuser=is_superuser,
            password=generate_password_hash(password), first_name=first_name,
            last_name=last_name, roles=role)
        profile = Profile()
        profile.user = user

        return user
示例#2
0
 def setting_to_user(cls, user):
     profile = Profile.query.filter(
         Profile.user_id == user.id
     )
     if profile.count() == 0:
         profile = Profile()
         profile.user = user
         db.session.add(profile)
         db.session.commit()
     else:
         profile = profile.one()
     return profile