Beispiel #1
0
    def register_companies(self, count = 10, verified = True):
        companies = []
        for a in xrange(count):
            user = User.create_user('*****@*****.**' % a, User.make_random_password())
            if not user:
                raise Exception('failed to create test user')
            User.collection.update({'_id' : user._id}, {'$set' : {'activated' : True}})

            employee = CompanyEmployee({'user_id' : user._id,
                                        'first_name' : 'test_user_' + str(a)})
            employee.save()
            company = Company({'rek_id' : integer_to_code(a + 10000),
                'owner_employee_id' : employee._id,
                'short_name' : 'tc_' + str(a),
                'full_name' : 'OOO Test Company ' + str(a),
                'brand_name' : 'Test Company Brand ' + str(a),
                'description' : 'Test company ' + str(a),
                'category_text' : 'Testing',
                'staff_size' : (a + 1) * 3,
                'inn' : int(str(a + 1) + '0' * (12 - len(str(a)))) + a + 1,
                'kpp' : int(str(a + 1) + '1' * (9 - len(str(a)))) + a + 1,
                'is_account_activated' : True,
                'account_status' : CompanyAccountStatus.VERIFIED if verified else CompanyAccountStatus.JUST_REGISTERED
            })
            company.save()
            employee.set(company_id = company._id)
            companies.append(company)

        return companies
    def handle(self, *args, **options):
        email = options.get('email', None)
        password = options.get('password', None)
        interactive = options.get('interactive')
        verbosity = int(options.get('verbosity', 1))

        # Do quick and dirty validation if --noinput
        if not interactive:
            if not password or not email:
                raise CommandError("You must use --password and --email with --noinput.")
            try:
                is_valid_email(email)
            except exceptions.ValidationError:
                raise CommandError("Invalid email address.")
            password = password.strip()
            if not len(password) < 6:
                raise CommandError("Password length must be > 5.")

        # Prompt for username/email/password. Enclose this whole thing in a
        # try/except to trap for a keyboard interrupt and exit gracefully.
        if interactive:
            try:

                # Get an email
                while 1:
                    if not email:
                        email = raw_input('E-mail address: ')
                        email = email.strip().lower()
                    try:
                        is_valid_email(email)
                    except exceptions.ValidationError:
                        sys.stderr.write("Error: That e-mail address is invalid.\n")
                        email = None
                    else:
                        break

                # Get a password
                while 1:
                    if not password:
                        password = getpass.getpass()
                        password2 = getpass.getpass('Password (again): ')
                        if password != password2:
                            sys.stderr.write("Error: Your passwords didn't match.\n")
                            password = None
                            continue
                    if len(password.strip()) < 6:
                        sys.stderr.write("Password length must be > 5.\n")
                        password = None
                        continue
                    break
            except KeyboardInterrupt:
                sys.stderr.write("\nOperation cancelled.\n")
                sys.exit(1)

        email = email.strip().lower()
        try:
            user = User.create_user(email, password)
            User.collection.update({'_id' : user._id}, {'$set' : {'is_superuser' : True}})
        except Exception, ex:
            sys.stderr.write("\nFailed to create user.\n%s\n" % unicode(ex))
    def register_verification_requesters(self, target_company, count = 10, status = RecommendationStatusEnum.RECEIVED):
        requesters = []
        for a in xrange(count):
            user = User.create_user('*****@*****.**' % a, 'aaa')
            User.collection.update({'_id' : user._id}, {'$set' : {'activated' : True}})
            if not user:
                raise Exception('failed to create test user')

            employee = CompanyEmployee({'user_id' : user._id,
                                        'first_name' : 'test_user_' + str(a)})
            employee.save()
            company = Company({'rek_id' : integer_to_code(a + 10000),
                               'owner_employee_id' : employee._id,
                               'short_name' : 'tc_' + str(a),
                               'full_name' : 'OOO Test Company ' + str(a),
                               'brand_name' : 'Test Company Brand ' + str(a),
                               'description' : 'Test company ' + str(a),
                               'category_text' : 'Testing',
                               'staff_size' : (a + 1) * 3,
                               'inn' : int(str(a + 1) + '0' * (12 - len(str(a)))) + a + 1,
                               'kpp' : int(str(a + 1) + '1' * (9 - len(str(a)))) + a + 1,
                               'account_status' : CompanyAccountStatus.JUST_REGISTERED,
                               'is_account_activated' : True
            })
            company.save()
            employee.set(company_id = company._id)

            request = RecommendationRequest({'requester' : company._id,
                                             'recipient' : target_company._id,
                                             'status' : status,
                                             'message' : 'Please recommend me.',
                                             'requester_email' : user.email})
            request.save()

            requesters.append((company, employee, user, request))
        return requesters
