コード例 #1
0
ファイル: views.py プロジェクト: ymdx/Practica_Django
    def post(self, request):
        form = SignUpForm(request.POST)

        if form.is_valid():
            user = User()
            cleaned_data = form.cleaned_data
            user.username = cleaned_data.get("username")
            user.first_name = cleaned_data.get("first_name")
            user.last_name = cleaned_data.get("last_name")
            user.email = cleaned_data.get("email")
            user.set_password(cleaned_data.get("password"))
            user.save()

            message = 'Usuario creado con éxito'
            django_login(request, user)
            url = request.GET.get('next', 'index')
            return redirect(url)
        else:
            message = "Se ha producido un error"

        context = {
            "form": form,
            "message":message
        }

        return render(request, 'users/signup.html', context)
コード例 #2
0
ファイル: views.py プロジェクト: jbiscarri/Wordplease-django
    def post(self, request):
        error_messages = []
        form = SignUpForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data.get('usr')     # Obtengo datos formateados o normalizados
            password = form.cleaned_data.get('pwd')
            name = form.cleaned_data.get('name')
            surnames = form.cleaned_data.get('surnames')
            email = form.cleaned_data.get('email')

            if username and password and name and surnames and email:
                User.objects.create_user(username, email=email, password=password, first_name=name, last_name=surnames )
                user = authenticate(username=username, password=password)
                if user is None:
                    error_messages.append('Usuario ya existente')
                else:
                    django_login(request, user)
                    url = request.GET.get('next', 'new_post')
                    return redirect(url)
            else:
                error_messages.append('Faltan datos')
        context = {
            'errors': error_messages,
            'login_form': form
        }
        return render(request, 'users/signup.html', context)
コード例 #3
0
ファイル: views.py プロジェクト: johanarnor/intnet14_project
def sign_up_view(request):
    if request.method != "POST":
        form = SignUpForm()
        dictionary = {"form": form}
        return render(request, "users/sign_up.html", dictionary)
    else:
        form = SignUpForm(request.POST)
        if form.is_valid():
            if form.cleaned_data["password1"] != form.cleaned_data["password2"]:
                dictionary = {"form": form, "pw": "Passwords did not match"}
                return render(request, "users/sign_up.html", dictionary)
            else:
                user = DirrUser.objects.create_user(
                    username=form.cleaned_data["username"],
                    password=form.cleaned_data["password1"],
                    email=form.cleaned_data["email"],
                    first_name=form.cleaned_data["first_name"],
                    last_name=form.cleaned_data["last_name"],
                    phone_nr=form.cleaned_data["phone_nr"],
                    address=form.cleaned_data["address"],
                    p_code=form.cleaned_data["p_code"],
                    city=form.cleaned_data["city"],
                )
                user.is_active = True
                user.is_staff = False
                user.is_superuser = False
                user.save()
                user.authenticate(form.cleaned_data["username"], form.cleaned_data["password1"])
                login(request, user)
        else:
            dictionary = {"form": form, "pw": "Some fields were left blank"}
            return render(request, "users/sign_up.html", dictionary)
        return HttpResponseRedirect(reverse("main:main"))
コード例 #4
0
ファイル: views.py プロジェクト: mvelezserrano/wordplease
 def post(self, request):
     success_message = ''
     form = SignUpForm(request.POST)
     if form.is_valid():
         form.save()
         form = SignUpForm()
         success_message = 'Usuario creado con éxito!'
     context = {
         'signup_form': form,
         'success_message': success_message
     }
     return render(request, 'users/signup.html', context)
コード例 #5
0
ファイル: views.py プロジェクト: none-da/iamtheresume
def view_signup(request, signup_template):
    if request.method == 'POST':
        form = SignUpForm(post_data(request))
        if form.is_valid():
            signup_data = form.cleaned_data
            userprofile = UserProfile.objects.create_profile(email=signup_data.get('email'),
                                                             password=signup_data.get('password'),
                                                             name=signup_data.get('name'))
            return _let_user_login(request,
                                   userprofile.user,
                                   email=signup_data.get('email'),
                                   password=signup_data.get('password'))
        else:
            from users.messages import USER_SIGNUP_FAILURE
            messages.error(request, USER_SIGNUP_FAILURE)
    else:
        form = SignUpForm()
    return response(request, signup_template, {'form':form})
