예제 #1
0
def registration(request):
    """Render the registration page"""
    if request.user.is_authenticated:
        return redirect(reverse('index'))
         
    if request.method =="POST":
        registration_form = UserRegistrationForm(request.POST)
        
        if registration_form.is_valid():
            registration_form.save()
            
            user = auth.authenticate(username=request.POST['username'], 
                                        password=request.POST['password1'])
            
            if user:
                auth.login(user=user, request=request)
                messages.success(request, "You have successfully registered")
                return redirect(reverse('index'))
            else:
                messages.error(request, "Unable to register your account at this time")
    
    else:
        registration_form = UserRegistrationForm()
            
    
    return render(request, 'registration.html', 
        {"registration_form": registration_form})
예제 #2
0
def register(request):
    if request.method == "POST":
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            try:
                customer = stripe.Customer.create(
                    email=form.cleaned_data["email"], card=form.cleaned_data["stripe_id"], plan="REG_MONTHLY"
                )
            except stripe.error.CardError, e:
                messages.error(request, "Your card was declined!")

            if customer:
                user = form.save()
                user.stripe_id = customer.id
                user.subscription_end = arrow.now().replace(weeks=+4).datetime
                user.save()

                user = auth.authenticate(email=request.POST.get("email"), password=request.POST.get("password1"))

                if user:
                    auth.login(request, user)
                    messages.success(request, "You have successfully registered")
                    return redirect(reverse("profile"))

                else:
                    messages.error(request, "We were unable to log you in at this time")
            else:
                messages.error(request, "We were unable to take payment from the card provided")
예제 #3
0
파일: views.py 프로젝트: Cvd2014/user-auth
def register(request):
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            try:
                customer = stripe.Customer.create(
                    email=form.cleaned_data['email'],
                    card=form.cleaned_data['stripe_id'],
                    plan="Sub1"
                )
            except stripe.error.CardError, e:
                messages.error(e._message)
                # messages.error(request, "Your card was declined!")

            if customer:
                user = form.save()
                user.stripe_id = customer.id
                user.subscription_end = arrow.now().replace(weeks=+4).datetime
                user.save()

                user = auth.authenticate(email=request.POST.get('email'),
                                         password=request.POST.get('password1'))

                if user:
                    messages.success(request, "You have successfully registered")
                    return redirect(reverse('profile'))

                else:
                    messages.error(request, "unable to log you in at this time!")

            else:
                messages.error(request, "We were unable to take a payment with that card!")
def register(request):
    """
    Gets a new users email and password and creates an account.
    """
    context = {}
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            try:
                # create a charge customer object for one off payments.
                # customer = stripe.Charge.create(
                #     amount=999,
                #     currency="USD",
                #     description=form.cleaned_data['email'],
                #     card=form.cleaned_data['stripe_id'],
                # )

                # create a customer object within Stripe using the email and
                # Stripe token/id for a re-occurring subscription.
                customer = stripe.Customer.create(
                    email=form.cleaned_data['email'],
                    card=form.cleaned_data['stripe_id'],  # this is currently the card token/id
                    plan='REG_MONTHLY2',  # name of plan. See 'Plans' in Stripe website.
                )
            except stripe.error.CardError, e:
                messages.error(request, "Your card was declined!")
            else:
                # charge() method above returns a customer object that contains a 'paid' boolean field.
                # If customer.paid:
                # form.save()

                if customer:
                    user = form.save()

                    # Used in updating/cancelling the subscription
                    user.stripe_id = customer.id  # This will be a string of the form ‘cus_XXXXXXXXXXXXXX’)

                    # Arrow is a fast way of dealing with dates and times in Python.
                    # Create a date that is exactly 4 weeks from now and convert it
                    # into a datetime object which is compatible with our DateTimeField
                    # in the User model.
                    user.subscription_end = arrow.now().replace(weeks=+4).datetime

                    user.save()

                    # request.POST.get() - gets specific data
                    user = auth.authenticate(email=request.POST.get('email'),
                                             password=request.POST.get('password1'))

                    if user:
                        auth.login(request, user)  # login customer/user in.
                        messages.success(request, "You have successfully registered.")
                        # reverse refers to the 'name' given to a route in urls.py
                        return redirect(reverse('profile'))

                    else:
                        messages.error(request, "unable to log you in at this time!")

                else:
                    messages.error(request, "We were unable to take payment from the card provided.")
예제 #5
0
def register(request):
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            try:
                customer = stripe.Customer.create(
                    email=form.cleaned_data['email'],
                    card=form.cleaned_data['stripe_id'], # this is currently the card token/id#
                    plan='REG_MONTHLY')

            except stripe.error.CardError, e:
                messages.error(request, "Your card was declined!")
            if customer:
                user = form.save()
                user.stripe_id = customer.stripe_id
                user.subscription_end = arrow.now().replace(weeks=+4).datetime
                user.save()
                user = auth.authenticate(email=request.POST.get('email'), password=request.POST.get('password1'))

                if user:
                    auth.login(request, user)
                    messages.success(request, "You have successfully registered")
                    return redirect(reverse('profile'))
                else:
                    messages.error(request, "unable to log you in at this time!")
            else:
                messages.error(request, "unable to log you in at this time!")
def register(request):
    """
    Handles the new user's email and password to create their account.
    :param request:
    :return:
    """
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            form.save()

            user = auth.authenticate(email=request.POST.get('email'),
                                     password=request.POST.get('password1'))

            if user:
                messages.success(request, "You have successfully registered")
                return redirect(reverse('profile'))

            else:
                messages.error(request, "unable to log you in at this time!")

    else:
        form = UserRegistrationForm()

    args = {'form': form}
    args.update(csrf(request))

    return render(request, 'register.html', args)
