def registration_view(request): if request.method=="POST": serializer=RegistrationSerializer(data=request.data) data={} if serializer.is_valid(): account=serializer.save() user=Account.objects.get(email=account.email) token=RefreshToken.for_user(user) current_site=get_current_site(request).domain relativeLink=reverse('email-verify') absurl = 'http://'+current_site+relativeLink+"?token="+str(token) email_body = 'Hi '+user.username + \ ' Use the link below to verify your email \n' + absurl email_data = {'email_body': email_body, 'to_email': user.email, 'email_subject': 'Verify your email'} send_email(email_data) data['response']=int(200) data['email']=account.email data['username']=account.username else: data=serializer.errors return Response(data)
class CourseSerializer(serializers.ModelSerializer): owner = RegistrationSerializer(many=False, read_only=True, required=False) category = CategorySerializer(many=False, read_only=True) students = RegistrationSerializer(many=True, read_only=True) class Meta: model = Course fields = '__all__' def create(self, *args, **kwargs): owner = Account.objects.get( id=self.context['request'].data['owner'].id) category = Category.objects.get( id=self.context['request'].data['category']) course = Course.objects.create( title=self.validated_data['title'], description=self.validated_data['description'], cover=self.validated_data['cover'], price=self.validated_data['price'], rate=self.validated_data['rate'], numReviewers=self.validated_data['numReviewers'], owner=owner, category=category, ) course.save() return course
def api_registration_view(request): logger = logging.getLogger(__name__) data = {} email = request.data.get('email').lower() role = request.data.get('role') if validate_email(email) is not None: data['error_message'] = 'That email is already in use.' data['response'] = 'Error' return Response(data) instaAccount = request.data.get('instaAccount') if validate_instaacount( instaAccount ) is not None: # TODO: Hay que corregir la funcion validate_instaacount() data['error_message'] = 'That instagram account is already in use.' data['response'] = 'Error' return Response(data) serializer = RegistrationSerializer(data=request.data) if request.data.get('password') != request.data.get('password2'): data['error_message'] = 'Passwords must match' data['response'] = 'Error' return Response(data) if serializer.is_valid(): user = serializer.save() if (role == '2'): company = Company(user=user, instaAccount=request.data.get('instaAccount'), phone=request.data.get('phone')) company.save() elif (role == '1'): if (request.data.get('phone') is None): profile = Profile( user=user, instaAccount=request.data.get('instaAccount')) profile.save() else: profile = Profile( user=user, instaAccount=request.data.get('instaAccount'), phone=request.data.get('phone')).save() data['response'] = 'user registered successfuly' data['email'] = user.email data['full_name'] = user.full_name data['active'] = user.active data['staff'] = user.staff data['admin'] = user.admin data['instaAccount'] = instaAccount data['phone'] = request.data.get('phone') data['role'] = role data['timestamp'] = user.timestamp token = Token.objects.get(user=user).key data['token'] = token logger.error(data) else: data = serializer.errors return Response(data) return Response(data, status=status.HTTP_201_CREATED)
def resgistration_view(request): if request.method == 'POST': serializer = RegistrationSerializer(data=request.data) data = {} if serializer.is_valid(): account = serializer.save() data['response'] = 'SuccessFully registers a new user.' data['email'] = account.email data['username'] = account.username else: data = serializer.errors return Response(data)
def registration_view(request): serializer = RegistrationSerializer(data=request.data) data = {} if serializer.is_valid(): account = serializer.save() data['response'] = 'successfully registered new user.' data['email'] = account.email data['username'] = account.username data['token'] = Token.objects.get(user=account).key else: data = serializer.errors return Response(data)
def post(self, request, format=None): serializer = RegistrationSerializer(data=request.data) if serializer.is_valid(): user = serializer.save() if user: user.set_password(request.data.get("password")) token = Token.objects.create(user=user) user.save() json = serializer.data json['token'] = token.key return Response(json, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def registration_view(request): serializer = RegistrationSerializer(data=request.data) data = {} if serializer.is_valid(): account = serializer.save() data['response'] = 'Account Registered.' data['email'] = account.email data['username'] = account.username token = Token.objects.get(user=account).key data['token'] = token return Response(data, status=status.HTTP_200_OK) data = serializer.errors return Response(data)
def registration_view(request): if request.method == 'POST': serializer = RegistrationSerializer(data=request.data) data = {} if serializer.is_valid(): user = serializer.save() data['response'] = "New user successfully registered" data['email'] = user.email data['username'] = user.username token = Token.objects.get(user=user).key data['token'] = token return Response(data, status=status.HTTP_201_CREATED) else: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def post(self, request): if request.method == 'POST': serializer = RegistrationSerializer(data=request.data) data = {} if serializer.is_valid(): account = serializer.save() data['response'] = 'Sucessfully registred a new user' data['id'] = account.id data['email'] = account.email data['username'] = account.username status_code = status.HTTP_201_CREATED else: data = serializer.errors status_code = status.HTTP_400_BAD_REQUEST return Response(data, status_code)
def registration_view(request): serializer = RegistrationSerializer(data=request.data) data = {} if serializer.is_valid(): account = serializer.save() data['response'] = "successfully registered a new user." data['id'] = account.id data['first_name'] = account.first_name data['last_name'] = account.last_name data['email'] = account.email token = Token.objects.get(user=account).key data['token'] = token else: data = serializer.errors return Response(data)
def api_registration_view(request): if request.method == "POST": serializer = RegistrationSerializer(data=request.data) data = {} if serializer.is_valid(): account = serializer.save() data['response'] = "Sucessfully Registered a new User ." data['email'] = account.email data['name'] = account.name data['contact'] = account.contact token = Token.objects.get(user=account).key data['token'] = token else: data = serializer.errors return Response(data)
def registration_view(request): serializer = RegistrationSerializer(data=request.data) if request.method == 'POST': data = {} if serializer.is_valid(): account = serializer.save() data['response'] = 'Successfully registrated a new user.' data['email'] = account.email data['username'] = account.username data['purchased_courses'] = [] data['course_made_by_me'] = [] token = Token.objects.get(user=account).key data['token'] = token else: data = serializer.errors return Response(data) return Response(serializer.data)
def registration_view(request): if request.method == 'POST': data = {} # Validate Email (Password Validation in serializers.py) email = request.data.get('email', '0') if validate_email(email) != None: data['response'] = 'Error' data['error_message'] = 'That email is already in use.' return Response(data) serializer = RegistrationSerializer(data=request.data) if serializer.is_valid(): user = serializer.save() data['response'] = 'Successfully Registered!' data['email'] = user.email # Send Account Activation Email current_site = get_current_site(request) from_email = settings.DEFAULT_FROM_EMAIL to = [user.email] subject = 'Jagrati Acount Activation' html_message = render_to_string( 'accounts/email/account_activation_email.html', { 'user': user, 'domain': current_site.domain, 'uid': urlsafe_base64_encode(force_bytes(user.pk)), 'token': account_activation_token.make_token(user), }) plain_message = strip_tags(html_message) send_mail( subject, plain_message, from_email, to, fail_silently=False, html_message=html_message, ) else: data = serializer.errors return Response(data)
def registration_view(request): if request.method == 'POST': data = {} email = request.data.get('email', '0').lower() if validate_email(email) is not None: data['error_message'] = 'That email is already in use.' data['response'] = 'Error' return Response(data) serializer = RegistrationSerializer(data=request.data) if serializer.is_valid(): account = serializer.save() data['response'] = 'successfully registered new user.' data['email'] = account.email # data['first_name'] = account.first_name # data['last_name'] = account.last_name data['pk'] = account.pk token = Token.objects.get(user=account).key data['token'] = token else: data = serializer.errors return Response(data)
class ReviewerSerializer(serializers.ModelSerializer): owner = RegistrationSerializer(many=False, read_only=True, required=False) comment_on = CourseSerializer(many=False, read_only=True, required=False) # rate = RaterSerializer(many=False, read_only=True, required=False) class Meta: model = Reviewer fields = '__all__' def create(self, *args, **kwargs): owner = Account.objects.get(id=self.context['request'].user.id) comment_on = Course.objects.get( id=self.context['request'].data['comment_on']) reviewer = Reviewer(owner=owner, comment=self.validated_data['comment'], comment_on=comment_on, stars=self.validated_data['stars']) reviewer.save() return reviewer
def registration_view(request): if request.method == 'POST': serializer = RegistrationSerializer(data=request.data) data = {} if serializer.is_valid(): account = serializer.save() data['response'] = "New user successfully registered." data['email'] = account.email data['username'] = account.username data['first_name'] = account.first_name data['last_name'] = account.last_name token = Token.objects.get(user=account).key data['token'] = token else: data = serializer.errors return Response(data) # @api_view(['GET', ]) # def api_detail_coach_view(request, slug): # try: # coach_profile = Coach.objects.get(slug=slug) # except Coach.DoesNotExist: # return Response(status=status.HTTP_404_NOT_FOUND) # if request.method == "GET": # serializer = CoachSerializer(coach_profile) # return Response(serializer.data) # @api_view(['PUT', ]) # def api_update_coach_view(request, slug): # try: # coach_profile = Coach.objects.get(slug=slug) # except Coach.DoesNotExist: # return Response(status=status.HTTP_404_NOT_FOUND) # if request.method == "PUT": # serializer = CoachSerializer(coach_profile) # data = {} # if serializer.is_valid(): # serializer.save() # data["Success"] = "Coach profile successfully updated." # return Response(data=data) # return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) # @api_view(['DELETE', ]) # def api_delete_coach_view(request, slug): # try: # coach_profile = Coach.objects.get(slug=slug) # except Coach.DoesNotExist: # return Response(status=status.HTTP_404_NOT_FOUND) # if request.method == "DELETE": # operation = coach_profile.DELETE() # data = {} # if operation == True: # data["Success"] = "Successfully deleted specified coach." # else: # data["Failure"] = "Unable to delete specified coach." # return Response(data=data) # class ApiCoachListView(ListAPIView): # queryset = Coach.objects.all() # #print("This is the queryset:", queryset) # serializer_class = CoachSerializer # # authentication_classes = (TokenAuthentication,) # # permission_classes = (IsAuthenticated,) # pagination_class = PageNumberPagination # filter_backends = (SearchFilter, OrderingFilter,) # search_fields = ('last_name',)