コード例 #6
0
ファイル: views.py プロジェクト: dachrisch/hackday
def sign_up(request):
    error_message = None

    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            # Create the user
            try:
                user = User.objects.create_user(
                        form.cleaned_data['user_name'],
                        form.cleaned_data['email'],
                        form.cleaned_data['password'])
            except IntegrityError:
                error_message = "That username is not available."
            else:
                user.first_name = form.cleaned_data['first_name']
                user.last_name = form.cleaned_data['last_name']
                user.save()

                # Create the user profile
                user_profile = UserProfile(
                        user=user,
                        alternate_email=form.cleaned_data['alternate_email'],
                        phone=form.cleaned_data['phone'],
                        tshirt=form.cleaned_data['tshirt'],
                        diet=form.cleaned_data['diet'],
                        location=form.cleaned_data['location'],
                        description=form.cleaned_data['description'],
                        notify_by_email=form.cleaned_data['notify_by_email'])
                user_profile.save()

                # Log the user in
                user = authenticate(username=user.username,
                        password=form.cleaned_data['password'])
                login(request, user)

                return HttpResponseRedirect(reverse('users-profile', args=[user.username])) # Redirect after POST
    else:
        form = SignUpForm()

    env = common_env()
    env['form'] = form
    env['error_message'] = error_message
    return render(request, 'users/signup.html', env)
コード例 #7
0
ファイル: views.py プロジェクト: jrcousins/hackday
def sign_up(request):
    error_message = None

    if request.method == "POST":
        form = SignUpForm(request.POST)
        if form.is_valid():
            # Create the user
            try:
                user = User.objects.create_user(
                    form.cleaned_data["user_name"], form.cleaned_data["email"], form.cleaned_data["password"]
                )
            except IntegrityError:
                error_message = "That username is not available."
            else:
                user.first_name = form.cleaned_data["first_name"]
                user.last_name = form.cleaned_data["last_name"]
                user.save()

                # Create the user profile
                user_profile = UserProfile(
                    user=user,
                    tshirt=form.cleaned_data["tshirt"],
                    diet=form.cleaned_data["diet"],
                    location=form.cleaned_data["location"],
                    description=form.cleaned_data["description"],
                    notify_by_email=form.cleaned_data["notify_by_email"],
                )
                user_profile.save()

                # Log the user in
                user = authenticate(username=user.username, password=form.cleaned_data["password"])
                login(request, user)

                return HttpResponseRedirect("/users")  # Redirect after POST
    else:
        form = SignUpForm()

    env = common_env()
    env["form"] = form
    env["error_message"] = error_message
    return render(request, "users/signup.html", env)
コード例 #8
0
    def post(self, request):
        """
        Muestra el formulario para crear un usuario nuevo
        :param request:
        :return:
        """
        user_form = SignUpForm(request.POST)

        if user_form.is_valid():
            user = User()
            user.username = user_form.cleaned_data.get('username')
            user.first_name = user_form.cleaned_data.get('first_name')
            user.last_name = user_form.cleaned_data.get('last_name')
            user.email = user_form.cleaned_data.get('email')
            user.password = user_form.cleaned_data.get('password1')

            user.save()

            return redirect('signup_success')
        else:
            context = {'form': user_form}

            return render(request, 'users/signup.html', context)
コード例 #9
0
ファイル: views.py プロジェクト: johanarnor/intnet
def sign_up_view(request):
    if request.method != 'POST':
        form = SignUpForm()
        dictionary = {'form': form}
        return render(request, 'users/sign_up.html', dictionary)
    else:
        form = SignUpForm(request.POST)
        if form.is_valid():
            if form.cleaned_data['password1'] != form.cleaned_data['password2']:
                dictionary = {'form': form, 'pw': 'Passwords did not match'}
                return render(request, 'users/sign_up.html', dictionary)
            else:
                user = DirrUser.objects.create_user(username=form.cleaned_data['username'], password=form.cleaned_data['password1'], email=form.cleaned_data['email'], first_name=form.cleaned_data['first_name'], last_name=form.cleaned_data['last_name'], phone_nr=form.cleaned_data['phone_nr'], address=form.cleaned_data['address'], p_code=form.cleaned_data['p_code'], city=form.cleaned_data['city'])
                user.is_active = True
                user.is_staff = False
                user.is_superuser = False
                user.save()
                user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password1'])
                login(request, user)
        else:
            dictionary = {'form': form, 'pw': 'Some fields were left blank'}
            return render(request, 'users/sign_up.html', dictionary)
        return HttpResponseRedirect(reverse('main:main'))