예제 #7
0
def register(request):
    #if we have a post to the url then populate the registration form with the request.POST information
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():

            try:
                #send web services call to stripe - makes association with credit card and customer
                customer = stripe.Charge.create(
                    amount = 499,
                    currency = "EUR",
                    description = form.cleaned_data['email'],
                    card = form.cleaned_data['stripe_id'],
                )
               # print "IM THE CUSTOMER", json.dumps(customer)

            except stripe.error.CardError, e:
                messages.error(request, "Your (valid) card was declined!")

            if customer.paid:
                form.save()
                user = auth.authenticate(email=request.POST.get('email'),
                                         password = request.POST.get('password1'))

                if user:
                    auth.login(request,user)

                    messages.success(request, "You have successfully registered. Your customer id number is")
                    return redirect(reverse('profile'))
                else:
                    messages.error(request,'Unable to log you in at this time!')
            else:
                messages.error(request, "We were unable to take a payment with that card!")
예제 #8
0
def register(request):
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            form.save()

            user = auth.authenticate(username=request.POST.get('username'), password=request.POST.get('password1'))

            if user:
                messages.success(request, "you have successfully registered, big woop.")
                auth.login(request, user)
                print ("hihihhihihih")
                return redirect(reverse('index'))
            else:
                print ("hi")
                messages.error(request, "unable to log you in at this time!")


    else:
        form = UserRegistrationForm()
        print ("hi-hooooo")
    args = {'form': form}
    args.update(csrf(request))

    return render(request, 'register.html', args)
예제 #9
0
파일: views.py 프로젝트: Mrbrianojee/stripe
def register(request):
    if request.method == "POST":
        form = UserRegistrationForm(request.POST)
        if form.is_valid():

            try:
                customer = stripe.Charge.create(
                    amount=499,
                    currency="USD",
                    description=form.cleaned_data["email"],
                    card=form.cleaned_data["stripe_id"],
                )
            except stripe.error.CardError, e:
                messages.error(request, "Your card was declined!")

            if customer.paid:
                form.save()

                user = auth.authenticate(email=request.POST.get("email"), password=request.POST.get("password1"))

                if user:
                    auth.login(request, user)
                    messages.success(request, "You have successfully registered")
                    return redirect(reverse("profile"))

                else:
                    messages.error(request, "unable to log you in at this time!")
            else:
                messages.error(request, "We wer unable to take a payment with that card!")
예제 #10
0
def register(request):
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            try:
                customer = stripe.Charge.create(
                    amount=499,
                    currency='EUR',
                    description=form.cleaned_data['email'],
                    card=form.cleaned_data['stripe_id'],
                )
            except stripe.error.CardError, e:
                messages.error(request, 'Your card was declined')

            if customer.paid:
                console.log(customer)

                form.save()

                user = auth.authenticate(email=request.POST.get('email'), password=request.POST.get('password1'))

                if user:
                    auth.login(request, user)
                    messages.success(request, 'You have successfully registered')
                    return redirect(reverse('profile'))

                else:
                    messages.error(request, 'Unable to log you in at this time ')
            else:
                messages.error(request, 'Unable to take payment with that card')
예제 #11
0
def register(request):
    data = wrap_data_accounts(request)
    data.update(csrf(request))
    success = False
    if request.method == 'POST':
        reg_form = UserRegistrationForm(request.POST)
        if reg_form.is_valid():
            domain = request.get_host()
            new_user = reg_form.save(domain)
            #username = user.username
            #password = reg_form.cleaned_data.get('password1') # user.password is a hashed value
            #auth_user = authenticate(username=username, password=password)
            #login(request, auth_user)
            success = True
        else:
            for error in reg_form.non_field_errors():
                data['errors'].append(error)
    else:
        reg_form = UserRegistrationForm()
    data['reg_form'] = reg_form
    destination = None
    if success:
        destination = redirect(reverse('account_register_done'))
    else:
        destination = _r('account/register.html', data)
    return destination
예제 #12
0
def register(request):
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            try:
                customer = stripe.Customer.create(
                        email=form.cleaned_data['email'],
                        card=form.cleaned_data['stripe_id'],  # this is currently the card token/id
                        plan='REG_MONTHLY',
                )

                if customer:
                    user = form.save()  # save here to create the user and get its instance

                    # now we replace the card id with the actual user id for later
                    user.stripe_id = customer.id
                    user.subscription_end = arrow.now().replace(weeks=+4).datetime  # add 4 weeks from now
                    user.save()

                # check we saved correctly and can login
                user = auth.authenticate(email=request.POST.get('email'),
                                         password=request.POST.get('password1'))

                if user:
                    auth.login(request, user)
                    messages.success(request, "You have successfully registered")
                    return redirect(reverse('profile'))

                else:
                    messages.error(request, "unable to log you in at this time!")

            except stripe.error.CardError, e:
                form.add_error(request, "Your card was declined!")