Beispiel #4
0
    def handle(self, *args, **options):
        email = options.get('email', None)
        password = options.get('password', None)
        interactive = options.get('interactive')
        verbosity = int(options.get('verbosity', 1))

        # Do quick and dirty validation if --noinput
        if not interactive:
            if not password or not email:
                raise CommandError(
                    "You must use --password and --email with --noinput.")
            try:
                is_valid_email(email)
            except exceptions.ValidationError:
                raise CommandError("Invalid email address.")
            password = password.strip()
            if not len(password) < 6:
                raise CommandError("Password length must be > 5.")

        # Prompt for username/email/password. Enclose this whole thing in a
        # try/except to trap for a keyboard interrupt and exit gracefully.
        if interactive:
            try:

                # Get an email
                while 1:
                    if not email:
                        email = raw_input('E-mail address: ')
                        email = email.strip().lower()
                    try:
                        is_valid_email(email)
                    except exceptions.ValidationError:
                        sys.stderr.write(
                            "Error: That e-mail address is invalid.\n")
                        email = None
                    else:
                        break

                # Get a password
                while 1:
                    if not password:
                        password = getpass.getpass()
                        password2 = getpass.getpass('Password (again): ')
                        if password != password2:
                            sys.stderr.write(
                                "Error: Your passwords didn't match.\n")
                            password = None
                            continue
                    if len(password.strip()) < 6:
                        sys.stderr.write("Password length must be > 5.\n")
                        password = None
                        continue
                    break
            except KeyboardInterrupt:
                sys.stderr.write("\nOperation cancelled.\n")
                sys.exit(1)

        email = email.strip().lower()
        try:
            user = User.create_user(email, password)
            User.collection.update({'_id': user._id},
                                   {'$set': {
                                       'is_superuser': True
                                   }})
        except Exception, ex:
            sys.stderr.write("\nFailed to create user.\n%s\n" % unicode(ex))
Beispiel #5
0
def create_new_account(email, password, brand_name, promo_code = None, invite_cookie = None):
    # mustdo: add "transaction"
    created_user = User.create_user(email, password)
    if not created_user:
        raise Exception('failed to create user')

    activation_link = UserActivationLinks({'user' : created_user._id})
    activation_link.save()

    new_employee = CompanyEmployee({'user_id':created_user._id, 'timezone' : 'Europe/Moscow'})
    new_employee.save()

    new_company = Company({'rek_id':generate_rek_id(),
                           'owner_employee_id':new_employee._id,
                           'brand_name' : brand_name})
    new_company.save()

    new_billing_account = Account({'type' : Account.TYPE_COMPANY,
                                   'name' : "Счет компании",
                                   'details' : {'subject_id' : new_company._id}})
    new_billing_account.save()

    if promo_code:
        promo_code.use(new_company._id)
        promo_account = Account.objects.get_one({'system_id' : Account.FIXED_PROMO_ACCOUNT_ID})
        transaction = Transaction({'source' : promo_account._id,
                                   'dest' : new_billing_account._id,
                                   'amount' : Currency.russian_roubles(SettingsManager.get_property("registration_promo_action_amount")),
                                   'comment' : u"Бонус при регистрации компании по промо-коду %s" % unicode(promo_code.code)})
        transaction.save()
        transaction.apply()

    new_employee.set(company_id=new_company._id)

    if invite_cookie and len(invite_cookie):
        invite = Invite.objects.get_one({'cookie_code' : invite_cookie})
        if invite:
            rec_request = RecommendationRequest({'requester' : new_company._id,
                                                 'recipient' : invite.sender,
                                                 'status' : RecommendationStatusEnum.ACCEPTED,
                                                 'message' : u'Регистрация по приглашению: %s' % invite.message,
                                                 'viewed' : True,
                                                 'requester_email' : '*****@*****.**'})
            rec_request.save()
            invite.rec_request = rec_request._id
            invite.save()
            if SettingsManager.get_property('rnes') < 2:
                new_company.objects.update({'_id' : new_company._id}, {'$set' : {'account_status' : CompanyAccountStatus.VERIFIED}})
                new_company.account_status = CompanyAccountStatus.VERIFIED

                dest_account = Account.objects.get_one({'type' : Account.TYPE_COMPANY,
                                                        'details.subject_id' : invite.sender})

                if dest_account:
                    promo_account = Account.objects.get_one({'system_id' : Account.FIXED_PROMO_ACCOUNT_ID})
                    if promo_account:
                        new_trans = Transaction({'source' : promo_account._id,
                                                 'dest' : dest_account._id,
                                                 'amount' : Currency.russian_roubles(SettingsManager.get_property('invite_bonus')),
                                                 'comment' : u'Бонус за приглашение компании "%s" (%s)' % (brand_name, new_company.rek_id)})
                        new_trans.save()
                        new_trans.apply()
    return created_user, password, new_company, activation_link