コード例 #10
0
ファイル: views.py プロジェクト: Jorgargom/bootcamp
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('home')
    else:
        form = SignUpForm()
    return render(request, "signup.html", {'form': form})
コード例 #11
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            email = form.cleaned_data.get('email')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(email=email, password=raw_password)
            login(request, user)
            return redirect('/admin/')
    else:
        form = SignUpForm()
    return render(request, 'users/signup.html', {'form': form})
コード例 #12
0
ファイル: views.py プロジェクト: sriegodedios/personalwebsite
def registration(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request)
            return redirect('../profile/address-info')
    else:
        form = SignUpForm()
    return render(request, 'users/registration.html', {'form': form})
コード例 #13
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        user = self.request.user
        context['user_form'] = SignUpForm(instance=user)
        context['profile_form'] = ProfileForm(instance=user.get_profile())

        if not self.request.POST:
            if user.is_member:
                context['member_form'] = MemberForm(
                    instance=user.get_member_profile())
            if user.is_voluntary:
                context['voluntary_form'] = VoluntaryForm(
                    instance=user.get_voluntary_profile())

        return context
コード例 #14
0
ファイル: views.py プロジェクト: Timibreez/saveBlog
def signup_user(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            login(request, user)
            return redirect('saveNow:index')
    else:
        form = SignUpForm()
    return render(request,'users/signup.html', {'form':form})
コード例 #15
0
def register(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.set_password(form.cleaned_data['password1'])
            user.save()
    else:
        form = SignUpForm()
    return render(request, 'users/signup.html', {'form': form})
コード例 #16
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            auth_login(request, user)
            return redirect('districts')
    else:
        form = SignUpForm()
    return render(request, 'users/signup.html', {'form': form})
コード例 #17
0
ファイル: views.py プロジェクト: seyidov579/dockerandtask
def signup(request):
    template = 'registration/registration.html'
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('email')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(email=username, password=raw_password)
            login(request, user)
            return redirect('home')
    else:
        form = SignUpForm()
    return render(request, template, {'form': form})
コード例 #18
0
def signup(request):
    """Register a new user."""
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('design:first')
    else:
        form = SignUpForm()
    return render(request, 'users/signup.html', {'form': form})
コード例 #19
0
def signup(request):
    if request.method == "POST":
        password = request.POST.get('password', '')
        re_enter_password = request.POST.get('re_enter_password', '')
        user_type = request.POST.get('user_type', '')

        if password == re_enter_password:
            username = request.POST.get('username')
            first_name = request.POST.get('first_name')
            last_name = request.POST.get('last_name')
            email = request.POST.get('email')
            user = User.objects.create_user(username, password=password)
            user.first_name = first_name
            user.last_name = last_name
            user.email = email
            user.save()
            user_account = UserAccount.objects.create(user=user,
                                                      user_type=user_type)
            user_account.save()
            if user_type == 'S':
                roll_number = request.POST.get('roll_number')
                year_of_joining = request.POST.get('year_of_joining')
                program = request.POST.get('program_type')
                discipline = request.POST.get('discipline_type')
                gender = request.POST.get('gender_type')
                hostel = request.POST.get('hostel_type')
                student = Student.objects.create(
                    user_account=user_account,
                    roll_number=roll_number,
                    year_of_joining=year_of_joining,
                    program=program,
                    discipline=discipline,
                    gender=gender,
                    hostel=hostel)
                student.save()
            else:
                emp_id = request.POST.get('emp_id')
                authority = ApprovingAuthority.objects.create(
                    user_account=user_account, emp_id=emp_id)
                authority.save()
            authenticate(username=username, password=password)
            return redirect('users:confirm-signup')
        else:
            return redirect('users:login')
    else:
        form = SignUpForm()
    return render(request, 'users/signup.html', {'form': form})
コード例 #20
0
ファイル: views.py プロジェクト: JIANZM/Videoproject
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password1 = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password1)
            auth_login(request, user)
            return redirect('home')
        else:
            print(form.errors)
    else:
        form = SignUpForm()
    return render(request, 'registration/signup.html', {'form': form})
コード例 #21
0
def signup_view(request):
    """"Sign up view."""
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('users:login')
    else:
        form = SignUpForm()

    return render(
        request=request,
        template_name='users/signup.html',
        context={'form': form},
    )
コード例 #22
0
def signup(request):
        """Handles signup form and keeps category drop down with the page"""
        categories = Category.objects.all()
        if request.method == 'POST':
            form = SignUpForm(request.POST)
            if form.is_valid():
                print('valid')
                form.save()
                username = form.cleaned_data.get('username')               
                raw_password = form.cleaned_data.get('password1')
                user = authenticate(username=username, password=raw_password)
                login(request, user)
                return redirect('/users/login')
        else:
            form = SignUpForm()
        return render(request, 'users/signup.html', {'form': form, 'categories': categories})
コード例 #23
0
ファイル: views.py プロジェクト: jsgovea/blog-django
def signup(request):
    """Sign up view."""
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            login(
                request,
                authenticate(username=form.cleaned_data["username"],
                             password=form.cleaned_data["password"]))
            return redirect('posts:feed')
    else:
        form = SignUpForm()

    return render(request=request,
                  template_name='users/signup.html',
                  context={'form': form})
コード例 #24
0
def signup(request):
    if request.method == 'POST':
        # form = UserCreationForm(request.POST)
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            if user is not None:
                login(request, user)
                return HttpResponseRedirect(reverse("cart"))
        else:
            return render(request, "users/signup.html", {"form": form})

    else:
        form = SignUpForm()
        return render(request, "users/signup.html", {"form": form})
コード例 #25
0
def index(request):
    title = 'Home'
    p = Post.objects.filter(deleted=False).order_by('created_at').reverse()
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            login(request, user)
            messages.add_message(request, messages.INFO, 'Welcome to our Blog!')
            return redirect('index')
    else:
        form = SignUpForm()
    form2 = SignInForm()
    return render(request, 'index.html', {'title': title, 'posts': p,
                                          'form': form, 'form2': form2})
コード例 #26
0
ファイル: views.py プロジェクト: Rouizi/OC_project11
def signup(request):
    title = 'Inscription'

    if request.user.is_authenticated:
        return redirect('index')
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=password)
            login(request, user)
            messages.add_message(request, messages.SUCCESS,
                                 'Félicitations, vous étes maintenant un utilisateur enregistré!')
            return redirect('index')
    else:
        form = SignUpForm()
    return render(request, 'users/signup.html', {'form': form ,'title': title})
