コード例 #1
0
ファイル: views.py プロジェクト: muhammadazani/RiPPLE-Core
def consent(request):
    user = UserService.logged_in_user(request)
    if request.method == 'POST':
        post_request = loads(request.body.decode("utf-8"))
        return JsonResponse(UserService.consent_service(user, post_request))
    else:
        return JsonResponse(UserService.get_user_consent(user))
コード例 #2
0
ファイル: views.py プロジェクト: ruddra/corporate-signup
    def get(self, *args, **kwargs):
        session_cleared = UserService().check_session_cleared(self.request)
        if session_cleared:
            return HttpResponseRedirect('/')
        company_id = UserService().get_from_session(
            self.request,
            SessionStorageConstants.COMPANY_ID
        )
        company = CompanyService().get_company(company_id)
        user = UserService().create_user(
            self.request
        )
        address = ProfileService().create_address(
            self.request
        )
        if user and address:
            profile = ProfileService().create_profile(
                user=user,
                address=address,
                company=company
            )
            if profile:
                UserService().reset_all_session_data(self.request)
                return super().get(*args, **kwargs)

        raise HttpResponseServerError(
            "Internal Server Error. Please contact administrator")
コード例 #3
0
ファイル: views.py プロジェクト: morfat/FalconSeed
    def on_get(self,req,resp,user_id):
        resp.status=falcon.HTTP_200 #this is default
        userService=UserService(db=self.db,url=req.uri,query_params=req.params)

        user=userService.get(user_id)
     
        resp.media=self.reply({"user":user},message="Got it")
コード例 #4
0
ファイル: views.py プロジェクト: muhammadazani/RiPPLE-Core
def update(request):
    if request.method != 'POST':
        return JsonResponse({"error": "Must use POST to this endpoint"},
                            status=405)

    post_request = loads(request.body.decode("utf-8"))
    user = UserService.logged_in_user(request)
    return JsonResponse(UserService.update_course(user, post_request))
コード例 #5
0
ファイル: views.py プロジェクト: morfat/FalconSeed
    def on_get(self,req,resp):
        resp.status=falcon.HTTP_200 #this is default

        userService=UserService(db=self.db,url=req.uri,query_params=req.params)

        users,pagination=userService.all(pagination=True)

        resp.media=self.reply({"users":users},pagination=pagination,message="Well Done")
コード例 #6
0
ファイル: forms.py プロジェクト: ruddra/corporate-signup
 def clean(self):
     cleaned_data = super().clean()
     email = cleaned_data.get('email', None)
     password, re_password = cleaned_data.get('password',
                                              None), cleaned_data.get(
                                                  'retype_password', None)
     try:
         UserService().validate_email(email)
         UserService().validate_password(password, re_password)
     except Exception as ex:
         raise forms.ValidationError(str(ex))
     return cleaned_data
コード例 #7
0
ファイル: views.py プロジェクト: tss89/calendar-sem8-tp
def token(request):
    token = request.GET.get('access_token')
    user_id = request.GET.get('user_id')
    
    try:
        UserService.facebookLogin(token,user_id, request)
        
    except Exception as e:
        print(e)
        pass

    return redirect("home")
コード例 #8
0
ファイル: views.py プロジェクト: ruddra/corporate-signup
 def get(self, request, *args, **kwargs):
     company = UserService().get_from_session(
         self.request,
         SessionStorageConstants.COMPANY_ID
     )
     if not company:
         raise Http404("No Company found")
     data = UserService().get_form_data_in_session(
         request,
         SessionStorageConstants.SECOND_STEP_KEY
     )
     if data:
         self.initial = data
     return super().get(request, *args, **kwargs)
コード例 #9
0
ファイル: views.py プロジェクト: muhammadazani/RiPPLE-Core
def image_update(request):
    if request.method != 'POST':
        return JsonResponse({"error": "Must use POST to this endpoint"},
                            status=405)
    post_request = loads(request.body.decode("utf-8"))
    new_image = post_request.get("image", None)
    if new_image is None:
        return JsonResponse({"error": "Missing image payload"}, status=405)

    course_user = UserService.logged_in_user(request)

    root_path = util.generate_static_path(request.get_host())

    return JsonResponse(
        UserService.update_user_image(course_user.user, root_path, new_image))
コード例 #10
0
ファイル: views.py プロジェクト: ruddra/corporate-signup
 def form_valid(self, form):
     """
     If the form is valid, redirect to the supplied URL.
     """
     UserService().set_form_data_in_session(
         self.request,
         SessionStorageConstants.SECOND_STEP_KEY,
         form.data
     )
     UserService().set_form_data_in_session(
         self.request,
         SessionStorageConstants.SECOND_STEP_CLEANED_DATA_KEY,
         form.cleaned_data
     )
     return HttpResponseRedirect(self.get_success_url())