Beispiel #6
0
def create_staff_user(email):
    password = User.make_random_password()
    created_user = User.create_user(email, password)
    created_user.save()

    return created_user, password
Beispiel #7
0
def create_new_account(email,
                       password,
                       brand_name,
                       promo_code=None,
                       invite_cookie=None):
    # mustdo: add "transaction"
    created_user = User.create_user(email, password)
    if not created_user:
        raise Exception('failed to create user')

    activation_link = UserActivationLinks({'user': created_user._id})
    activation_link.save()

    new_employee = CompanyEmployee({
        'user_id': created_user._id,
        'timezone': 'Europe/Moscow'
    })
    new_employee.save()

    new_company = Company({
        'rek_id': generate_rek_id(),
        'owner_employee_id': new_employee._id,
        'brand_name': brand_name
    })
    new_company.save()

    new_billing_account = Account({
        'type': Account.TYPE_COMPANY,
        'name': "Счет компании",
        'details': {
            'subject_id': new_company._id
        }
    })
    new_billing_account.save()

    if promo_code:
        promo_code.use(new_company._id)
        promo_account = Account.objects.get_one(
            {'system_id': Account.FIXED_PROMO_ACCOUNT_ID})
        transaction = Transaction({
            'source':
            promo_account._id,
            'dest':
            new_billing_account._id,
            'amount':
            Currency.russian_roubles(
                SettingsManager.get_property(
                    "registration_promo_action_amount")),
            'comment':
            u"Бонус при регистрации компании по промо-коду %s" %
            unicode(promo_code.code)
        })
        transaction.save()
        transaction.apply()

    new_employee.set(company_id=new_company._id)

    if invite_cookie and len(invite_cookie):
        invite = Invite.objects.get_one({'cookie_code': invite_cookie})
        if invite:
            rec_request = RecommendationRequest({
                'requester':
                new_company._id,
                'recipient':
                invite.sender,
                'status':
                RecommendationStatusEnum.ACCEPTED,
                'message':
                u'Регистрация по приглашению: %s' % invite.message,
                'viewed':
                True,
                'requester_email':
                '*****@*****.**'
            })
            rec_request.save()
            invite.rec_request = rec_request._id
            invite.save()
            if SettingsManager.get_property('rnes') < 2:
                new_company.objects.update({'_id': new_company._id}, {
                    '$set': {
                        'account_status': CompanyAccountStatus.VERIFIED
                    }
                })
                new_company.account_status = CompanyAccountStatus.VERIFIED

                dest_account = Account.objects.get_one({
                    'type':
                    Account.TYPE_COMPANY,
                    'details.subject_id':
                    invite.sender
                })

                if dest_account:
                    promo_account = Account.objects.get_one(
                        {'system_id': Account.FIXED_PROMO_ACCOUNT_ID})
                    if promo_account:
                        new_trans = Transaction({
                            'source':
                            promo_account._id,
                            'dest':
                            dest_account._id,
                            'amount':
                            Currency.russian_roubles(
                                SettingsManager.get_property('invite_bonus')),
                            'comment':
                            u'Бонус за приглашение компании "%s" (%s)' %
                            (brand_name, new_company.rek_id)
                        })
                        new_trans.save()
                        new_trans.apply()
    return created_user, password, new_company, activation_link
Beispiel #8
0
def create_staff_user(email):
    password = User.make_random_password()
    created_user = User.create_user(email, password)
    created_user.save()

    return created_user, password