Esempio n. 1
0
    def test_has_functions(self):
        self.assertEqual(auth.hasUser("00000000-0000-0000-C000-000000000046"), True)
        self.assertEqual(auth.hasUser("6a8f7800-91ba-11e5-af58-0002a5d5c51b"), True)
        self.assertEqual(auth.hasUser("576a5880-91ba-11e5-833f-0002a5d5c51b"), False)

        self.assertEqual(auth.hasProfile("00000000-0000-0000-C000-000000000046"), True)
        self.assertEqual(auth.hasProfile("6a8f7800-91ba-11e5-af58-0002a5d5c51b"), False)
        self.assertEqual(auth.hasProfile("576a5880-91ba-11e5-833f-0002a5d5c51b"), False)
Esempio n. 2
0
def apply_paying_info(request):
    if auth.isLogin(request):
        user = auth.get_user_data(request)
        if auth.hasProfile(user.uuid):

            try:
                req_data = json.loads(request.body)
                order = Orders.objects.get(uuid=req_data["OID"], Orderer=user)
                order.paid_account = req_data["PACCOUNT"]
                order.paid_date = datetime.date(
                    datetime.date.today().year, int(req_data["PMONTH"]), int(req_data["PDAY"])
                )
                order.save()

                response = HttpResponse()
                response.status_code = 200
                return response

            except ObjectDoesNotExist:
                response = HttpResponse()
                response.status_code = 400
                return response

    response = HttpResponse()
    response.status_code = 403

    return response
Esempio n. 3
0
def order(request, ordering):
    if auth.isLogin(request) and auth.hasProfile(auth.get_user_data(request).uuid):
        parts = json.loads(request.body)["order_list"].split(",")
        parts = map(lambda x: x.split(":"), parts)
        parts_detail = map(lambda x: [retrieve_component_detail(x[0]), int(x[1])], parts)

        non_exist_or_noprice = filter(lambda x: x[0].unit_price <= 0, parts_detail)

        part_detail_dicts = map(lambda x: addquantity(model_to_dict(x[0]), x[1]), parts_detail)
        part_detail_dicts = map(lambda x: removekey(x, "associated_order"), part_detail_dicts)
        part_detail_dicts = map(lambda x: removekey(x, "id"), part_detail_dicts)
        # XXX: show pass common name to front end
        # map(lambda x: operator.setitem(x, "generic_type", model_to_dict(GComponents.objects.get(pk = x["generic_type"]))), part_detail_dicts)
        # map(lambda x: x["generic_type"].pop("id"), part_detail_dicts)
        # map(lambda x: x["generic_type"].pop("ctype"), part_detail_dicts)

        response = HttpResponse(json.dumps(part_detail_dicts))

        if len(non_exist_or_noprice):
            response.status_code = 400
        else:
            if ordering:
                user = auth.get_user_data(request)
                profile = auth.get_user_profile(request)
                create_order(user, profile, parts_detail)
                mail.send_order_received(request)
            response.status_code = 200
        return response
    else:
        response = HttpResponse()
        response.status_code = 403

        return response
Esempio n. 4
0
def edit_component_comment(request):
    payload = json.loads(request.body)

    if auth.isLogin(request):
        user = auth.get_user_data(request)
        if auth.hasProfile(user.uuid):
            try:
                comment = Comment.objects.get(pk = int(payload['pk']), commenter = user)

                comment.text = payload['content']

                comment.save()

                response = HttpResponse()
                response.status_code = 200

                return response
            except:
                response = HttpResponse()
                response.status_code = 404

                return response

    response = HttpResponse()
    response.status_code = 403

    return response
Esempio n. 5
0
 def init_user(self, uuid, access_token):
     if auth.hasUser(uuid) and auth.hasProfile(uuid):
         return False
     else:
         if auth.create_empty_user(uuid, self.provider_name, access_token):
             return True
         else:
             raise RuntimeError
Esempio n. 6
0
    def init_session_with_uuid(self, uuid, request):
        if auth.hasUser(uuid):
            if auth.create_session(request, uuid):
                if auth.hasProfile(uuid):
                    return redirect("digikey.views.progress_page")

                else:
                    return redirect("login.views.profile")
            else:
                raise RuntimeError
        else:
            raise RuntimeError
Esempio n. 7
0
def chatroom(request):
    if auth.isLogin(request):
        data = auth.get_user_data(request)
        if auth.hasProfile(data.uuid):
            profile = auth.get_user_profile(request)
            return render(request, "chatroom.html", {'username' : profile.username,
                                                     'disp': 'static'})
        else:
            return redirect("/profile/")

    else:
        return render(request, "chatroom.html", {'username' : '',
                                                 'disp': 'none'})
Esempio n. 8
0
def get_user_orders(request):
    if auth.isLogin(request):
        user = auth.get_user_data(request)
        if auth.hasProfile(user.uuid):

            order_list = []

            for order in Orders.objects.all().filter(Orderer=user):

                order_list.append(order.uuid)

            response = HttpResponse(json.dumps(order_list))

            return response

    response = HttpResponse()
    response.status_code = 403

    return response