예제 #13
0
def register(request):
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST, request.FILES)
        if form.is_valid():
            try:
                customer = stripe.Customer.create(
                    email=form.cleaned_data['email'],
                    card=form.cleaned_data['stripe_id'],
                    plan='REG_MONTHLY',
                )
            except stripe.error.CardError, e:
                messages.error(request, "Your card was declined!")

            if customer:
                user = form.save()
                user.stripe_id = customer.id
                user.subscription_end = arrow.now().replace(weeks=+4).datetime
                user.save()

                user = auth.authenticate(email=request.POST.get('email'), password=request.POST.get('password1'))

                if 'user_profile_picture' in request.FILES:
                    profile.user_profile_picture = request.FILES['user_profile_picture']

                if user:
                    auth.login(request, user)
                    messages.success(request, "You have successfully registered")
                    return redirect(reverse('profile'))

                else:
                    messages.error(request, "We were unable to log you in at this time")
            else:
                messages.error(request, "We were unable to take payment from the card provided")
예제 #14
0
파일: views.py 프로젝트: amcevoy83/musichub
def register(request):
    #if we have a post to the url then populate the registration form with the request.POST information
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():

            try:
                customer = stripe.Customer.create(
                    email = form.cleaned_data['email'],
                    card = form.cleaned_data['stripe_id'],
                    plan = 'REG_MONTHLY',
                )

            except stripe.error.CardError, e:
                messages.error(request, "Your (valid) card was declined!")

            if customer:
                user = form.save()
                user.stripe_id = customer.id
                user.subscription_end = arrow.now().replace(weeks=+4).datetime
                user.save()

                user = auth.authenticate(email=request.POST.get('email'),
                                        password = request.POST.get('password1'))
                if user:
                    auth.login(request,user)

                    messages.success(request, "You have successfully registered. Your customer id number is")
                    return redirect(reverse('profile'))
            else:
                messages.error(request,'Unable to log you in at this time!')
        else:
            messages.error(request, "We were unable to take a payment with that card!")
예제 #15
0
    def test_registration_form(self):
        form = UserRegistrationForm({
            'password1': 'letmein',
            'password2': 'letmein'
        })

        self.assertTrue(form.is_valid())
        self.assertRaisesMessage(form.ValidationError, "This field is required.", form.clean)
예제 #16
0
파일: views.py 프로젝트: jairajdesai/Schule
def register(request):
  if request.method =='POST':
    form = UserRegistrationForm(request.POST)
    if form.is_valid():
      #user = User.objects.create_user(form.cleaned_data['username'], None, form.cleaned_data['password1'])
      #user.save()
      form.save()
      return redirect(settings.USER_HOME) # Redirect after POST
  else:
    form = UserRegistrationForm() # An unbound form

  return render_to_response('accounts/register.html', {
    'form': form,
},context_instance=RequestContext(request))
예제 #17
0
파일: views.py 프로젝트: RohitRepo/Schule
def register(request):
  if request.method =='POST':
    form = UserRegistrationForm(request.POST,user=request.user.id)
    if form.is_valid():
      #user = User.objects.create_user(form.cleaned_data['username'], None, form.cleaned_data['password1'])
      #user.save()
      form.save()
      #TODO- On adding new user, add it to the institute-wide group, ensure update is generated corresponding to user addition.
      return redirect(settings.USER_HOME) # Redirect after POST
  else:
    form = UserRegistrationForm() # An unbound form

  return render_to_response('accounts/register.html', {
    'form': form,
},context_instance=RequestContext(request))
예제 #18
0
파일: views.py 프로젝트: stekerr/social
def register(request):
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():

            try:
                customer = stripe.Customer.create(
                    email=form.cleaned_data['email'],
                    card=form.cleaned_data['stripe_id'],
                    plan='REG_MONTHLY',
                )

                # our initial code for a single payment**
                '''customer = stripe.Charge.create(
                    amount=499,
                    currency='USD',
                    description=form.cleaned_data['email'],
                    card=form.cleaned_data['stripe_id'],
                )'''
                # our initial code for a single payment

            except stripe.error.CardError, e:
                messages.error(request, "Your card was declined!")
            # initial code
            '''if customer.paid:
                form.save()

                user = auth.authenticate(email=request.POST.get('email'),
                                         password=request.POST.get('password1'))'''
            # initial code
            if customer:
                user = form.save()
                user.stripe_id = customer.id
                user.subscription_end = arrow.now().replace(weeks=+4).datetime
                user.save()

                user = auth.authenticate(email=request.POST.get('email'),
                                         password=request.POST.get('password1'))

                if user:
                    auth.login(request, user)
                    messages.success(request, "Thank you, your card was authorised. You have successfully registered!")
                    return redirect(reverse('profile'))

                else:
                    messages.error(request, "unable to log you in at this time!")
            else:
                messages.error(request, "We were unable to take a payment with that card!")
def register(request):
    if(request.method == 'POST'):
        form = UserRegistrationForm(request.POST, request.FILES)
        if(form.is_valid()):
            user, created = User.objects.get_or_create(username = form.cleaned_data['username'], email = form.cleaned_data['email'])
            if(not created):
                return HttpResponseBadRequest("An accound with this username or email already exists.")
            else:
                user.set_password(form.cleaned_data['password'])
                avatar = Avatar(user = user, avatar_image = form.cleaned_data['avatar'])
                user.save()
                avatar.save()
                return HttpResponse()
        else:
            return HttpResponseBadRequest("There was something wrong with the information you inputed. Please try again.") 
    else:
        return HttpResponseBadRequest("This endpoint does not support any method other than POST.")
