Пример #1
0
def register(request):
    args = {}
    args.update(csrf(request))
    args['form'] = UserCreationForm()
    if request.POST:
        newuser_form = UserCreationForm(request.POST)
        if newuser_form.is_valid():
            newuser_form.save()
            newuser = auth.authenticate(username=newuser_form.cleaned_data['username'], password=newuser_form.cleaned_data['password2'])
            auth.login(request, newuser)
            #Adding user to main bucket
            try:
                c = Bucket('couchbase://localhost/nihongo')
                username = newuser_form.cleaned_data['username']
                password = newuser_form.cleaned_data['password2']
                c_username = '******' + username
                new_user = {'username' : username, 'password' : password,  'doc_type' : 'user_doc'}
                doc_channels = [c_username]
                new_user['doc_channels'] = doc_channels
                c.upsert(c_username, new_user)
            except CouchbaseError as ce:
                raise Http404("Couchbase server error")
            #Adding user to sync gateway database
            SyncGateway.put_user(c_username, '*****@*****.**', password, [c_username])
            return redirect('/')
        else:
            args['form'] = newuser_form
    return render_to_response('register.html', args)
Пример #2
0
def confirm_ir(request, ir_id, group_id, user_id):
    print("IR CONFIRMATION")
    c = Bucket('couchbase://localhost/nihongo')
    user_doc = c.get(user_id).value
    password = user_doc['password']
    ir_doc = c.get(ir_id).value


    if 'accept' in request.POST:
        print("IR ACCEPTED")
        ir_doc['confirmed'] = 'accepted'
        sync_user = SyncGateway.get_user(user_id)
        new_sync_user = {}
        admin_channels = sync_user['admin_channels']
        #all_channels = sync_user['all_channels']
        admin_channels.append(group_id)

        SyncGateway.put_user(sync_user['name'], '*****@*****.**', password, admin_channels)
        print(sync_user)

    elif 'decline' in request.POST:
        ir_doc['confirmed'] = 'declined'
        print("IR DECLINED")
    c.upsert(ir_id, ir_doc)
    return HttpResponseRedirect(reverse('tutor:tutor_groups'))
Пример #3
0
 def test_create_session(self):
     SyncGateway.put_user("username1", "*****@*****.**", "password",
                          ["public"])
     res = SyncGateway.create_session("username1")
     self.assertEqual(res.status_code, 200)
     res = SyncGateway.create_session("username1", ttl=60 * 60 * 24)
     self.assertEqual(res.status_code, 200)
Пример #4
0
 def test_delete_user(self):
     res = SyncGateway.put_user("username1", "*****@*****.**", "password",
                                ["public"])
     res = SyncGateway.delete_user("username1")
     self.assertTrue(res)
     with self.assertRaises(SyncGatewayException):
         SyncGateway.get_user("*****@*****.**")
Пример #5
0
 def test_bug_with_load_by_uid(self):
     # it sets uid value to first textfield
     uid = 'unfilled_model_uid'
     incomplete_data = dict(title2='title')
     SyncGateway.save_json(uid, incomplete_data)
     m = Mock(uid)
     self.assertNotEqual(uid, m.title)
     self.assertFalse(bool(m.title))
Пример #6
0
 def test_bug_with_load_by_uid(self):
     # it sets uid value to first textfield
     uid = "unfilled_model_uid"
     incomplete_data = dict(title2="title")
     SyncGateway.save_json(uid, incomplete_data)
     m = Mock(uid)
     self.assertNotEqual(uid, m.title)
     self.assertFalse(bool(m.title))
Пример #7
0
    def handle(self, *args, **options):
        latest_modification_time = timezone.now() - timedelta(days=30)
        date_to = latest_modification_time.date().isoformat()

        for uid in self.get_uids(date_to):
            o = CouchbaseModel(uid)
            # print 'will delete %s / %s' % (uid, o.rev)
            SyncGateway.delete_document(uid, o.rev)