コード例 #27
0
ファイル: views.py プロジェクト: ZhenKasp/TrelloClone
def register(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.refresh_from_db()
            user.profile.birth_date = form.cleaned_data.get('birth_date')
            user.save()
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=password)
            login(request, user)
            return redirect('index')
    else:
        form = SignUpForm()
    return render(request, 'registration/register.html', {'form': form})
コード例 #28
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.refresh_from_db(
            )  # load the profile instance created by the signal
            user.Profile.account_no = form.cleaned_data.get('account_no')
            user.save()
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=user.username, password=raw_password)
            login(request, user)
            return redirect('home')
    else:
        form = SignUpForm()
    return render(request, 'signup.html', {'form': form})
コード例 #29
0
 def post(self, request):
     user_post = User()
     form = SignUpForm(request.POST, instance= user_post)
     if form.is_valid():
         user_post.set_password(form.cleaned_data.get("password"))
         user_post = form.save()
         default_blog_name= "Weblog " + str(user_post.username)
         url = "/blogs/" + str(user_post.username)
         blog_default = Blog(description="",name="Weblog " + user_post.username,user=user_post, url=url)
         blog_default.save()
         form = SignUpForm()
         message = "User "+user_post.username+" registered successfully! "
         message+= "Your default blog name is "+ default_blog_name
         messages.success(request, message)
     context = {'form': form}
     return render(request, "signup_form.html", context)