예제 #20
0
def register(request):
    log.info("Handling register %s request", request.method)
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():

            try:

                customer = stripe.Customer.create(
                    card=form.cleaned_data['stripe_id'],
                    description=form.cleaned_data['email'],
                    email=form.cleaned_data['email'],
                    plan='REG_MONTHLY'
                )

                log.info("customer %s", customer)

            except stripe.error.CardError:
                messages.error(request, "Your card was declined")

            if customer:
                user = form.save()
                user.stripe_id = customer.stripe_id
                user.subscription_end = arrow.now().replace(weeks=+4).datetime
                user.save()

                user = auth.authenticate(email=request.POST.get('email'), password=request.POST.get('password1'))

                if user:

                    messages.success(request, "You have successfully registered")
                    return redirect(reverse('profile'))

                else:
                    messages.error(request, "unable to log you in at this time!")
            else:
                messages.error(request, "We were unable to take payment with that card")

    else:
        form = UserRegistrationForm()

    args = {'form': form, 'publishable': settings.STRIPE_PUBLISHABLE}
    args.update(csrf(request))

    return render(request, 'register.html', args)
예제 #21
0
def register(request):
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        print form

        if form.is_valid():
            try:
                customer = stripe.Customer.create(
                    description=form.cleaned_data['email'],
                    card=form.cleaned_data['stripe_id'],
                    plan='REG_MONTHLY'
                )
                print customer
            except stripe.CardError:
                messages.error(request, "Your card was declined!")
                print 'error carderror'
            if customer:
                user = form.save()
                user.stripe_id = customer.id
                user.subscription_end = arrow.now().replace(weeks=+4).datetime
                user.save()

                user = auth.authenticate(email=request.POST.get('email'),
                                         password=request.POST.get('password1'))

                if user:
                    auth.login(request, user)
                    messages.success(request, "You have successfully registered!")
                    return redirect(reverse('profile'))

                else:
                    messages.error(request, "Unable to log you in at this time")
            else:
                messages.error(request, "Unable to take a payment with that card")

    else:
        today = datetime.date.today()
        form = UserRegistrationForm(initial={'expiry_month': today.month,
                                            'expiry_year': today.year})

    args = {'form': form, 'publishable': settings.STRIPE_PUBLISHABLE}
    args.update(csrf(request))

    return render(request, 'register.html', args)
예제 #22
0
def register(request):
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            user = auth.authenticate(username=request.POST.get('username'),
                                     password=request.POST.get('password1'))
            if user:
                messages.success(request, "You have successfully registered")
                return redirect(reverse('profile'))
            else:
                messages.error(request, "Unable to login")

    else:
        form = UserRegistrationForm()
    args = {'form': form}
    args.update(csrf(request))

    return render(request, 'register.html', args)
예제 #23
0
def register(request):
    if request.method == 'POST':
        userForm = UserRegistrationForm(request.POST, prefix="user_form")
        profileForm = UserProfileRegistrationForm(request.POST, prefix="profile_form")

        if userForm.is_valid() and profileForm.is_valid():
            new_user = userForm.save()
            new_profile = profileForm.save(commit=False)
            new_profile.User_associated = new_user
            new_profile.Unikey_validated = True
            new_profile.Points = 200
            new_profile.Profile_picture = 'images_profile/sampleAvatar.png'
            new_profile.save()
            return HttpResponseRedirect('/accounts/register-success')
    else:
        userForm = UserRegistrationForm(prefix="user_form")
        profileForm = UserProfileRegistrationForm(prefix="profile_form")
   
    return render_to_response('accounts/signup.html', {"user_form": userForm, "profile_form": profileForm}, context_instance=RequestContext(request))
예제 #24
0
파일: views.py 프로젝트: devangb/to-do-app
def register(request):
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            form.save()

            user = auth.authenticate(username=request.POST.get('username'), password=request.POST.get('password1'))

            if user:
                auth.login(request, user)
                return redirect(reverse('index'))
            else:
                messages.error(request, "unable to log you in at this time!")


    else:
        form = UserRegistrationForm()

    args = {'form': form}
    args.update(csrf(request))

    return render(request, 'register.html', args)
예제 #25
0
def register(request):
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            try:
                customer = stripe.Customer.create(
                    email=form.cleaned_data['email'],
                    card=form.cleaned_data['stripe_id'],
                    # currency='JPY',
                    # amount=499,
                    plan='REG_MONTHLY')
                #
                #

                # description=form.cleaned_data['email'],
                # card=form.cleaned_data['stripe_id'],

            except stripe.error.CardError, e:
                messages.error(request, 'Your card was declined')

            if customer:
                user = form.save()
                user.stripe_id = customer.id
                user.subscription_end = arrow.now().replace(weeks=+4).datetime
                user.save()

                user = auth.authenticate(email=request.POST.get('email'), password=request.POST.get('password1'))

                if user:
                    auth.login(request, user)
                    messages.success(request, 'You have successfully registered')
                    # return redirect(reverse('profile'))
                    return render(request, 'customer_info.html', {'cushty': customer})
            else:
                messages.error(request, 'Unable to log you in at this time ')
        else:
            messages.error(request, 'Unable to take payment with that card')
예제 #26
0
파일: views.py 프로젝트: ezy023/marker-api
def create_user(request):
    if not request.method == 'POST':
        return HttpResponseNotAllowed(['POST'])

    post_params = json.loads(request.body)
    form = UserRegistrationForm(data=post_params)
    if form.is_valid():
        user = User()
        user.email = form.cleaned_data.get('email')
        user.set_password(form.cleaned_data.get('password'))
        with transaction.atomic():
            user.save()
            token = Token.create_token()
            user.token_set.add(token)

        logger.info("New user created. Email: %s", user.email)
        user_dict = user.to_dict()
        user_dict['access_token'] = token.token
        data = json.dumps(user_dict)
        return HttpResponse(data)
    else:
        logger.error("Invalid form to create new user. Errors: %s", form.errors)
        data = json.dumps(form.errors)
        return HttpResponseBadRequest(data)