Пример #8
0
 def test_change_username(self):
     res = SyncGateway.put_user("*****@*****.**", "*****@*****.**", "password", ["public", "boo"])
     res = SyncGateway.change_username("*****@*****.**", "*****@*****.**", "password")
     self.assertTrue(res)
     d = SyncGateway.get_user("*****@*****.**")
     self.assertEqual(d["name"], "*****@*****.**")
     self.assertEqual(d["email"], "*****@*****.**")
     self.assertIn("boo", d["admin_channels"])
     with self.assertRaises(SyncGatewayException):
         SyncGateway.get_user("*****@*****.**")
Пример #9
0
 def test_change_username(self):
     res = SyncGateway.put_user("*****@*****.**", "*****@*****.**", "password", ["public", 'boo'])
     res = SyncGateway.change_username("*****@*****.**", "*****@*****.**", "password")
     self.assertTrue(res)
     d = SyncGateway.get_user("*****@*****.**")
     self.assertEqual(d['name'], "*****@*****.**")
     self.assertEqual(d['email'], "*****@*****.**")
     self.assertIn('boo', d['admin_channels'])
     with self.assertRaises(SyncGatewayException):
         SyncGateway.get_user("*****@*****.**")
Пример #10
0
def clean_buckets():
    if "test" not in settings.COUCHBASE_BUCKET:
        raise Exception("will not clean non-test bucket")

    all_docs = SyncGateway.all_docs([], really_all=True)

    for i in all_docs["rows"]:
        uid = i["id"]
        rev = i["value"]["rev"]
        if "sync" in uid:
            continue
        # print 'del %s' % uid
        SyncGateway.delete_document(uid, rev)
Пример #11
0
 def test_remove_channels(self):
     c = str(uuid4())
     new_c1 = str(uuid4())
     new_c2 = str(uuid4())
     username = "******"
     SyncGateway.put_user(username, "*****@*****.**", "password", ["public", c, new_c1, new_c2])
     SyncGateway.remove_channels(username, [new_c1, new_c2])
     d = SyncGateway.get_user(username)
     self.assertIn(c, d["admin_channels"])
     self.assertIn("public", d["admin_channels"])
     self.assertNotIn(new_c1, d["admin_channels"])
     self.assertNotIn(new_c2, d["admin_channels"])
     self.assertEqual(2, len(d["admin_channels"]))
Пример #12
0
def clean_buckets():
    if 'test' not in settings.COUCHBASE_BUCKET:
        raise Exception('will not clean non-test bucket')

    all_docs = SyncGateway.all_docs([], really_all=True)

    for i in all_docs['rows']:
        uid = i['id']
        rev = i['value']['rev']
        if 'sync' in uid:
            continue
        # print 'del %s' % uid
        SyncGateway.delete_document(uid, rev)
Пример #13
0
 def test_remove_channels(self):
     c = str(uuid4())
     new_c1 = str(uuid4())
     new_c2 = str(uuid4())
     username = '******'
     SyncGateway.put_user(username, "*****@*****.**", "password",
                          ["public", c, new_c1, new_c2])
     SyncGateway.remove_channels(username, [new_c1, new_c2])
     d = SyncGateway.get_user(username)
     self.assertIn(c, d['admin_channels'])
     self.assertIn('public', d['admin_channels'])
     self.assertNotIn(new_c1, d['admin_channels'])
     self.assertNotIn(new_c2, d['admin_channels'])
     self.assertEqual(2, len(d['admin_channels']))
Пример #14
0
 def test_append_channels(self):
     c = str(uuid4())
     new_c1 = str(uuid4())
     new_c2 = str(uuid4())
     username = '******'
     SyncGateway.put_user(
         username,
         "*****@*****.**",
         "password",
         ["public", c]
     )
     SyncGateway.append_channels(username, [new_c1, new_c2])
     d = SyncGateway.get_user(username)
     self.assertIn(c, d['admin_channels'])
     self.assertIn('public', d['admin_channels'])
     self.assertIn(new_c1, d['admin_channels'])
     self.assertIn(new_c2, d['admin_channels'])
     self.assertEqual(4, len(d['admin_channels']))
