コード例 #1
0
ファイル: person_tests.py プロジェクト: KestL/django-accounts
 def test_authenticate_bad(self):
     self.assertEquals(
         Person.authenticate(
             'snhorne',
             self.person_one.account,
             'wrongpassword',
         ), None)
コード例 #2
0
 def test_authenticate_bad(self):
     self.assertEquals(
         Person.authenticate(
             'snhorne',
             self.person_one.account,
             'wrongpassword',
         ),
         None
     )
コード例 #3
0
 def test_get_user_from_session_with_no_session_key(self):
     """
     Try to load person from session when ther is no session key
     """
     request = MockRequest()
     request.account = self.person_one.account
     self.assertEquals(
         Person.load_from_request(request),
         None,
     )
コード例 #4
0
ファイル: person_tests.py プロジェクト: KestL/django-accounts
 def test_get_user_from_session_with_no_session_key(self):
     """
     Try to load person from session when ther is no session key
     """
     request = MockRequest()
     request.account = self.person_one.account
     self.assertEquals(
         Person.load_from_request(request),
         None,
     )
コード例 #5
0
 def test_get_user_from_session(self):
     """
     Loads the user with id = request.session[Person.SESSION_KEY]
     """
     request = MockRequest()
     request.account = self.person_one.account
     self.person_one.login(request)
     self.assertEquals(
         Person.load_from_request(request),
         self.person_one,
     )
コード例 #6
0
ファイル: person_tests.py プロジェクト: KestL/django-accounts
 def test_get_user_from_session(self):
     """
     Loads the user with id = request.session[Person.SESSION_KEY]
     """
     request = MockRequest()
     request.account = self.person_one.account
     self.person_one.login(request)
     self.assertEquals(
         Person.load_from_request(request),
         self.person_one,
     )
コード例 #7
0
 def test_get_user_from_session_with_invalid_session_key(self):
     """
     Try to load person from session when the session key
     doesn't match any person's id.
     """
     request = MockRequest()
     request.account = self.person_one.account
     request.session[Person.SESSION_KEY] = 100
     self.assertEquals(
         Person.load_from_request(request),
         None,
     )
コード例 #8
0
ファイル: person_tests.py プロジェクト: KestL/django-accounts
 def test_get_user_from_session_with_invalid_session_key(self):
     """
     Try to load person from session when the session key
     doesn't match any person's id.
     """
     request = MockRequest()
     request.account = self.person_one.account
     request.session[Person.SESSION_KEY] = 100
     self.assertEquals(
         Person.load_from_request(request),
         None,
     )
コード例 #9
0
ファイル: person_tests.py プロジェクト: KestL/django-accounts
    def test_login_logout(self):
        request = MockRequest()
        self.person_one.login(request)
        # Person will be saved to request
        self.assertEquals(
            request.person,
            self.person_one,
        )
        # Person's id will be saved to session
        self.assertEquals(
            request.session[Person.SESSION_KEY],
            self.person_one.id,
        )

        # On logout these are cleared.
        Person.logout(request)

        self.assertEquals(
            request.person,
            None,
        )
        self.assertFalse(Person.SESSION_KEY in request.session, )
コード例 #10
0
ファイル: views.py プロジェクト: abz53378/wp_project_mango
def account_manage(request):
    if request.method == 'POST':
        username = request.POST.get('username', False)
        password = request.POST.get('password', False)
        name = request.POST.get('name', False)
        email = request.POST.get('email', False)
        social_id = request.POST.get('social_id', False)
        gender = request.POST.get('gender', False)
        birthday = request.POST.get('birthday', False)
        address = request.POST.get('address', False)
        phone = request.POST.get('phone', False)
        if not username or not password or not name or not email or not social_id or not gender or not birthday or not address or not phone:
            return HttpResponse(status=400)

        user = User.objects.create_user(username=username, password=password, email=email)
        user.save()

        # TODO set is_active to False, and send email to user

        person = Person(user=user,
                        name=name,
                        social_id=social_id,
                        gender=gender,
                        birthday=datetime.strptime(birthday, "%Y-%m-%d").date(),
                        address=address,
                        phone=phone)
        person.save()
        return HttpResponse(status=200)
    elif request.method == 'GET':
        if request.user.is_authenticated() == False:
            return HttpResponseForbidden()

        user = User.objects.get(username=request.user.username)
        response_data = model_to_dict(user.person, exclude=['id'])
        print(response_data)
        return HttpResponse(json.dumps(response_data,default=date_handler), status=200, content_type='application/json')
コード例 #11
0
 def test_login_logout(self):
     request = MockRequest()
     self.person_one.login(request)
     # Person will be saved to request
     self.assertEquals(
         request.person,
         self.person_one,
     )
     # Person's id will be saved to session
     self.assertEquals(
         request.session[Person.SESSION_KEY],
         self.person_one.id,
     )
     
     # On logout these are cleared.
     Person.logout(request)
     
     self.assertEquals(
         request.person,
         None,
     )
     self.assertFalse(
         Person.SESSION_KEY in request.session,
     )