예제 #27
0
def register(request):
    """ Render user registration page """
    if request.user.is_authenticated:
        return redirect(reverse('index'))
    if request.method == 'POST':
        registration_form = UserRegistrationForm(request.POST)
        if registration_form.is_valid():
            registration_form.save()

            user = auth.authenticate(username=request.POST['username'],
                                     password=request.POST['password1'])
            if user:
                auth.login(user=user, request=request)
                messages.success(request,
                                 'You have been successfully registered!')
                return redirect(reverse('index'))
            else:
                messages.error(request, 'Unable to register your account.')
    else:
        registration_form = UserRegistrationForm()
    return render(request, 'register.html',
                  {'registration_form': registration_form})
예제 #28
0
def register(request):
    if request.method == "POST":
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            form.save()

            user = auth.authenticate(email=request.POST.get('email'),
                                     password=request.POST.get('password1'))

            if user:
                messages.success(request, "You have successfully registered")
                return redirect(reverse('profile'))
            else:
                messages.error(request, "Unable to log you in at this time")

    else:
        form = UserRegistrationForm()

    args = {'form': form}
    args.update(csrf(request))

    return render(request, 'register.html', args)
예제 #29
0
def registration(request):
    """Render the registration page"""
    if request.user.is_authenticated:
        return redirect(reverse('index'))

    if request.method == "POST":
        registration_form = UserRegistrationForm(request.POST)

        if registration_form.is_valid():
            registration_form.save()

            user = auth.authenticate(username=request.POST['username'],
                                     password=request.POST['password1'])
            if user:
                auth.login(user=user, request=request)
                messages.success(request, "You have successfully registered", extra_tags="alert-success")
            else:
                messages.error(request, "Unable to register your account at this time", extra_tags="alert-danger")
    else:
        registration_form = UserRegistrationForm()
    return render(request, 'registration.html', {
        "registration_form": registration_form})
예제 #30
0
def index(request):
    """ Returns the index and registration page """
    if request.user.is_authenticated:
        return redirect(profile, request.user.pk)
    if request.method == "POST":
        registration_form = UserRegistrationForm(request.POST)
        if registration_form.is_valid():
            registration_form.save()
            user = auth.authenticate(username=request.POST['username'],
                                     password=request.POST['password1'])
            if user:
                auth.login(user=user, request=request)
                return redirect(profile, user.pk)
            else:
                messages.error(
                    request,
                    "Sorry. We are unable to register your account at this time."
                )
    else:
        registration_form = UserRegistrationForm()
    return render(request, 'index.html',
                  {'registration_form': registration_form})
예제 #31
0
def register(request):
    """A view that manages the registration form"""
    if request.method == 'POST':
        user_form = UserRegistrationForm(request.POST)
        if user_form.is_valid():
            user_form.save()

            user = auth.authenticate(request.POST.get('email'),
                                     password=request.POST.get('password1'))

            if user:
                auth.login(request, user)
                messages.success(request, "You have successfully registered")
                return redirect(reverse('index'))

            else:
                messages.error(request, "unable to log you in at this time!")
    else:
        user_form = UserRegistrationForm()

    args = {'user_form': user_form}
    return render(request, 'register.html', args)
def registration(request):
    """Render the registration page"""
    if request.user.is_authenticated:
        return redirect(reverse('index'))

    if request.method == "POST":
        registration_form = UserRegistrationForm(request.POST)

        if registration_form.is_valid():
            registration_form.save()

            user = auth.authenticate(username=request.POST['username'],
                                     password=request.POST['password1'])
            if user:
                auth.login(user=user, request=request)
                messages.success(request, "You have successfully registered and have been automatically logged in")
        else:
            messages.error(request, "Sorry, we were unable to register your account at this time, please check for error messages below")
    else:
        registration_form = UserRegistrationForm()
    return render(request, 'registration.html', {
        "registration_form": registration_form})
예제 #33
0
def registration(request):
    """
    Render the registration page
    """
    if request.user.is_authenticated:
        return redirect(reverse('index'))
        """
        redirect a registered user away from registration to the index
        """

    if request.method == "POST":
        registration_form = UserRegistrationForm(request.POST)

        if registration_form.is_valid():
            """
            add the user data to the User model in the database
            """
            registration_form.save()
            user = auth.authenticate(username=request.POST['username'],
                                     password=request.POST['password1'])
            if user:
                auth.login(user=user, request=request)
                messages.success(request, "You have registered successfully")
                return redirect(reverse('index'))
                """
                redirect the newly registered user away from registration to 
                the index
                """

        else:
            messages.error(request, registration_form.errors)
            """
            messages.warning(request, "Please check that your passwords
            match and username/email is unique!")
            """

    registration_form = UserRegistrationForm()
    return render(request, 'registration.html',
                  {"registration_form": registration_form})
예제 #34
0
def registration(request):
    ''' allows new clients to register an account '''

    if request.user.is_authenticated:
        return redirect(reverse('index'))

    if request.method == 'POST':
        registration_form = UserRegistrationForm(request.POST)

        if registration_form.is_valid():
            registration_form.save()
            messages.success(request, 'Account created successfully')
            return redirect(reverse('index'))
        else:
            messages.error(request,
                           'Unable to create your account at this time')

    else:
        registration_form = UserRegistrationForm()

    return render(request, "registration.html",
                  {"registration_form": registration_form})