Пример #15
0
    def setUp(self):
        from django_cbtools.management.commands.create_cb_views import Command

        SyncGateway.put_admin_user()
        command = Command()
        command.handle()

        # get random string to use as channel
        fake = Mock()
        self.channel = fake.get_uid()
        # print self.channel

        m = Mock(title="my title", b=True, num=12)
        m.channels.append(self.channel)
        m.save()
        self.uid1 = m.uid

        m = Mock(title="my title", b=True, num=12)
        m.channels.append(self.channel)
        m.save()
        self.uid2 = m.uid
Пример #16
0
    def setUp(self):
        from django_cbtools.management.commands.create_cb_views import Command

        SyncGateway.put_admin_user()
        command = Command()
        command.handle()

        # get random string to use as channel
        fake = Mock()
        self.channel = fake.get_uid()
        # print self.channel

        m = Mock(title="my title", b=True, num=12)
        m.channels.append(self.channel)
        m.save()
        self.uid1 = m.uid

        m = Mock(title="my title", b=True, num=12)
        m.channels.append(self.channel)
        m.save()
        self.uid2 = m.uid
Пример #17
0
 def test_delete_user(self):
     res = SyncGateway.put_user("username1", "*****@*****.**", "password", ["public"])
     res = SyncGateway.delete_user("username1")
     self.assertTrue(res)
     with self.assertRaises(SyncGatewayException):
         SyncGateway.get_user("*****@*****.**")
Пример #18
0
 def test_create_user(self):
     res = SyncGateway.put_user("username1", "*****@*****.**", "password", ["public"])
     self.assertTrue(res)
Пример #19
0
 def test_create_user(self):
     res = SyncGateway.put_user("username1", "*****@*****.**", "password", ["public"])
     self.assertTrue(res)
Пример #20
0
 def setUp(self):
     SyncGateway.put_admin_user()
     clean_buckets()
     self.maxDiff = None
Пример #21
0
 def setUp(self):
     SyncGateway.put_admin_user()
     clean_buckets()
     self.maxDiff = None
Пример #22
0
 def handle(self, *args, **options):
     SyncGateway.put_admin_user()
     SyncGateway.put_guest_user()
Пример #23
0
 def test_st_deleted_new_object(self):
     uid = 'some_key'
     data = dict(title2='title')
     SyncGateway.save_json(uid, data)
     m = Mock(uid)
     self.assertFalse(m.st_deleted)
Пример #24
0
 def test_get_user(self):
     SyncGateway.put_user("*****@*****.**", "*****@*****.**", "password", ["public"])
     d = SyncGateway.get_user("*****@*****.**")
     self.assertEqual(d['name'], "*****@*****.**")
     self.assertEqual(d['email'], "*****@*****.**")
Пример #25
0
 def test_create_session_for_non_existing_user(self):
     with self.assertRaises(SyncGatewayException):
         SyncGateway.create_session("not_existing_user")
Пример #26
0
 def test_create_session(self):
     SyncGateway.put_user("username1", "*****@*****.**", "password", ["public"])
     res = SyncGateway.create_session("username1")
     self.assertEqual(res.status_code, 200)
     res = SyncGateway.create_session("username1", ttl=60 * 60 * 24)
     self.assertEqual(res.status_code, 200)
Пример #27
0
 def test_create_session_for_non_existing_user(self):
     with self.assertRaises(SyncGatewayException):
         SyncGateway.create_session("not_existing_user")
Пример #28
0
 def setUp(self):
     SyncGateway.put_admin_user()
     clean_buckets()
Пример #29
0
 def test_get_user(self):
     SyncGateway.put_user("*****@*****.**", "*****@*****.**", "password", ["public"])
     d = SyncGateway.get_user("*****@*****.**")
     self.assertEqual(d["name"], "*****@*****.**")
     self.assertEqual(d["email"], "*****@*****.**")
Пример #30
0
 def test_st_deleted_new_object(self):
     uid = "some_key"
     data = dict(title2="title")
     SyncGateway.save_json(uid, data)
     m = Mock(uid)
     self.assertFalse(m.st_deleted)
Пример #31
0
 def setUp(self):
     SyncGateway.put_admin_user()
     clean_buckets()
Пример #32
0
 def handle(self, *args, **options):
     SyncGateway.put_admin_user()
     SyncGateway.put_guest_user()