Beispiel #1
0
def hk_register(request):
    username = request.POST.get('username', '')
    password = request.POST.get('password', '')
    email = request.POST.get('email', '')
    if User.objects.filter(email=email).exists():
        return HttpResponseBadRequest(
            reason='A user exists for this email address.')

    if User.objects.filter(username=username).exists():
        return HttpResponseBadRequest(reason='Sorry, this username is taken.')

    try:
        User.objects.create_user(username, email, password)
        user = authenticate(username=username, password=password)
        account = Account(user=user, email=email)
        account.save()
    except Exception as e:
        print str(e)
        return HttpResponseServerError(reason=str(e))

    try:
        user.is_active = False
        user.save()
        login(request, user)
        return HttpResponse()
    except Exception as e:
        print str(e)
        return HttpResponseServerError(reason=str(e))
Beispiel #2
0
def cw_register(request):
	username = request.POST.get('username', '')
	password = request.POST.get('password', '')
	email = request.POST.get('email', '')
	first_name = request.POST.get('first_name', '')
	last_name = request.POST.get('last_name', '')
	zip_code = request.POST.get('zip_code', '')
	if User.objects.filter(email=email).exists():
		return HttpResponseBadRequest(reason='An account exists for this email address.')

	if User.objects.filter(username=username).exists():
		return HttpResponseBadRequest(reason='Sorry, this username is taken.')

	try:
		User.objects.create_user(username, email, password)
		user = authenticate(username=username, password=password)
		account = Account(user=user, email=email, first_name=first_name, last_name=last_name, zip_code=zip_code)
		account.save()
	except Exception as e:
		print str(e)
		return HttpResponseServerError(reason=str(e))

	try:
		user.is_active = False
		user.save()
		login(request, user)
		print "Should be good at this point?"
		return HttpResponse()
	except Exception as e:
		print str(e)
		return HttpResponseServerError(reason=str(e))
Beispiel #3
0
def cw_register(request):
    form = AccountRegistrationForm(request.POST or None)
    if request.method == 'POST':
        # Form Validation
        if form.is_valid():
            username = form.clean_username()
            password = form.clean_password()
            email = form.clean_email()

            # Create a New Account
            try:
                User.objects.create_user(username, email, password)
                user = authenticate(username=username, password=password)

                account = Account(user=user)
                if not settings.CLOSED_BETA:
                    account.beta_access = True
                account.save()

                user.is_active = True
                user.save()

                uid = urlsafe_base64_encode(force_bytes(user.pk))
                token = account_activation_token.make_token(user)
                domain = get_current_site(request).domain
                base_url = "http://{domain}/auth/activate_account/{uid}/{token}/"
                url_with_code = base_url.format(domain=domain,
                                                uid=uid,
                                                token=token)
                # Send Email Verification Message
                # TODO: Move this to string templates
                email_context = {
                    'title':
                    'Verify your email with CiviWiki',
                    'body':
                    ("Welcome to CiviWiki! Follow the link below to verify your email with us. "
                     "We're happy to have you on board :)"),
                    'link':
                    url_with_code
                }

                send_email.delay(subject="CiviWiki Account Setup",
                                 recipient_list=[email],
                                 context=email_context)

                login(request, user)
                return HttpResponse()

            except Exception as e:
                return HttpResponseServerError(reason=str(e))

        else:
            response = {
                'success': False,
                'errors': [error[0] for error in form.errors.values()]
            }
            return JsonResponse(response, status=400)
    else:
        return HttpResponseBadRequest(reason="POST Method Required")
def cw_register(request):
    form = AccountRegistrationForm(request.POST or None)
    if request.method == 'POST':
        # Form Validation
        if form.is_valid():
            username = form.clean_username()
            password = form.clean_password()
            email = form.clean_email()

            # Create a New Account
            try:
                User.objects.create_user(username, email, password)
                user = authenticate(username=username, password=password)

                account = Account(user=user)
                if not settings.CLOSED_BETA:
                    account.beta_access = True
                account.save()

                user.is_active = True
                user.save()

                uid = urlsafe_base64_encode(force_bytes(user.pk))
                token = account_activation_token.make_token(user)
                domain = get_current_site(request).domain
                base_url = "http://{domain}/auth/activate_account/{uid}/{token}/"
                url_with_code = base_url.format(domain=domain, uid=uid, token=token)
                # Send Email Verification Message
                # TODO: Move this to string templates
                email_context = {
                    'title' : 'Verify your email with CiviWiki',
                    'body' : "Welcome to CiviWiki! Follow the link below to verify your email with us. We're happy to have you on board :)",
                    'link': url_with_code
                }

                send_email.delay(
                    subject="CiviWiki Account Setup",
                    recipient_list=[email],
                    context=email_context
                )

                login(request, user)
                return HttpResponse()

            except Exception as e:
                return HttpResponseServerError(reason=str(e))

        else:
            response = {
                'success': False,
                'errors' : [error[0] for error in form.errors.values()]
            }
            return JsonResponse(response, status=400)
    else:
        return HttpResponseBadRequest(reason="POST Method Required")