def customer_profile(request):
    if request.method == 'POST':
        """create forms for user and customer, """
        """prefilled with current user info"""
        user_form = UserRegistrationForm(request.POST, instance=request.user)
        customer_form = CustomerForm(request.POST,
                                     instance=request.user.customer)
        """If user and customer info valid after editing, update/save infor"""
        if (user_form.is_valid() and customer_form.is_valid()
                and (customer_form.cleaned_data["full_name"] != '')
                and (customer_form.cleaned_data["street_Address1"] != '')
                and (customer_form.cleaned_data["street_Address2"] != '')
                and (customer_form.cleaned_data["town_or_city"] != '')
                and (customer_form.cleaned_data["county"] != '')
                and (customer_form.cleaned_data["country"] != '')
                and (customer_form.cleaned_data["postcode"] != '')
                and (customer_form.cleaned_data["phone_number"] != '')):
            user_form.save()
            customer_form.save()
            messages.success(
                request,
                _('Your Profile was\
                                 successfully updated!'))
            return redirect('settings:profile')
        else:
            """ If user/customer form not valid, prompt user"""
            if (form.cleaned_data["name"] == ''):
                messages.error(request, ('Please correct the error below.'))
    else:
        """create forms for user and customer, """
        """prefilled with current user info"""
        user_form = UserRegistrationForm(instance=request.user)
        customer_form = CustomerForm(instance=request.user.customer)
    """redisplay profile, with updated user/customer info"""
    return render(request, 'profiles/profile.html', {
        'user_form': user_form,
        'customer_form': customer_form
    })
예제 #36
0
파일: views.py 프로젝트: xislam/final_12
def signup(request):
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST, request.FILES)
        if form.is_valid():
            user = form.save()
            user.refresh_from_db(
            )  # load the profile instance created by the signal
            user.profile.avatar = form.cleaned_data.get('avatar')
            user.profile.first_name = form.cleaned_data.get('first_name')
            user.profile.last_name = form.cleaned_data.get('last_name')
            user.save()
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=user.username, password=raw_password)
            login(request, user)
            return redirect(
                reverse('accounts:profile', kwargs={'pk': user.profile.pk}))
    else:
        form = UserRegistrationForm()
    return render(request, 'registration/register.html', {'form': form})
예제 #37
0
def register(request):
    if request.user.is_authenticated:
        return HttpResponseRedirect('../home')
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.refresh_from_db()  # This will load the Profile created by the Signal
            user.profile.city = form.cleaned_data.get('city')
            user.profile.phone = form.cleaned_data.get('phone')
            user.save()
            raw_password  = form.cleaned_data.get('password1')
            user = authenticate(username=user.username, password=raw_password)
            login(request, user)
            return redirect('/account/userProfile.html')
    else:
        form = UserRegistrationForm()
        
    return render(request, 'webapp/account/register.html',{'form': form})
예제 #38
0
    def post(self, request, *args, **kwargs):

        # checking for email if is already taken or not
        # username is by default unique
        if User.objects.filter(email=request.POST['email']).exists():
            messages.error(request, 'That email is taken')
            return redirect('accounts:register')

        user_form = UserRegistrationForm(data=request.POST)

        if user_form.is_valid():
            user = user_form.save(commit=False)
            password = user_form.cleaned_data.get("password1")
            user.set_password(password)
            user.save()
            return redirect('accounts:login')
        else:
            user_form = UserRegistrationForm()
            return render(request, 'accounts/form.html', {'form': user_form})
def registration(request):
    """ render the registration page"""
    if request.user.is_authenticated():
        return redirect(reverse('dashboard_page'))
        
    if request.method=="POST":
        registration_form = UserRegistrationForm(request.POST)
        
        if registration_form.is_valid():
            registration_form.save()
            
            user = auth.authenticate(username = request.POST['username'],
                                        password = request.POST['password1'])
        
            if user:
                auth.login(user=user, request=request)
                messages.success(request, "You have seccessfully registered.")
                return redirect(reverse('dashboard_page'))
            else:
                messages.error(request, "Unable to register your account at this time.")
            
    registration_form = UserRegistrationForm()
    return render(request, "registration.html", { 'registration_form': registration_form })
예제 #40
0
def registration(request):
    ''' registration page '''
    if request.user.is_authenticated:
        return redirect(reverse('index'))

    if request.method == 'POST':
        registration_form = UserRegistrationForm(request.POST)

        if registration_form.is_valid():
            registration_form.save()

            user = auth.authenticate(username=request.POST['username'],
                                     password=request.POST['password1'])
            if user:
                auth.login(user=user, request=request)
                messages.success(request, 'You have successfully registered')
            else:
                messages.error(request, 'An error occured')
    else:
        registration_form = UserRegistrationForm()

    return render(request, 'registration.html',
                  {'registration_form': registration_form})
예제 #41
0
def register(request):
    """ Renders the registration page """
    if request.user.is_authenticated:
        return redirect(reverse("profile"))
    if request.method == "POST":
        register_form = UserRegistrationForm(request.POST)
        if register_form.is_valid():
            register_form.save()
            user = auth.authenticate(username=request.POST["username"],
                                     password=request.POST["password1"])
            if user:
                auth.login(user=user, request=request)
                messages.success(request, f"Welcome, {user.first_name}!")
                return redirect(reverse("profile"))
            else:
                messages.error(request,
                               f"Error with registration. Please try again!")
    else:
        register_form = UserRegistrationForm()
    context = {
        "register_form": register_form,
    }
    return render(request, "register.html", context)