コード例 #30
0
ファイル: views.py プロジェクト: leenasherif239/crowd-funding
def UserRegisterView(request):

    form = SignUpForm()
    if request.method == 'POST':
        form = SignUpForm(request.POST, request.FILES)
        if form.is_valid():
            user = form.save()

            # username = form.cleaned_data.get('frist_name')
            # messages.success(request, 'Account was created for ' + username)
            ###############email activat##########################33
            user.is_active = False
            username = request.POST['username']
            email = request.POST['email']
            email_subject = 'Activate your account'
            current_site = get_current_site(request)
            email_body = {
                'user': user,
                'domain': current_site.domain,
                'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                'token': account_activation_token.make_token(user),
            }

            link = reverse('activate',
                           kwargs={
                               'uidb64': email_body['uid'],
                               'token': email_body['token']
                           })

            email_subject = 'Activate your account'

            activate_url = 'http://' + current_site.domain + link

            email = EmailMessage(
                email_subject,
                'Hi ' + ', Please the link below to activate your account \n' +
                activate_url,
                '*****@*****.**',
                [email],
            )
            email.send(fail_silently=False)
            messages.success(request, 'Account successfully created')
            return redirect('login')

    context = {'form': form}
    return render(request, 'users/form.html', context)
コード例 #31
0
ファイル: views.py プロジェクト: mudits02/dell-hackathon
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(request,
                                email=user.email,
                                password=raw_password)
            if user is not None:
                login(request, user)
            else:
                print("user is not authenticated")
            return redirect('users:profile')
    else:
        form = SignUpForm()
    return render(request, 'signup.html', {'form': form})
コード例 #32
0
ファイル: views.py プロジェクト: chuagavin7/secprogv2
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.refresh_from_db(
            )  # load the profile instance created by the signal
            user.profile.contact_num = form.cleaned_data.get('contact_num')
            user.profile.shippingAdd = form.cleaned_data.get('shippingAdd')
            user.profile.billingAdd = form.cleaned_data.get('billingAdd')
            user.save()
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=user.username, password=raw_password)
            return redirect('/')
    else:
        form = SignUpForm()
    return render(request, 'users/register.html', {'form': form})
コード例 #33
0
ファイル: views.py プロジェクト: Lucas-Simbiose/Corneteirosv0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            profile = Profile.objects.create(user=user)
            teamdata = TeamData.objects.create(profile=profile)
            TeamCrest.objects.create(teamdata=teamdata)
            TeamShirt.objects.create(teamdata=teamdata)
            # UserTournament.objects.create(teamdata=teamdata)
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('dados_time')
    else:
        form = SignUpForm()
    return render(request, 'signup.html', {'form': form})
コード例 #34
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.refresh_from_db()
            user.save()
            # username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            confirm_email = form.cleaned_data.get('email')
            user = authenticate(username=user.username,
                                password=raw_password,
                                email=confirm_email)
            login(request, user)
            return redirect('home')
    else:
        form = SignUpForm()
    return render(request, 'main/signup.html', {'form': form})
コード例 #35
0
ファイル: views.py プロジェクト: brose73/DU
def register(request):
    """Register a new user"""
    if request.method != 'POST':
        # Display blank registration form
        form = SignUpForm()
    else:
        # Process completed form
        form = SignUpForm(data=request.POST)
        if form.is_valid():
            new_user = form.save()
            #form.save()
            # Log the user in and redirect to home page
            authenticated_user = authenticate(
                username=new_user.username, password=request.POST['password1'])
            login(request, authenticated_user)
            return HttpResponseRedirect(reverse('pizzas:index'))
    context = {'form': form}
    return render(request, 'pizzas/register.html', context)
コード例 #36
0
def signup(request):
    title = 'Signup'

    if request.user.is_authenticated:
        return redirect('index')
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password1')
            with transaction.atomic():
                user = authenticate(username=username, password=password)
                login(request, user)
                last_msg_read = LastMessageRead.objects.create(
                    user=request.user, last_message_read_time=timezone.now())
                last_msg_read.save()
                messages.add_message(
                    request, messages.SUCCESS,
                    'Congratulations, you are now a registered user!')
                return redirect('index')
    else:
        form = SignUpForm()
    return render(request, 'users/signup.html', {'form': form, 'title': title})