コード例 #11
0
ファイル: user.py プロジェクト: NimishVerma/BirthdayPostStash
    def validate(self, data):
        username = data.get(User.USERNAME_FIELD).lower()
        password = data.get('password')

        try:
            user = User.objects.get(username=username)
        except:
            raise serializers.ValidationError(
                messages.INVALID_CREDENTIALS_ERROR)
        data['user'] = user
        user_service = UserService()
        is_valid = user_service.verify_account(user, password)
        if not is_valid:
            raise serializers.ValidationError(messages.INACTIVE_ACCOUNT_ERROR)
        return data
コード例 #12
0
ファイル: views.py プロジェクト: muhammadazani/RiPPLE-Core
def rate(request):
    if request.method != 'POST':
        return JsonResponse({
            "error": "Must use POST to this endpoint"
        }, status=405)

    post_request = loads(request.body.decode("utf-8"))
    distractor_id = post_request.get("distractorID", None)

    difficulty = post_request.get("difficulty", None)
    quality = post_request.get("quality", None)

    if difficulty is None and quality is None:
        return JsonResponse({"error": "At least response.rating or response.quality must be specified"}, status=422)

    if difficulty is not None:
        if is_number(difficulty) is False or not 0 <= int(difficulty) <= 5:
            return JsonResponse({"error": "response.difficulty must be between 0 and 5 inclusive"}, status=422)
        difficulty = int(difficulty)

    if quality is not None:
        if is_number(quality) is False or not 0 <= int(quality) <= 5:
            return JsonResponse({"error": "response.quality must be between 0 and 5 inclusive"}, status=422)
        quality = int(quality)

    if distractor_id is None:
        return JsonResponse({"error": "Missing integer distractorID in request"}, status=422)

    user_ratings = {"difficulty": difficulty, "quality": quality}
    if QuestionService.rate_question(distractor_id, user_ratings, UserService.logged_in_user(request)) is False:
        return JsonResponse({"error": "Invalid distractorID"}, status=422)
    else:
        return HttpResponse(status=204)
コード例 #13
0
ファイル: apis.py プロジェクト: joway/Chirp
 def register(self, request):
     """
     注册
     """
     serializer = UserRegistrationSerializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     return UserService.register(email=serializer.data['email'], username=serializer.data['username'])
コード例 #14
0
ファイル: apis.py プロジェクト: joway/Chirp
 def init(self, request):
     """
     初始化密码
     """
     serializer = UserLoginSerializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     return UserService.init(serializer.data['email'], serializer.data['password'])
コード例 #15
0
ファイル: apis.py プロジェクト: joway/Chirp
 def registerpwd(self, request):
     """
     注册
     """
     serializer = UserRegistrationWithPWDSerializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     return UserService.registerpwd(email=serializer.data['email'], password=serializer.data['password'])
コード例 #16
0
ファイル: views.py プロジェクト: muhammadazani/RiPPLE-Core
def next_recommended_question(request):
    logged_in_user = UserService.logged_in_user(request)
    question = QuestionService.next_recommended_question(logged_in_user)
    if question is None:
        return JsonResponse({"error": "You are not enrolled in the course for this question"}, status=403)

    return JsonResponse({"data": question.id})
コード例 #17
0
ファイル: views.py プロジェクト: ruddra/corporate-signup
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context['company_id'] = UserService().get_from_session(
         self.request,
         SessionStorageConstants.COMPANY_ID
     )
     return context
コード例 #18
0
ファイル: views.py プロジェクト: ruddra/corporate-signup
 def get_context_data(self, *args, **kwargs):
     context = super().get_context_data(*args, **kwargs)
     context['form_0_data'] = UserService().get_form_data_in_session(
         self.request,
         SessionStorageConstants.FIRST_STEP_CLEANED_DATA_KEY
     )
     context['form_1_data'] = UserService().get_form_data_in_session(
         self.request,
         SessionStorageConstants.SECOND_STEP_CLEANED_DATA_KEY
     )
     company_id = UserService().get_from_session(
         self.request,
         SessionStorageConstants.COMPANY_ID
     )
     context['company'] = CompanyService().get_company(company_id)
     return context
コード例 #19
0
 def activate(self, request):
     try:
         confirm = request.GET['confirm']
     except MultiValueDictKeyError:
         return Response(data={'message': '400001 格式非法'},
                         status=status.HTTP_400_BAD_REQUEST)
     return UserService.confirm(confirm)
コード例 #20
0
ファイル: views.py プロジェクト: muhammadazani/RiPPLE-Core
def get_reasons(request):
    if request.method != 'POST':
        return JsonResponse({
            "error": "Must use POST to this endpoint"
        }, status=405)

    user = UserService.logged_in_user(request)
    return JsonResponse({"data": QuestionService.get_reason_list(user)})
コード例 #21
0
 def register(self, request):
     """
     注册
     """
     serializer = UserRegistrationSerializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     return UserService.register(email=serializer.data['email'],
                                 username=serializer.data['username'])
コード例 #22
0
 def registerpwd(self, request):
     """
     注册
     """
     serializer = UserRegistrationWithPWDSerializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     return UserService.registerpwd(email=serializer.data['email'],
                                    password=serializer.data['password'])
