Esempio n. 1
0
 def mutate(self, info, **kwargs):
     form = SignupForm(kwargs)
     if form.is_valid():
         form.instance.last_login = time.time()
         form.save()
         send_welcome_email(
             form.instance,
             info.context.META.get("HTTP_ORIGIN",
                                   "https://imaps.goodwright.com"))
         info.context.imaps_refresh_token = form.instance.make_refresh_jwt()
         info.context.user = form.instance
         return SignupMutation(access_token=form.instance.make_jwt(900),
                               user=form.instance)
     raise GraphQLError(json.dumps(form.errors))
Esempio n. 2
0
 def post(self, request, *args, **kwargs):
     user_form = SignupForm(data=request.POST)
     registered = False
     if user_form.is_valid():
         user = user_form.save(commit=True)
         user.email = user_form.cleaned_data['email']
         user.save()
         registered = True
         return render(request, 'my_auth/signup.html',
                       {'registered': registered})
     else:
         return render(request, 'my_auth/signup.html', {
             'form': user_form,
             'registered': registered
         })
Esempio n. 3
0
def sign_up(request):
    """
    Sign up new user, log them in and redirect to new game
    """
    context = {}
    if request.POST:
        form = SignupForm(request.POST)
        if form.is_valid():
            username, password = form.save()
            user = authenticate(username=username, password=password)
            login(request, user)
            return HttpResponseRedirect("/")
    else:
        form = SignupForm()
    context['form'] = form    
    return render_to_response('registration/sign_up.html', context, context_instance=RequestContext(request))
Esempio n. 4
0
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():

            authy_user = authy_api.users.create(
                email=form.cleaned_data.get('email'),
                phone=form.cleaned_data.get('contact'),
                country_code=91)
            if authy_user.ok():
                print(authy_user.id)
                sms = authy_api.users.request_sms(authy_user.id,
                                                  {'force': True})
                if sms.ok():
                    print('SMS request successful')

                    user = User.objects.create(
                        username=form.cleaned_data.get('username'),
                        name=form.cleaned_data.get('name'),
                        email=form.cleaned_data.get('email'),
                        contact=form.cleaned_data.get('contact'),
                        password=form.cleaned_data.get('password1'),
                        authy_id=authy_user.id)
                    try:
                        sendConfirm(user)
                    except:
                        return HttpResponse(
                            'You may have entered a wrong email address. Please check it again!'
                        )

                    return redirect('verify_otp', authy_user.id)
                    #
                    # else:
                    #     login(request, user)
                    #     return render(request, 'index.html', {'user': user})
                else:
                    return HttpResponse(
                        'You may have entered a wrong contact number. Please check it!'
                    )
            else:
                print(authy_user.errors())
                return render(request, '500.html')

    else:
        form = SignupForm()
    return render(request, 'signup.html', {'form': form})
Esempio n. 5
0
def sign_up(request):
    """
    Sign up new user, log them in and redirect to new game
    """
    context = {}
    if request.POST:
        form = SignupForm(request.POST)
        if form.is_valid():
            username, password = form.save()
            user = authenticate(username=username, password=password)
            login(request, user)
            return HttpResponseRedirect("/")
    else:
        form = SignupForm()
    context['form'] = form
    return render_to_response('registration/sign_up.html',
                              context,
                              context_instance=RequestContext(request))
Esempio n. 6
0
def register(request):
    """
    This view redirects users to the signup page. If user is submitting
    form (POST), user registration takes place. If user is visiting
    page, user is directed to page containing registration form.

    """
    if request.method == 'POST':
        post_data = request.POST.copy()
        post_data['date_of_birth'] = parse(post_data['date_of_birth'])
        form = SignupForm(post_data)
        if form.is_valid():
            new_user, created = User.objects.get_or_create(
                username=form.data['username'])
            if created:
                new_user.first_name = form.data['first_name']
                new_user.last_name = form.data['last_name']
                new_user.email = form.data['email']
                new_user.set_password(form.data['password'])
                new_user.profile.bio = form.data['bio']
                new_user.profile.gender = form.data['gender']
                new_user.profile.photo = form.data['photo']
                new_user.profile.date_of_birth = form.data['date_of_birth']
                new_user.profile.mobile_number = form.data['mobile_number']
                new_user.profile.address = form.data['address']
                new_user.profile.city = form.data['city']
                new_user.profile.country = form.data['country']
                new_user.is_active = True
                new_user.save()
                login(request, new_user)
                messages.success(
                    request,
                    'Registration was successful. Welcome to Auto-shop.',
                )
                return redirect('/')

        print 'Profile for user "%s" failed to save due to validation errors: %s' % (
            request.user.username, form.errors)
        messages.error(request,
                       'Form is invalid. Please try again.' + form.errors)
        return render(request, 'register.html')
    else:
        form = SignupForm()
        return render(request, 'register.html', {'form': form})
Esempio n. 7
0
def signup(request):
    """View that handles user registration."""

    if request.user.is_authenticated():
        return HttpResponseRedirect("/")

    if request.method == "GET":
        form = SignupForm()  # Create an empty form if the method is GET.
    elif request.method == "POST":
        form = SignupForm(request.POST)  # Populate the form with POST data.
        if form.is_valid():
            # Get the form data.
            username = form.cleaned_data["username"]
            email = form.cleaned_data["email"]
            password = form.cleaned_data["password"]
            first_name = form.cleaned_data["first_name"]
            last_name = form.cleaned_data["last_name"]

            # Create a new user and profile.
            user = User.objects.create_user(username, email, password)
            user.first_name = first_name
            user.last_name = last_name
            user.save()  # Save the user.

            new_profile = UserProfile()
            new_profile.new(user, form.cleaned_data["phone"], get_remote_ip(request))

            # Send an email with the confirmation link
            site = Site.objects.get_current()
            subject = "%s User Activation" % site.name
            body = (
                "Hello, %s, and thanks for signing up for an account at %s!"
                "\n\nTo activate your account, click this link within 48 hours:"
                "\n\nhttp://%s/login/%s" % (user.username, site.domain, site.domain, new_profile.activation_key)
            )
            send_mail(subject, body, "settings.EMAIL_HOST_USER", [user.email])

            # Redirect to a confirmation page.
            return HttpResponseRedirect("/signup/confirmed/")

    # Load signup.html on GET request and POST error.
    return load_page(request, "signup.html", {"form": form})
Esempio n. 8
0
def sign_up(request: WSGIRequest) -> HttpResponse:
    if request.method == "POST":
        signup_form = SignupForm(request.POST)
        if signup_form.is_valid():
            username = signup_form.cleaned_data["username"]
            email = signup_form.cleaned_data["email"]
            password = signup_form.cleaned_data["password"]
            FinetoothUser.objects.create_user(username, email, password)
            messages.success(request, _("Account creation successful!"))
            new_user = authenticate(username=username, password=password)
            login(request, new_user)
            return redirect("home")
        else:
            messages.warning(request, signup_form.errors)
            return render(
                request, 'sign_up.html', {'signup_form': signup_form},
                status=422
            )
    else:
        signup_form = SignupForm()
        return render(request, 'sign_up.html', {'signup_form': signup_form})