def login_post(request):
    vm = LoginViewModel(request)
    vm.validate()

    if not vm.user:
        # Haxors more slow
        time.sleep(5)

    if vm.error:
        return vm.to_dict()

    vm.user_svc.login(vm.user.id)
    navigaiton.redirect_to('/account')
def register_post(request):
    vm = RegisterViewModel(request)
    vm.validate()

    if vm.error:
        return vm.to_dict()

    try:
        user = user_service.create_account(vm.full_name, vm.email, vm.password)
        vm.user_svc.login(user.id)
    except Exception as x:
        vm.error = 'Could not create your account: {}'.format(x)
        return vm.to_dict()

    navigaiton.redirect_to('/account')
def logout(request):
    session = UserSession(request)
    session.logout()
    navigaiton.redirect_to('/')
def register_get(request):
    vm = RegisterViewModel(request)
    if vm.user:
        navigaiton.redirect_to('/account')

    return vm.to_dict()
def login_get(request):
    vm = LoginViewModel(request)
    if vm.user:
        navigaiton.redirect_to('/account')

    return vm.to_dict()
def index(request):
    vm = AccountHomeViewModel(request)
    if not vm.user:
        navigaiton.redirect_to('/account/login')

    return vm.to_dict()