예제 #42
0
def registration(request):
    # logic to record form information in our database
    if request.user.is_authenticated:
        return redirect(reverse('index'))

    if request.method == "POST":
        registration_form = UserRegistrationForm(request.POST)

        if registration_form.is_valid():
            registration_form.save()

            user = auth.authenticate(username=request.POST['username'],
                                     password=request.POST['password1'])
            if user:
                auth.login(user=user, request=request)
                messages.success(request, "You have successfully registered")
            else:
                messages.error(request,
                               "Unable to register your account at this time")
    else:
        registration_form = UserRegistrationForm()
    return render(request, 'registration.html',
                  {"registration_form": registration_form})
예제 #43
0
def registration(request):
    """Render the registration page"""
    if request.user.is_authenticated:
        return redirect(reverse('index'))

    if request.method == "POST":
        registration_form = UserRegistrationForm(request.POST)

        if registration_form.is_valid():
            registration_form.save()

            user = auth.authenticate(username=request.POST['username'],
                                     password=request.POST['password1'])
            if user:
                auth.login(user=user, request=request)
                messages.success(request, "You have registered")
                return redirect(reverse('index'))
            else:
                messages.error(request, "Account registeration failed")
    else:
        registration_form = UserRegistrationForm()
    return render(request, 'registration.html',
                  {"registration_form": registration_form})
예제 #44
0
def register(request, e=None):
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            try:
                customer = stripe.Customer.create(
                    email=form.cleaned_data['email'],
                    card=form.cleaned_data['stripe_id'],
                    plan='REG_MONTHLY',
                )

                if customer.paid:
                    form.save()
                    user = auth.authenticate(email=request.POST.get('email'), password=request.POST.get('password1'))

                    if user:
                        auth.login(request, user)
                        messages.success(request, "You have successfully registered")
                        return redirect(reverse('profile'))

                    else:
                        messages.error(request, "We are unable to log you in")

                else:
                    messages.error(request, "We were unable to take a payment with that card")

            except stripe.error.CardError as e:
                messages.error(request, "Your card was declined")

    else:
        today = datetime.date.today()
        form = UserRegistrationForm()

    args = {'form': form, 'publishable': settings.STRIPE_PUBLISHABLE}
    args.update(csrf(request))

    return render(request, 'Yoga/templates/register.html', args)
예제 #45
0
def register(request):
    if request.method == 'POST':
        user_form = UserRegistrationForm(request.POST)
        if user_form.is_valid():
            new_user = user_form.save(commit=False)
            new_user.set_password(user_form.cleaned_data['password'])
            new_user.save()
            Profile.objects.create(user=new_user)
            new_user.save()
            return render(request,
                          'accounts/register_done.html',
                          {'new_user': new_user, }, )
        return render(request,
                      'accounts/registration.html',
                      {'user_form': user_form, }, )
    else:
        user_form = UserRegistrationForm()
        return render(request,
                      'accounts/registration.html',
                      {'user_form': user_form, }, )
예제 #46
0
def registration(request):
    """Renders registration page"""
    if request.user.is_authenticated:
        return redirect(reverse('index'))

    if request.method == "POST":
        registration_form = UserRegistrationForm(request.POST)

        if registration_form.is_valid():
            registration_form.save()

            user = auth.authenticate(username=request.POST['username'],
                                     password=request.POST['password1'])
            if user:
                auth.login(user=user, request=request)
                messages.success(request,
                                 "Successfully registered a new user!")
            else:
                messages.error(request,
                               "Couldn't register you, try again later : (")
    else:
        registration_form = UserRegistrationForm()
    return render(request, 'registration.html',
                  {"registration_form": registration_form})
예제 #47
0
def register(request):
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            if User.objects.filter(email=form.cleaned_data['email']):
                messages.error(request, "This email is already taken")
            else:
                form.save()
                user = auth.authenticate(
                    email=request.POST.get('email'),
                    password=request.POST.get('password1'))
                if user:
                    auth.login(request, user)
                    messages.success(request,
                                     "You have successfully registered!")
                    return redirect(reverse('home'))
                else:
                    messages.error(request,
                                   "Unable to log you in at this time!")
    else:
        form = UserRegistrationForm()
    args = {'form': form}
    args.update(csrf(request))
    return render(request, 'register.html', args)
예제 #48
0
def registration(request):
    """ Renders the registration page """
    if request.user.is_authenticated:
            return redirect(reverse("index"))

    if request.method=="POST":
        registration_form = UserRegistrationForm(request.POST)
        if registration_form.is_valid():
            registration_form.save()
            user = auth.authenticate(
                username=request.POST["username"],
                password=request.POST["password1"])
            if user:
                auth.login(user=user, request=request)
                messages.success(request, "You have successfully registered!")
                return redirect(reverse("index"))
            else:
                messages.error(
                    request, "There has been an error with registration, please try again!")
    else:
        registration_form = UserRegistrationForm()

    return render(request, "registration.html", {
        "registration_form": registration_form})
예제 #49
0
def registration(request):
    '''
    Register a new user based on full name, email address and password
    '''
    if request.user.is_authenticated:
        return redirect(reverse('index'))

    if request.method == 'POST':
        registration_form = UserRegistrationForm(request.POST)
        if registration_form.is_valid():
            registration_form.save()
            user = auth.authenticate(username=request.POST['email'],
                                     password=request.POST['password1'])
            if user:
                auth.login(user=user, request=request)
                messages.success(request, 'You have been registered')
                return redirect(reverse('index'))
            else:
                messages.error(request, 'Unable to register your account')
    else:
        registration_form = UserRegistrationForm()

    return render(request, 'register.html',
                  {'registration_form': registration_form})
