Exemple #1
0
    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)
Exemple #2
0
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"))
Exemple #3
0
    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)
Exemple #4
0
 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)
Exemple #5
0
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})
Exemple #6
0
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)
Exemple #7
0
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)
    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)
Exemple #9
0
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'))
Exemple #10
0
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))