Пример #1
0
 def setUp(self):
     self.other_user = AccountFactory.create()
     self.other_user_post = PostFactory.create(owner=self.other_user,
                                               publisher=self.other_user)
     self.account = AccountFactory.create()
     self.user = self.account.user
     [
         PostFactory.create(owner=self.account, publisher=self.account)
         for _ in range(2)
     ]
Пример #2
0
 def setUp(self):
     account0 = AccountFactory.create(user__first_name='Search 0')
     account1 = AccountFactory.create(user__first_name='Search 1')
     account2 = AccountFactory.create(user__first_name='Search 2')
     RelationshipFactory.create(owner=account0, follow=account1)
     RelationshipFactory.create(owner=account1, follow=account2)
     [PostFactory.create(owner=account0, publisher=account0,
                         title='Search A', tags='search') for _ in range(2)]
     [PostFactory.create(owner=account1, publisher=account1,
                         title='Search B', tags='search') for _ in range(2)]
     [PostFactory.create(owner=account2, publisher=account2,
                         title='Search C', tags='search') for _ in range(2)]
     [PostFactory.create(title='Search D', tags='search') for _ in range(2)]
     self.user = account0.user
Пример #3
0
 def setUp(self):
     new_user = AccountFactory.build().user
     self.account = AccountFactory.create()
     self.user = self.account.user
     self.form_login = {
         'identity': self.user.username,
         'password': DEFAULT_PASSWORD,
     }
     self.form_user = {
         'first_name': new_user.first_name,
         'last_name': new_user.last_name,
         'username': new_user.username,
         'email': new_user.email,
         'password': DEFAULT_PASSWORD,
     }
Пример #4
0
def login(request):
    # 不接受POST请求
    if request.method != 'GET':
        raise Http404()

    account = AccountFactory.getAccountObj()
    return account.login(request)
Пример #5
0
 def test_follow_other_user(self):
     user2 = AccountFactory.create().user
     self.client.login(username=self.user.username,
                       password=DEFAULT_PASSWORD)
     response = self.client.post(
         reverse('account_follow', args=[user2.username]))
     self.assertRedirects(response, reverse('profile',
                                            args=[user2.username]))
Пример #6
0
    def authenticate(self, ticket=None, request=None):
        account = AccountFactory.getAccountObj()
        status, user = account.check_backend_login_status(request)

        if not status or not user:
            return None

        return user
Пример #7
0
 def process_response(self, request, response):
     """
     统一处理response请求
     """
     account = AccountFactory.getAccountObj()
     # 统一处理 response, 包括 cookie、session 等
     response = account.handel_response(request, response)
     return response
Пример #8
0
 def test_unfollow_following_user(self):
     account2 = AccountFactory.create()
     RelationshipFactory.create(owner=self.account, follow=account2)
     self.client.login(username=self.user.username,
                       password=DEFAULT_PASSWORD)
     response = self.client.post(
         reverse('account_unfollow', args=[account2.user.username]))
     self.assertRedirects(response,
                          reverse('profile', args=[account2.user.username]))
Пример #9
0
def get_login_state(request):
    """
    获取登录态
    """
    account = AccountFactory.getAccountObj()
    # 重定向到首页
    response = HttpResponseRedirect(SITE_URL)
    # 处理登录的cookie
    response = account.handel_response(request, response)
    return response
Пример #10
0
    def setUp(self) -> None:
        self.client = Client()
        self.user = AccountFactory()
        self.alarm_statuses = [
            AlarmStatusFactory(),
            AlarmStatusFactory(),
        ]
        self.house = HouseFactory()

        self.client.force_login(self.user)
Пример #11
0
def http_referer(request):
    """
    获取 HTTP_REFERER 头
    """
    if 'HTTP_REFERER' in request.META:
        http_referer = urlparse.urlparse(request.META['HTTP_REFERER'])[2]
    else:
        from account.factories import AccountFactory
        account = AccountFactory.getAccountObj()
        http_referer = account._config.LOGIN_REDIRECT_URL
    return http_referer
Пример #12
0
    def process_view(self, request, view, args, kwargs):
        """
        校验登录, 如果未登录由跳转登录页
        """
        # 判断豁免权
        if getattr(view, 'login_exempt', False):
            return None

        # 判断用户登录状态是否OK
        account = AccountFactory.getAccountObj()
        loginStatus = account.check_user_login_status(request)
        if loginStatus == 0:
            return None

        # 判断视图是不是自定义了login_url和redirect_field_name
        loginUrl = getattr(view, 'login_url', account.getConfig().LOGIN_URL)
        redirectFieldName = getattr(view, 'redirect_field_name',
                                    REDIRECT_FIELD_NAME)

        # 对于登录态不OK的用户, 引导重新登录 (首页的直接跳登录页, 非首页的跳登录态错误页)
        return account.redirectReLogin(request, loginUrl, redirectFieldName)
Пример #13
0
def login_success(request):
    """
    登录成功页面
    """
    account = AccountFactory.getAccountObj()
    return account.login_success(request)
Пример #14
0
def check_failed(request):
    """
    权限验证错误页面
    """
    account = AccountFactory.getAccountObj()
    return account.check_failed(request)
Пример #15
0
def logout(request):
    account = AccountFactory.getAccountObj()
    return account.logout(request)
Пример #16
0
def login_page(request):
    """
    平台统一登录页面
    """
    account = AccountFactory.getAccountObj()
    return account.login_page(request)
Пример #17
0
 def setUp(self):
     account = AccountFactory.create()
     self.user = account.user
Пример #18
0
 def setUpTestData(cls):
     cls.account = AccountFactory()