예제 #50
0
def registration(request):
    """
    View for users to register a new account.
    Checks if form is valid, and responds accordingly,
    then redirects users to the login page on successfully
    creating a new account.
    """

    if request.user.is_authenticated():
        return redirect(reverse("index"))

    if request.method == "POST":
        registration_form = UserRegistrationForm(request.POST)

        if registration_form.is_valid():
            registration_form.save()

            user = auth.authenticate(
                username=request.POST["username"],
                password=request.POST["password1"],
            )
            if user:
                auth.login(user=user, request=request)

                messages.success(
                    request,
                    f"You have successfully registered {user.username}",
                )
                return redirect(reverse("index"))
            else:
                messages.error(request,
                               "Unable to register your account at this time")
    else:
        registration_form = UserRegistrationForm()
    return render(request, "registration.html",
                  {"registration_form": registration_form})
예제 #51
0
def registration(request):
    '''Render the registration page'''
    
    if request.user.is_authenticated:
        return redirect(reverse('index'))
        
    if request.method == 'POST':
        registration_form = UserRegistrationForm(request.POST)
        
        if registration_form.is_valid():
            registration_form.save()
            
            user = auth.authenticate(username=request.POST['username'],
                                    password=request.POST['password1'])
            if user:
                auth.login(user=user, request=request)
                messages.success(request, 'You have successfully registered and have been logged in!')
                return redirect(reverse('index'))
            else:
                messages.error(request, 'Sorry, something went wrong during your account registration. Unable to register your account at this time.')
                
    else:
        registration_form = UserRegistrationForm()
    return render(request, 'registration.html', {'registration_form': registration_form})
예제 #52
0
def registration(request):
    if request.user.is_authenticated:
        return redirect(reverse('tickets'))

    if request.method == "POST":
        registration_form = UserRegistrationForm(request.POST)

        if registration_form.is_valid():
            registration_form.save()

            user = auth.authenticate(username=request.POST['username'],
                                     password=request.POST['password1'])

            if user:
                auth.login(user=user, request=request)
                messages.success(request, "You have registered successfully")
                return redirect(reverse('tickets'))
            else:
                messages.error(request,
                               "Unable to register your details at this time")
    else:
        registration_form = UserRegistrationForm()
    return render(request, 'registration.html',
                  {'registration_form': registration_form})
def register(request):
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            form.save()
 
            user = auth.authenticate(email=request.POST.get('email'),
                                     password=request.POST.get('password1'))
 
            if user:
                auth.login(request,user)
                messages.success(request, "You have successfully registered")
                return redirect(reverse('index'))
 
            else:
                messages.error(request, "unable to log you in at this time!")
 
    else:
        form = UserRegistrationForm()
 
    args = {'form': form, 'active_register': True}
    args.update(csrf(request))
 
    return render(request, 'register.html', args)
예제 #54
0
def registration(request):
    """Render the registration page"""
    #redirect to the index page if user is authenticated
    if request.user.is_authenticated:
        return redirect(reverse('index'))
    if request.method == "POST":
        # create an instance of the reg form using values within the pos request
        #  create new login form with the data posted from the form
        registration_form = UserRegistrationForm(request.POST)
        if registration_form.is_valid():
            registration_form.save()
            user = auth.authenticate(username=request.POST['username'],
                                     password=request.POST['password1'])
            if user:
                auth.login(user=user, request=request)
                messages.success(request, "You have successfully registered")
                return redirect(reverse('index'))
            else:
                messages.error(request,
                               "Unable to register your account at this time")
    else:
        registration_form = UserRegistrationForm()
    return render(request, 'registration.html',
                  {"registration_form": registration_form})
예제 #55
0
def add_user_view(request):
    if request.user.has_perm('create_stuff'):
        if request.method == 'POST':
            user_form = UserRegistrationForm(request.POST)
            if user_form.is_valid():
                role = request.POST.get('user_role')
                if role == 'admin':
                    user = user_form.save()
                    assign_role(user, 'admin')
                    return redirect('academics:all_accounts')
                elif role == 'stuff':
                    user = user_form.save()
                    assign_role(user, 'stuff')
                    return redirect('academics:all_accounts')
            else:
                return render(request, 'academics/add_user.html')
        else:
            user_form = UserRegistrationForm()
        context = {
            'user_form': user_form,
        }
        return render(request, 'academics/add_user.html', context)
    else:
        return render(request, 'academics/permission_required.html')
예제 #56
0
def register(request):
    """
    Render the registration page
    """
    if request.user.is_authenticated:
        sweetify.info(request,
                      "You are already logged in",
                      button='Ok',
                      timer=3000)
        return redirect(reverse('index'))

    if request.method == "POST":
        registration_form = UserRegistrationForm(request.POST)

        if registration_form.is_valid():
            registration_form.save()

            user = auth.authenticate(username=request.POST['username'],
                                     password=request.POST['password1'])

            if user:
                auth.login(user=user, request=request)
                sweetify.success(request, "You have successfully registered")
                return redirect(reverse('index'))
            else:
                sweetify.info(request,
                              "Unable to register your account at this time!",
                              button='Ok',
                              timer=3000)
    else:
        # Create an instance of reg form
        registration_form = UserRegistrationForm()

    return render(request, 'registration.html',
                  {"registration_form": registration_form})
    """