コード例 #37
0
ファイル: views.py プロジェクト: richardgiddings/racewithme
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.is_active = False
            user.save()

            current_site = get_current_site(request)
            subject = 'Activate your account'
            message = render_to_string('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),
            })
            queue = django_rq.get_queue('email')
            job = queue.enqueue(user.email_user, subject, message)

            return redirect('account_activation_sent')
    else:
        form = SignUpForm()
    return render(request, 'signup.html', {'form': form})
コード例 #38
0
ファイル: views.py プロジェクト: YaroslavSim/MyFlask
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.is_active = False
            user.save()
            current_site = get_current_site(request)
            subject = 'Activate Your MySite Account'
            token = account_activation_token.make_token(user)
            user_id = urlsafe_base64_encode(force_bytes(user.pk))
            message = render_to_string(
                'users/account_activation_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'user_id': user_id,
                    'token': token
                })
            user.email_user(subject, message)
            return render(request, 'users/account_activation_sent.html')
    else:
        form = SignUpForm()
    return render(request, 'users/signup.html', {'form': form})
コード例 #39
0
ファイル: views.py プロジェクト: MMartinOrtu/wordplease
 def get(self, request):
     form = SignUpForm()
     return render(request, 'users/signup.html', {'form': form})
コード例 #40
0
ファイル: views.py プロジェクト: tommydangerous/skimreads
def new(request):
    """Create new user."""
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            new_user = form.save()
            user = auth.authenticate(email=request.POST.get('email').lower())
            auth.login(request, user)
            # If the user is signing up through ajax form
            pk = request.POST.get('reading')
            if pk:
                reading = get_object_or_404(Reading, pk=pk)
                # Create a dictionary of comment & vote forms for each note
                comment_forms = defaultdict(str)
                vote_forms = defaultdict(str)
                notes = reading.note_set.all()
                for note in notes:
                    d = { 
                        'comment_form': CommentForm(),
                        'note': note,
                    }
                    t = loader.get_template('comments/comment_form.html')
                    v = loader.get_template('votes/vote_form.html')
                    context = RequestContext(request, add_csrf(request, d))
                    comment_forms[str(note.pk)] = t.render(context)
                    vote_forms[str(note.pk)] = v.render(context)
                # Create a dictionary of reply forms for each comment
                reply_forms = defaultdict(str)
                comments = reading.comments()
                for comment in comments:
                    d = {
                        'comment': comment,
                        'reply_form': ReplyForm(),
                    }
                    t = loader.get_template('replies/reply_form.html')
                    context = RequestContext(request, add_csrf(request, d))
                    reply_forms[str(comment.pk)] = t.render(context)
                # Create the note & tag form
                d = {
                        'note_form': NoteForm(),
                        'reading': reading,
                        'static': settings.STATIC_URL,
                }
                favorite_form = loader.get_template('favorites/favorite_form.html')
                header = loader.get_template('header.html')
                note_form = loader.get_template('notes/note_form.html')
                tag_form = loader.get_template('tags/tag_form.html')
                context = RequestContext(request, add_csrf(request, d))
                # Ready all the partials to be outputted as JSON
                data = {
                    'comment_forms': comment_forms,
                    'favorite_form': favorite_form.render(context),
                    'header': header.render(context),
                    'note_form': note_form.render(context),
                    'reply_forms': reply_forms,
                    'success': 'yes',
                    'tag_form': tag_form.render(context),
                    'vote_forms': vote_forms,
                }
                return HttpResponse(json.dumps(data), 
                    mimetype='application/json')
            messages.success(request, 
                """Welcome %s, skim some reads and discover 
                something new""" % user.first_name)
            return HttpResponseRedirect(reverse('readings.views.discover'))
        else:
            pk = request.POST.get('reading')
            if pk:
                data = {
                    'success': 'no',
                }
                return HttpResponse(json.dumps(data), 
                    mimetype='application/json')
    else:
        form = SignUpForm()
    d = {
            'title': 'Welcome',
            'form': form,
    }
    return render_to_response('users/new.html', add_csrf(request, d), 
        context_instance=RequestContext(request))