Esempio n. 9
0
def update_profile(request):
    if auth.isLogin(request):
        uuid = auth.get_user_data(request).uuid

        user_profile = User_Profiles(
            username=request.POST["username"],
            email=request.POST["email"],
            default_shipping_address=request.POST["shipping_address"],
            phone_number=request.POST["phone"],
            real_name=request.POST["realname"],
            tw_id=request.POST["id"],
        )

        if not auth.hasProfile(uuid):
            auth.register_data(uuid, user_profile)
        else:
            auth.update_data(uuid, user_profile)

        return redirect("digikey.views.progress_page")
Esempio n. 10
0
def order_page(request):
    if auth.isLogin(request):
        data = auth.get_user_data(request)
        if auth.hasProfile(data.uuid):
            profile = auth.get_user_profile(request)
            return render(
                request,
                "order.html",
                {
                    "realname": profile.real_name,
                    "email": profile.email,
                    "shipping_address": profile.default_shipping_address,
                    "phone": profile.phone_number,
                },
            )
        else:
            return redirect("/profile/")

    response = HttpResponse()
    response.status_code = 403
    return response
Esempio n. 11
0
def del_component_comment(request):
    if auth.isLogin(request):
        user = auth.get_user_data(request)
        if auth.hasProfile(user.uuid):
            try:
                comment = Comment.objects.get(pk = int(request.GET['pk']), commenter = user)

                comment.delete()

                response = HttpResponse()
                response.status_code = 200

                return response
            except:
                response = HttpResponse()
                response.status_code = 404

                return response

    response = HttpResponse()
    response.status_code = 403

    return response
Esempio n. 12
0
def profile(request):
    if isLogin(request):
        data = auth.get_user_data(request)
        if auth.hasProfile(data.uuid):
            profile = auth.get_user_profile(request)

            return render(
                request,
                "profile.html",
                {
                    "realname": profile.real_name,
                    "email": profile.email,
                    "username": profile.username,
                    "shipping_address": profile.default_shipping_address,
                    "id": profile.tw_id,
                    "phone": profile.phone_number,
                },
            )

        else:
            login_provider = login_providers[data.login_service](request)

            uuid, data = login_provider.get_userdata_and_uuid(data.access_token, request)

            return render(
                request,
                "profile.html",
                {
                    "realname": data.real_name,
                    "email": data.email,
                    "username": data.username,
                    "shipping_address": data.default_shipping_address,
                    "id": data.tw_id,
                    "phone": data.phone_number,
                },
            )
Esempio n. 13
0
def rank_entry(request):
    if auth.isLogin(request):
        user = auth.get_user_data(request)
        if auth.hasProfile(user.uuid):
            try:
                entry = Entry.objects.get(pk = int(request.GET['pk']))

                er, newed = ERanking.objects.get_or_create(entry = entry, users = user)
                old_rank = er.rank
                er.rank = 1 if request.GET['up'] == "True" else -1
                er.save()

                if old_rank == 0:
                    response_data = str(er.rank)
                elif old_rank != er.rank:
                    if old_rank == -1:
                        response_data = "2"
                    else:
                        response_data = "-2"
                else:
                        response_data = "0"

                response = HttpResponse(response_data)
                response.status_code = 200

                return response
            except:
                response = HttpResponse()
                response.status_code = 404

                return response

    response = HttpResponse()
    response.status_code = 403

    return response
Esempio n. 14
0
def rank_comment(request):
    if auth.isLogin(request):
        user = auth.get_user_data(request)
        if auth.hasProfile(user.uuid):
            try:
                comment = Comment.objects.get(pk = int(request.GET['pk']))

                cr, newed = CRanking.objects.get_or_create(comment = comment, users = user)
                old_rank = cr.rank
                cr.rank = 1 if request.GET['up'] == "True" else -1
                cr.save()

                if old_rank == 0:
                    response_data = str(cr.rank)
                elif old_rank != cr.rank:
                    if old_rank == -1:
                        response_data = "2"
                    else:
                        response_data = "-2"
                else:
                        response_data = "0"

                response = HttpResponse(response_data)
                response.status_code = 200

                return response
            except:
                response = HttpResponse()
                response.status_code = 404

                return response

    response = HttpResponse()
    response.status_code = 403

    return response
Esempio n. 15
0
 def test_register_profile(self):
     profile = User_Profiles(username="******", email="*****@*****.**", default_shipping_address="nowhere", phone_number="0000000000", tw_id="A123456789", real_name="DUMMY")
     auth.register_data("6a8f7800-91ba-11e5-af58-0002a5d5c51b", profile)
     self.assertEqual(auth.hasProfile("6a8f7800-91ba-11e5-af58-0002a5d5c51b"), True)