Beispiel #5
0
    def post(self, request):
        try:
            data = json.loads(request.body)
            account = Account(**data)
            account.save()

            return HttpResponse(status=201,
                                content=json.dumps({'id': account.id}),
                                content_type='application/json')
        except:
            rollbar.report_exc_info()
Beispiel #6
0
    def save(self):
        user = Account(email=self.validated_data['email'],
                       first_name=self.validated_data['first_name'],
                       last_name=self.validated_data['last_name'],
                       username=self.validated_data['username'],
                       address=self.validated_data['address'],
                       city=self.validated_data['city'],
                       zip_code=self.validated_data['zip_code'],
                       country=self.validated_data['country'])

        password = self.validated_data['password']
        password2 = self.validated_data['password2']

        if password != password2:
            raise serializers.ValidationError(
                {'password': '******'})
        user.set_password(password)
        user.save()
        Token.objects.get_or_create(user=user)
        return user
def beta_register(request):
    """ Special registration request for beta access """
    # Beta Check
    beta_token = request.POST.get('beta_token', '')
    if beta_token:
        email = request.POST.get('email' '')
        try:
            invitation = Invitation.objects.get(invitee_email=email)
        except Invitation.DoesNotExist:
            response_data = {
                "message": "Beta invitation does not exist for this email",
                "error": "NO_BETA_INVITE"
            }
            return JsonResponse(response_data, status=400)

        if invitation.verification_code != beta_token:
            response_data = {
                "message": "The beta token is not valid",
                "error": "INVALID_BETA_TOKEN"
            }
            return JsonResponse(response_data, status=400)

    else:
        response_data = {
            "message": "Missing Beta Token",
            "error": "MISSING_BETA_TOKEN"
        }
        return JsonResponse(response_data, status=400)

    form = AccountRegistrationForm(request.POST or None)
    if request.method == 'POST':
        # Form Validation
        if form.is_valid():
            username = form.clean_username()
            password = form.clean_password()
            email = form.clean_email()

            # Create a New Account
            try:
                User.objects.create_user(username, email, password)
                user = authenticate(username=username, password=password)
                account = Account(user=user)
                account.beta_access = True
                account.is_verfied = True
                account.save()

                invitation = Invitation.objects.get(invitee_email=email)
                invitation.invitee_user = user
                invitation.save()

                user.is_active = True
                user.save()

                login(request, user)
                return HttpResponse()

            except Exception as e:
                return HttpResponseServerError(reason=str(e))

        else:
            response = {
                'success': False,
                'errors': [error[0] for error in form.errors.values()]
            }
            return JsonResponse(response, status=400)
    else:
        return HttpResponseBadRequest(reason="POST Method Required")
Beispiel #8
0
 def make_account(**kwargs):
     user = User.objects.get(username=kwargs['username'])
     if 'username' in kwargs:
         kwargs.pop('username')
     acc = Account(user=user, **kwargs)
     acc.save()
Beispiel #9
0
def beta_register(request):
    """ Special registration request for beta access """
    # Beta Check
    beta_token = request.POST.get('beta_token', '')
    if beta_token:
        email = request.POST.get('email' '')
        try:
            invitation = Invitation.objects.get(invitee_email=email)
        except Invitation.DoesNotExist:
            response_data = {
                "message": "Beta invitation does not exist for this email",
                "error":"NO_BETA_INVITE"
            }
            return JsonResponse(response_data, status=400)

        if invitation.verification_code != beta_token:
            response_data = {
                "message": "The beta token is not valid",
                "error":"INVALID_BETA_TOKEN"
            }
            return JsonResponse(response_data, status=400)

    else:
        response_data = {
            "message": "Missing Beta Token",
            "error":"MISSING_BETA_TOKEN"
        }
        return JsonResponse(response_data, status=400)


    form = AccountRegistrationForm(request.POST or None)
    if request.method == 'POST':
        # Form Validation
        if form.is_valid():
            username = form.clean_username()
            password = form.clean_password()
            email = form.clean_email()

            # Create a New Account
            try:
                User.objects.create_user(username, email, password)
                user = authenticate(username=username, password=password)
                account = Account(user=user)
                account.beta_access = True
                account.is_verfied = True
                account.save()

                invitation = Invitation.objects.get(invitee_email=email)
                invitation.invitee_user = user
                invitation.save()

                user.is_active = True
                user.save()

                login(request, user)
                return HttpResponse()

            except Exception as e:
                return HttpResponseServerError(reason=str(e))

        else:
            response = {
                'success': False,
                'errors' : [error[0] for error in form.errors.values()]
            }
            return JsonResponse(response, status=400)
    else:
        return HttpResponseBadRequest(reason="POST Method Required")