示例#1
0
def register_user(nick,
                  email=None,
                  password=None,
                  referer=None,
                  referral_of_id=None,
                  action_id=None,
                  is_bot=False,
                  gender=game_relations.GENDER.MASCULINE,
                  full_create=True):
    from the_tale.game import tt_api as game_tt_api
    from the_tale.game.heroes import logic as heroes_logic
    from the_tale.game.balance import constants as c

    if Account.objects.filter(nick=nick).exists():
        return REGISTER_USER_RESULT.DUPLICATE_USERNAME, None, None

    if email and Account.objects.filter(email=email).exists():
        return REGISTER_USER_RESULT.DUPLICATE_EMAIL, None, None

    try:
        referral_of = AccountPrototype.get_by_id(referral_of_id)
    except ValueError:
        referral_of = None

    if (email and not password) or (not email and password):
        raise exceptions.EmailAndPasswordError()

    is_fast = not (email and password)

    if is_fast and is_bot:
        raise exceptions.BotIsFastError()

    if password is None:
        password = accounts_settings.FAST_REGISTRATION_USER_PASSWORD

    account = AccountPrototype.create(nick=nick,
                                      email=email,
                                      is_fast=is_fast,
                                      is_bot=is_bot,
                                      password=password,
                                      referer=referer,
                                      referral_of=referral_of,
                                      action_id=action_id,
                                      gender=gender)

    AccountAchievementsPrototype.create(account)
    AccountItemsPrototype.create(account)

    hero = heroes_logic.create_hero(account=account, full_create=full_create)

    if full_create:
        game_tt_api.change_energy_balance(account_id=account.id,
                                          type='initial_contribution',
                                          energy=c.INITIAL_ENERGY_AMOUNT,
                                          async=False,
                                          autocommit=True)

        tt_api.create_cards_timer(account_id=account.id)

    return REGISTER_USER_RESULT.OK, account.id, hero.actions.current_action.bundle_id
示例#2
0
def register_user(nick,
                  email=None,
                  password=None,
                  referer=None,
                  referral_of_id=None,
                  action_id=None,
                  is_bot=False):
    from the_tale.game.heroes import logic as heroes_logic

    if Account.objects.filter(nick=nick).exists():
        return REGISTER_USER_RESULT.DUPLICATE_USERNAME, None, None

    if email and Account.objects.filter(email=email).exists():
        return REGISTER_USER_RESULT.DUPLICATE_EMAIL, None, None

    try:
        referral_of = AccountPrototype.get_by_id(referral_of_id)
    except ValueError:
        referral_of = None

    if (email and not password) or (not email and password):
        raise exceptions.EmailAndPasswordError()

    is_fast = not (email and password)

    if is_fast and is_bot:
        raise exceptions.BotIsFastError()

    if password is None:
        password = accounts_settings.FAST_REGISTRATION_USER_PASSWORD

    account = AccountPrototype.create(nick=nick,
                                      email=email,
                                      is_fast=is_fast,
                                      is_bot=is_bot,
                                      password=password,
                                      referer=referer,
                                      referral_of=referral_of,
                                      action_id=action_id)

    AccountAchievementsPrototype.create(account)
    AccountItemsPrototype.create(account)

    market_logic.create_goods(account.id)

    hero = heroes_logic.create_hero(account=account)

    return REGISTER_USER_RESULT.OK, account.id, hero.actions.current_action.bundle_id
示例#3
0
文件: logic.py 项目: Alkalit/the-tale
def register_user(nick, email=None, password=None, referer=None, referral_of_id=None, action_id=None, is_bot=False):

    if Account.objects.filter(nick=nick).exists():
        return REGISTER_USER_RESULT.DUPLICATE_USERNAME, None, None

    if email and Account.objects.filter(email=email).exists():
        return REGISTER_USER_RESULT.DUPLICATE_EMAIL, None, None

    try:
        referral_of = AccountPrototype.get_by_id(referral_of_id)
    except ValueError:
        referral_of = None

    if (email and not password) or (not email and password):
        raise exceptions.EmailAndPasswordError()

    is_fast = not (email and password)

    if is_fast and is_bot:
        raise exceptions.BotIsFastError()

    if password is None:
        password = accounts_settings.FAST_REGISTRATION_USER_PASSWORD

    account = AccountPrototype.create(nick=nick,
                                      email=email,
                                      is_fast=is_fast,
                                      is_bot=is_bot,
                                      password=password,
                                      referer=referer,
                                      referral_of=referral_of,
                                      action_id=action_id)

    AccountAchievementsPrototype.create(account)
    AccountItemsPrototype.create(account)

    market_logic.create_goods(account.id)

    hero = HeroPrototype.create(account=account)
    dress_new_hero(hero)
    messages_for_new_hero(hero)
    hero.save()

    return REGISTER_USER_RESULT.OK, account.id, hero.actions.current_action.bundle_id