コード例 #23
0
 def init(self, request):
     """
     初始化密码
     """
     serializer = UserLoginSerializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     return UserService.init(serializer.data['email'],
                             serializer.data['password'])
コード例 #24
0
ファイル: views.py プロジェクト: muhammadazani/RiPPLE-Core
def id(request, id):
    logged_in_user = UserService.logged_in_user(request)
    question = QuestionService.get_question_by_id(logged_in_user, id)

    if question is None:
        return JsonResponse({"error": "You are not enrolled in the course for this question"}, status=403)

    return JsonResponse({"data": question})
コード例 #25
0
ファイル: views.py プロジェクト: muhammadazani/RiPPLE-Core
def all_reports(request):
    user = UserService.logged_in_user(request)

    result = QuestionService.all_reports(user)
    if type(result) != list and result.get("error", None) is not None:
        return JsonResponse(result)
    else:
        return JsonResponse({"data": result})
コード例 #26
0
ファイル: views.py プロジェクト: muhammadazani/RiPPLE-Core
def report(request):
    if request.method != 'POST':
        return JsonResponse({
            "error": "Must use POST to this endpoint"
        }, status=405)

    post_request = loads(request.body.decode("utf-8"))
    user = UserService.logged_in_user(request)
    return JsonResponse({"data": QuestionService.report_question(user, post_request)})
コード例 #27
0
ファイル: views.py プロジェクト: muhammadazani/RiPPLE-Core
def leaderboard(request, sort_field, sort_order):
    logged_in_user = UserService.logged_in_user(request)
    user_roles = (str(x) for x in logged_in_user.roles.all())
    limit = -1 if is_administrator(logged_in_user) else 20

    if sort_order != "DESC" and sort_order != "ASC":
        sort_order = "DESC"

    leaderboard_scores = QuestionService.get_course_leaders(logged_in_user,
        False, sort_field, sort_order, limit)
    return JsonResponse({"data": leaderboard_scores})
コード例 #28
0
ファイル: views.py プロジェクト: muhammadazani/RiPPLE-Core
def add(request):
    v = validate_request(request)
    if not v[0]:
        return v[1]

    root_path, post_request = v

    response = AuthorService.add_question(
        post_request, root_path, UserService.logged_in_user(request))

    return validate_response(response)
コード例 #29
0
ファイル: views.py プロジェクト: muhammadazani/RiPPLE-Core
def update(request, qid):
    val = validate_request(request)
    if not val[0]:
        return val[1]

    root_path, post_request = val

    response = QuestionService.update_question(
        post_request, root_path, UserService.logged_in_user(request), qid)

    return validate_response(response)
コード例 #30
0
ファイル: views.py プロジェクト: muhammadazani/RiPPLE-Core
def get_all_notifications(request):
    user = UserService.logged_in_user(request)

    notifications = Notification.objects.filter(user=user).order_by("-id")
    data = []

    for n in notifications:
        n.sent = True
        data.append(n.toJSON())

    return JsonResponse({"data": data})
コード例 #31
0
ファイル: views.py プロジェクト: ruddra/corporate-signup
    def get(self, request, company_id, *args, **kwargs):
        # Setting Company ID in Session
        # Also overriding to get pre-populated data
        company = CompanyService().get_company(company_id)
        if not company:
            raise Http404("Company does not exist")
        UserService().set_in_session(
            request,
            SessionStorageConstants.COMPANY_ID,
            company.id
        )
        data = UserService().get_form_data_in_session(
            request,
            SessionStorageConstants.FIRST_STEP_KEY
        )
        if data:
            self.initial = data

        self.initial['company_id'] = company_id

        return super().get(request, *args, **kwargs)
コード例 #32
0
def respond(request):
    if request.method != 'POST':
        return JsonResponse({
            "error": "Must use POST to this endpoint"
        }, status=405)

    post_request = loads(request.body)
    distractor_id = post_request.get("distractorID", None)

    if distractor_id is None:
        return JsonResponse({"error": "Missing integer distractorID in request"}, status=422)
    if QuestionService.respond_to_question(distractor_id, UserService.logged_in_user(request)) is None:
        return JsonResponse({"error": "Invalid distractorID"}, status=422)
    else:
        return HttpResponse(status=204)
コード例 #33
0
ファイル: views.py プロジェクト: muhammadazani/RiPPLE-Core
def get_all_user_achievements(request):
    user = UserService.logged_in_user(request)

    achievements = Achievement.objects.all()
    data = []
    for ach in achievements:
        result = engine.check_achievement(user=user, key=ach.key)
        data.append(result)
        if result["new"]:
            n = Notification(name=result["name"] + " Earned",
                             description=result["description"],
                             icon=result["icon"],
                             user=user)
            n.save()

    return JsonResponse({"data": data})
コード例 #34
0
ファイル: apis.py プロジェクト: joway/Chirp
 def activate(self, request):
     try:
         confirm = request.GET['confirm']
     except MultiValueDictKeyError:
         return Response(data={'message': '400001 格式非法'}, status=status.HTTP_400_BAD_REQUEST)
     return UserService.confirm(confirm)