Ejemplo n.º 1
0
 def post(self, request):
     form = UserForm(request.POST, request.FILES, instance=request.user)
     data = {"form": form}
     if form.is_valid():
         form.save()
         return redirect(reverse("users:edit"))
     return render(request, self.template_name, data)
Ejemplo n.º 2
0
def update(request, id):
    employee = UserModel.objects.get(uid=id)
    form = UserForm(request.POST, instance=employee)
    if form.is_valid():
        form.save()
        return redirect("/show")
    return Response(status=status.HTTP_200_OK)
Ejemplo n.º 3
0
def settings(request):
    usr = request.user
    form = UserForm(instance=usr)
    try:
        pno = usr.contactdetails
        # print(pno, usr.contactdetails)
        pform = UpdatePhoneNo(instance=pno)
    except:
        pno = None
        pform = UpdatePhoneNo()

    if request.method == 'POST':
        pform = UpdatePhoneNo(data=request.POST, instance=pno)
        form = UserForm(data=request.POST, instance=usr)
        if pform.is_valid():
            p_obj = pform.save(commit=False)
            p_obj.user = request.user
            p_obj.save()

        if form.is_valid():
            form.save()

        return render(request, 'users/settings.html', locals())

    else:
        return render(request, 'users/settings.html', locals())
Ejemplo n.º 4
0
class UserProfileSettings(TemplateView, CategoryListMixin):
    template_name, form, cities, citys = None, None, None, None

    def get(self, request, *args, **kwargs):
        self.template_name = get_my_template("profile/settings/profile.html",
                                             request.user,
                                             request.META['HTTP_USER_AGENT'])
        if request.user.city:
            self.citys = request.user.city.region.get_cities()
        return super(UserProfileSettings, self).get(request, *args, **kwargs)

    def get_context_data(self, **kwargs):
        from users.forms import UserForm
        from region.models import Region

        context = super(UserProfileSettings, self).get_context_data(**kwargs)
        context["form"] = UserForm()
        context["regions"] = Region.objects.exclude(name="Все регионы",
                                                    is_deleted=True)
        context["citys"] = self.citys
        return context

    def post(self, request, *args, **kwargs):
        from users.forms import UserForm

        self.form = UserForm(request.POST,
                             request.FILES,
                             instance=request.user)
        if request.is_ajax() and self.form.is_valid():
            self.form.save()
            photo_input = request.FILES.get('s_avatar')
            if photo_input:
                request.user.create_s_avatar(photo_input)
            return HttpResponse()
        return super(UserProfileSettings, self).post(request, *args, **kwargs)
Ejemplo n.º 5
0
def user_login(request):

    post = request.POST.copy()

    if request.method == 'POST':

        post['username'] = post['username'].lower()
        email = post['username']
        first_name = post['first_name']

        form = UserForm(post)
        user_profile_form = UserProfileForm(post)

        if email and first_name:
            try:
                user = User.objects.get(email=email)
            except User.DoesNotExist:
                if form.is_valid():
                    user = form.save(commit=False)
                    user.set_password(user.username)
                    user = form.save()

            user = authenticate(username=email, password=email)

            if user is not None:
                if user.is_active:
                    login(request, user)

                    # FIXME
                    post['user'] = user.id
                    user_profile_form = UserProfileForm(post)
                    if user_profile_form.is_valid():
                        try:
                            profile = user.get_profile()
                        except:
                            aux = UserProfile.objects
                            profile, created = aux.get_or_create(user=user)
                        newsletter = user_profile_form.clean()['newsletter']
                        profile.newsletter = newsletter
                        profile.save()

                    try:
                        spectacle = Spectacle.objects.get(status=True)
                        if spectacle.mode == SPECTACLE_MODE_EASY or \
                           spectacle.mode == SPECTACLE_MODE_RESET:
                            url = spectacle.get_easy_show_url()
                        else:
                            url = spectacle.get_hard_show_url()
                        return HttpResponseRedirect(url)
                    except Spectacle.MultipleObjectsReturned:
                        msg = '<h1>%s</h1>' % _('Spectacle not found')
                        return HttpResponseNotFound(msg)
    else:
        form = UserForm()
        user_profile_form = UserProfileForm()

    c = { 'form':form, 'user_profile_form':user_profile_form }

    return render(request, 'login.html', c)
Ejemplo n.º 6
0
def register(request):
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():
            form.save()
    else:
        form = UserForm()
    return render(request, 'users/register.html', context={'form': form})
Ejemplo n.º 7
0
 def post(self, request):
     form = UserForm(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')
     context = {'form': form}
     return render(request, 'users/new_user.html', context)
Ejemplo n.º 8
0
def profile(request):
    form = UserForm(request.POST or None,
                    request.FILES or None,
                    instance=request.user)
    args = {}
    args['form'] = form
    args['article'] = Article.objects.all()
    if request.method == 'POST':
        if form.is_valid():
            form.save()
            return redirect('users:profile')
    return render(request, 'profile.html', args)
Ejemplo n.º 9
0
def edit_profile(request):
    user = request.user

    if request.method == 'POST':
        form = UserForm(request.POST, instance=user)
        if form.is_valid():
            form.save()
            return redirect(reverse('profile'))

    form = UserForm(instance=user)
    context = {'form': form}
    return render(request, 'polls/edit_profile.html', context)
Ejemplo n.º 10
0
 def test_user_form(self):
     """Test the combined User and BucketUser form"""
     form = UserForm(instance=self.user)
     self.assertEqual(type(form.bucket_user_form), BucketUserForm)
     data = {'first_name': 'Foo', 'last_name': 'Bar', 'bio': 'about me'}
     form = UserForm(data=data, instance=self.user)
     self.assertTrue(form.is_valid())
     form.save()
     self.assertEqual(self.user.first_name, 'Foo')
     self.assertEqual(self.user.last_name, 'Bar')
     bucket_user = BucketUser.objects.get(user=self.user)
     self.assertEqual(bucket_user.bio, 'about me')
Ejemplo n.º 11
0
def user_edit(request, pk):
    user = User.get(pk)
    form = UserForm(request.POST or None, instance=user)
    profile = ProfileForm(request.POST or None, instance=get_profile(user))
    if form.is_valid() and profile.is_valid():
        form.save()
        profile.save()
        return HttpResponseRedirect(reverse("user-list"))
    return direct_to_template(request, "user_edit.html", extra_context={
        "form": form,
        "profile": profile,
        "nav": {"selected": "users",},
    })
Ejemplo n.º 12
0
def emp(request):
    if request.method == "POST":
        form = UserForm(json.loads(request.body))  #json handling for POST
        if form.is_valid():
            try:
                form.save()
                return HttpResponse("OK")
            except:
                pass
        else:
            return HttpResponse("Form inValid")
    else:
        form = UserForm()
    return form
Ejemplo n.º 13
0
def registration(request):
    form = None

    if request.method == "POST":
        form = UserForm(request.POST)

        if form.is_valid():
            form.save()

            return redirect(reverse_lazy('user_profile'))
    else:
        form = UserForm()

    return render(request, 'user/registration.html', {'form': form})
Ejemplo n.º 14
0
 def test_user_form(self):
     """Test the combined User and SystersUser form"""
     form = UserForm(instance=self.user)
     self.assertEqual(type(form.systers_user_form), SystersUserForm)
     data = {'first_name': 'Foo',
             'last_name': 'Bar',
             'blog_url': 'http://example.com/'}
     form = UserForm(data=data, instance=self.user)
     self.assertTrue(form.is_valid())
     form.save()
     self.assertEqual(self.user.first_name, 'Foo')
     self.assertEqual(self.user.last_name, 'Bar')
     systers_user = SystersUser.objects.get(user=self.user)
     self.assertEqual(systers_user.blog_url, 'http://example.com/')
Ejemplo n.º 15
0
 def test_user_form(self):
     """Test the combined User and SystersUser form"""
     form = UserForm(instance=self.user)
     self.assertEqual(type(form.systers_user_form), SystersUserForm)
     data = {'first_name': 'Foo',
             'last_name': 'Bar',
             'blog_url': 'http://example.com/'}
     form = UserForm(data=data, instance=self.user)
     self.assertTrue(form.is_valid())
     form.save()
     self.assertEqual(self.user.first_name, 'Foo')
     self.assertEqual(self.user.last_name, 'Bar')
     systers_user = SystersUser.objects.get()
     self.assertEqual(systers_user.blog_url, 'http://example.com/')
Ejemplo n.º 16
0
def users(request):

    form = UserForm()

    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():
            form.save(commit=True)
            return HttpResponseRedirect(reverse("users"))

    users = User.objects.all()
    title = "This page contains an awesome list of users."
    context = {'users': users, 'form': form, 'page_title': title}
    return render(request, 'users/users.html', context=context)
def update_profile(request):
    if request.method == 'POST':
        user_form = UserForm(request.POST)
        profile_form = ProfileForm(request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            u = user_form.save()
            u.set_password(request.POST['password'])
            u.save()
            Profile.objects.get_or_create(
                user=u,
                position=request.POST.get('position'),
                phone=request.POST.get('phone'),
                address=request.POST.get('address'),
                birth_date=request.POST.get('birth_date'),
                joined_date=request.POST.get('joined_date'),
                image=request.FILES.get('image'))
            # profile_form.save()
            messages.success(request,
                             ('Your profile was successfully updated!'))
            return redirect('core:main_dashboard')
        else:
            messages.error(request, ('Please correct the error below.'))
    else:
        user_form = UserForm()
        profile_form = ProfileForm()
        # user_form = UserForm(instance=request.user)
        # profile_form = ProfileForm(instance=request.user.profile)
    return render(request, 'core/register_new_member.html', {
        'user_form': user_form,
        'profile_form': profile_form
    })
Ejemplo n.º 18
0
def register(request):
    if request.method == 'POST':
        form = UserForm(request.POST)
        # print(form.errors.as_data())
        if form.is_valid():
            user = form.save(commit=False)
            user.is_active = False
            pwd = form.cleaned_data['password']
            user.set_password(pwd)
            user.save()
            current_site = get_current_site(request)
            mail_subject = 'Activate your account.'
            message = render_to_string(
                'users/activatemail.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(user.id)),
                    'token': account_activation_token.make_token(user),
                })
            to_email = form.cleaned_data.get('email')
            email = EmailMessage(mail_subject, message, to=[to_email])
            email.send()
            return HttpResponse(
                'Please confirm your email address to complete the registration'
            )
    else:
        form = UserForm()
    return render(request, 'users/registration.html', {'user_form': form})
Ejemplo n.º 19
0
def register_customer(request):
    registered = False
    if request.method == "POST":
        user_form = UserForm(data=request.POST)
        customer_form = CustomerForm(data=request.POST)
        if user_form.is_valid() and customer_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()

            customer = customer_form.save(commit=False)
            customer.user = user

            customer.save()
            registered = True
        else:
            print(user_form.errors, customer_form.errors)
    else:
        user_form = UserForm()
        customer_form = CustomerForm()

    return render(
        request, 'users/register_customer.html', {
            'user_form': user_form,
            'customer_form': customer_form,
            'registered': registered
        })
Ejemplo n.º 20
0
def user_register(request):
    form = UserForm()
    if request.method == 'POST':

        f = UserForm(request.POST)
        #form.permissao = request.POST['permissao']
        valido = False
        if f.is_valid():
            valido = True
            u = f.save(commit=False)
            u.date_joined = datetime.date.today()
            # request.POST['permissao']
            u.permissao = f.cleaned_data['permissao']
            u.save()
        c = {
            'form': form,
        }
        if valido:
            c['sucesso'] = True
        else:
            c['sucesso'] = False
        return render(request, 'users/register.html', c)
        # return redirect('user_login')

    c = {
        'form': form,
    }
    return render(request, 'users/register.html', c)
Ejemplo n.º 21
0
def register(request):
    registed = False

    if request.method == "POST":
        user_form = UserForm(data=request.POST)
        custom_form = CustomUserForm(data=request.POST)
        if user_form.is_valid() and custom_form.is_valid():
            user = user_form.save()
            user.save()

            custom = custom_form.save(commit=False)
            custom.user = user
            custom.save()

            registed = True
            return HttpResponseRedirect(reverse('login'))
        else:
            print(user_form.errors, custom_form.errors)
    else:
        user_form = UserForm()
        custom_form = CustomUserForm

    return render(request, 'users/register.html', {
        'registed': registed,
        'user_form': user_form,
        'custom_form': custom_form
    })
Ejemplo n.º 22
0
def cadastro(request):
    if request.method == 'POST':
        form = UserForm(request.POST)
        form_perfil = PerfilForm(request.POST)
        print(form_perfil.is_valid())
        if form.is_valid() and form_perfil.is_valid():
            user = form.save()

            perfil = form_perfil.save(commit=False)
            perfil.user = user

            perfil.save()

            email = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password1')
            user = authenticate(username=email, password=password)
            auth_login(request, user)
            return redirect('/')
    else:
        form = UserForm(request.POST)
        form_perfil = PerfilForm(request.POST)

    contexto = {
        'form': form,
        'form_perfil': form_perfil,
    }

    return render(request, 'cadastro.html', contexto)
Ejemplo n.º 23
0
def user_register(request):
    if request.method == "GET":
        user_form = UserForm()
        profile_form = ProfileForm()
    elif request.method == "POST":
        user_form = UserForm(request.POST)
        profile_form = ProfileForm(request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            profile.save()

            password = user.password
            # The form doesn't know to call this special method on user.
            user.set_password(password)
            user.save()

            # You must call authenticate before login. :(
            user = authenticate(username=user.username,
                                password=password)
            login(request, user)
            messages.add_message(
                request,
                messages.SUCCESS,
                "Congratulations, {}, on creating your new account! You are now logged in.".format(
                    user.username))
            return redirect('index')
    return render(request, "users/register.html", {'user_form': user_form,
                                                   'profile_form': profile_form})
Ejemplo n.º 24
0
 def post(self, request, *args, **kwargs):
     user_form = UserForm(request.POST)
     user_profile_form = SignUpProfileForm(request.POST)
     if user_form.is_valid() and user_profile_form.is_valid():
         user = user_form.save()
         user_profile = UserProfile(
             user = user,
             city = user_profile_form.data['city'],
             country = user_profile_form.data['country']
         )
         try:
             user_profile.save()
             user = authenticate(
                 username=user_form.data.get('username'),
                 password=user_form.data.get('password1')
             )
             login(self.request, user)
         except:
             transaction.rollback()
         return HttpResponseRedirect(self.success_url)
     else:
         context = {}
         context['user_form'] = user_form
         context['user_profile_form'] = user_profile_form
         context['cities'] = City.objects.all()
         context['countries'] = Country.objects.all()
         return self.render_to_response(context)
Ejemplo n.º 25
0
def register_rater(request):
    if request.method == "POST":
        user_form = UserForm(request.POST)
        rater_form = RaterForm(request.POST)
        if user_form.is_valid() and rater_form.is_valid():
            user = user_form.save()

            rater = rater_form.save(commit=False)
            rater.user = user
            rater.save()

            password = user.password
            user.set_password(password)
            user.save()

            user = authenticate(username=user.username,
                                password=password)

            login(request, user)

            messages.add_message(
                request,
                messages.SUCCESS,
                "Welcome, {}. You have successfully created an account and are now logged in".format(user.username))

            return redirect('top20')
    else:
        user_form = UserForm()
        rater_form = RaterForm()
    return render(request, "users/register.html", {'user_form': user_form,
                                                   'rater_form': rater_form})
Ejemplo n.º 26
0
 def post(self, request):
     if request.GET.get('login'):
         self.post_login(request)
         username = request.POST.get('username')
         password = request.POST.get('password')
         user = authenticate(username=username, password=password)
         if user:
             if user.is_active:
                 login(request, user)
                 return redirect('tasks:index')
         return render(request, 'users/login.html', {'user_form': UserForm(), 'profile_form': ProfileForm()})
     else:
         user_form = UserForm(data=request.POST)
         profile_form = ProfileForm(data=request.POST)
         if user_form.is_valid() and profile_form.is_valid():
             with atomic():
                 user = user_form.save()
                 user.set_password(user.password)
                 user.save()
                 profile = profile_form.save(commit=False)
                 profile.user = user
                 profile.creating = True
                 profile.updating = True
                 thread = Thread()
                 thread.save()
                 profile.thread = thread
                 profile.save()
             login(request, user)
             return redirect('tasks:index')
         else:
             return render(request, 'users/login.html', {'user_form':user_form, 'profile_form': profile_form})
Ejemplo n.º 27
0
def user_register(request):
    if request.method == "GET":
        user_form = UserForm()
        profile_form = ProfileForm()
    elif request.method == "POST":
        user_form = UserForm(request.POST)
        profile_form = ProfileForm(request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            profile.save()

            password = user.password
            # The form doesn't know to call this special method on user.
            user.set_password(password)
            user.save()

            # You must call authenticate before login. :(
            user = authenticate(username=user.username, password=password)
            login(request, user)
            messages.add_message(
                request, messages.SUCCESS,
                "Congratulations, {}, on creating your new account! You are now logged in."
                .format(user.username))
            return redirect('index')
    return render(request, "users/register.html", {
        'user_form': user_form,
        'profile_form': profile_form
    })
Ejemplo n.º 28
0
def Register(request):
    context = RequestContext(request)
    registered = False

    if request.method == 'POST':

        user_form = UserForm(request.POST)
        profile_form = UserProfileForm(request.POST)

        if user_form.is_valid() and profile_form.is_valid():

            user = user_form.save()
            user.set_password(user.password)
            user.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()
            registered = True
            login(request, user)
            return redirect('home')

        else:
            print user_form.errors, profile_form.errors

    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render(request,
            'users/register.html',
            {'user_form': user_form, 'profile_form': profile_form, 'registered': registered})
Ejemplo n.º 29
0
    def post(self, request):
        user_form = UserForm(request.POST)
        profile_form = ProfileForm(request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            profile.save()

            password = user.password
            user.set_password(password)
            user.save()

            user = authenticate(username=user.username,
                                password=password)

            login(self.request, user)
            messages.add_message(
                request,
                messages.SUCCESS,
                "Account Successfully Created.")
            return redirect("/")

        else:
            return render(request, "users/register.html", {"form1": user_form, "form2": profile_form})
Ejemplo n.º 30
0
def accept_invite(request, token):
    invite = get_object_or_404(Invite, token=token)
    if not invite.is_tokened:
        invite.is_tokened = True
        invite.save()
        user = User.objects.filter(email=invite.email)
        if user.exists():
            _create_event_member(user[0], invite.event)
            login(request, user[0])
            return redirect('post_details', invite.event.id)
        else:
            form = UserForm()
            if request.method == 'POST':
                form = UserForm(request.POST)
                if form.is_valid():
                    password = form.cleaned_data['password']
                    email = form.cleaned_data['email']
                    member = form.save()
                    _create_event_member(member, invite.event)

                    user = authenticate(email=email, password=password)

                    if user is not None:
                        login(request, user)
                        return redirect('post_details', invite.event.id)
            return render(request, 'users/signup.html', {'form': form})
    else:
        raise Http404("Token does not exist")
Ejemplo n.º 31
0
def register(request):
    activate(request.LANGUAGE_CODE)
    if not isinstance(request.user, models.AnonymousUser):
        logout(request)

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserExtendedForm(data=request.POST)
        user_tz = request.POST.get('timezone')
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            profile = profile_form.save(commit=False)
            profile.user = user
            if user_tz:
                profile.timezone = user_tz
            try:
                profile.save()
            except:
                raise ValidationError("Can't save user to the database!")
            user.save()
            return HttpResponseRedirect(reverse('users:login'))
    else:
        user_form = UserForm()
        profile_form = UserExtendedForm()

    return render(
        request, 'users/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'timezones': pytz.common_timezones,
            'def_timezone': settings.DEF_USER['timezone']
        })
Ejemplo n.º 32
0
def register(request):
    """ Register a new user """

    # Set registered to false by default
    registered = False
    if request.method != 'POST':  # This SHOULD always be post
        form = UserForm()
        account_form = UserAccountForm()
    else:
        form = UserForm(data=request.POST)
        account_form = UserAccountForm(data=request.POST)

        if form.is_valid() and account_form.is_valid():
            new_user = form.save()
            new_user.set_password(new_user.password)
            new_user.save()
            account = account_form.save(commit=False)
            account.user = new_user
            account.save()

            registered = True
            login(request, new_user)
            return redirect('book_keeping:index')
        else:
            print(form.errors, account_form.errors)
    context = {
        'form': form,
        'account_form': account_form,
        'registered': registered
    }
    return render(request, 'users/register.html', context)
Ejemplo n.º 33
0
def _update(request, user):
    was_superuser = user.is_superuser
    
    form = UserForm(instance = user, data = request.PUT)
    if form.is_valid():
        user = form.save()
        
        # Check if modified user is the last superuser in which case
        # his super-user status must remain True
        if was_superuser \
        and not user.is_superuser \
        and not User.objects.filter(is_superuser = True):
            message = INFO_MSG%"Au moins un utilisateur doit être super-utilisateur."
            request.user.message_set.create( message = message )
            user.is_superuser = True
            user.save()
        
        # Changes have been made.
        message = SUCCESS_MSG % "Modification effectuée avec succès."
        request.user.message_set.create( message = message )
        if request.user.is_superuser:
            return redirect( 'user_collection' )
        else:
            return redirect( 'user_edit', request.user.id )
    else:
        message = ERROR_MSG % 'Le formulaire est invalide, veuillez corriger les erreurs suivantes.'
        request.user.message_set.create( message = message )
        return direct_to_template(request, "users/edit.html", {
            'user': user,
            'form': form
        })
Ejemplo n.º 34
0
def register(request):

	Context = RequestContext(request)

	if request.method == 'POST': #user bilgilerini girmis kayit ol butonuna basmis.
		user_form = UserForm(data = request.POST)
		profile_form = UserProfileForm(data = request.POST)

		if user_form.is_valid() and profile_form.is_valid():
			user = user_form.save()
			user.set_password(user.password)
			user.save()
            #registered = True

			profile = profile_form.save(commit = False)
			profile.user = user

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

			profile.save()
			return render(request, 'users/register_success.html')

		else:
			print user_form.errors, profile_form.errors

	else: # henuz yeni register ekrani goren user icin
		user_form = UserForm()
		profile_form = UserProfileForm()
        
        return render_to_response(
		'users/registration.html',
		{'user_form':user_form, 'profile_form':profile_form}, Context)
Ejemplo n.º 35
0
def register(request):
    form = UserForm(request.POST or None)
    if form.is_valid():
        instance = form.save(commit=False)
        instance.save()
    context = {'form': form}
    return render(request, 'index.html', context)
Ejemplo n.º 36
0
def register(request):
    registered  = False

    if request.method == 'POST':
        user_form = UserForm(data = request.POST)
        profile_form = UserProfileInfoForm(data= request.POST)

        if user_form.is_valid() and profile_form.is_valid() :
            user = user_form.save()
            user.save()

            profile = profile_form.save(commit= False)
            profile.user = user
            profile.save()

            registered = True

        else:
            print(user_form.errors,profile_form.errors)
    else:
        user_form =UserForm()
        profile_form = UserProfileInfoForm()
    

    context ={
        'registered': registered,
        'user_form': user_form,
        'profile_form': profile_form,
    }
    
    return render(request, 'users/registration.html', context)
Ejemplo n.º 37
0
def SignUp(request):

    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():

            user = user_form.save()
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user

            if 'profile_pic' in request.FILES:
                profile.profile_pic = request.FILES['profile_pic']
            profile.save()

            registered=True

        else:
            print(user_form.errors, profile_form.errors)

    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    return render(request, 'signup.html',{'user_form':user_form,'profile_form':profile_form, 'registered':registered})
Ejemplo n.º 38
0
 def create(self, request, *args, **kwargs):
     registered = False
     flag =1
     user_form = UserForm(data=request.POST)
     profile_form = UserProfileForm(data=request.POST)
     User = get_user_model()
     if user_form.is_valid() and profile_form.is_valid():
         for User in User.objects.filter():
             if user_form.cleaned_data['email'] == User.email:
                 flag =0
                 user_form.cleaned_data['username'] = "******"
                 print("This mail address already exists!")
         if flag ==1:
             user = user_form.save()
             print("user saved")
             user.set_password(user.password)
             user.save()
             profile = profile_form.save(commit=False)
             profile.user = user
             if 'profile_pic' in request.FILES:
                 print('found it')
                 profile.profile_pic = request.FILES['profile_pic']
             profile.save()
             registered = True
         else :
             print("not-saved")
     else:
         print(user_form.errors,profile_form.errors)
     return render(request,'users/registration.html',
                         {'user_form':user_form,
                        'profile_form':profile_form,
                        'registered':registered,
                        'flag':flag})
Ejemplo n.º 39
0
def register(request):

    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)

        if user_form.is_valid():
            user = user_form.save()

            user.set_password(user.password)
            user.save()

            registered = True
            return render(request, 'login.html', {})

        else:
            print(user_form.errors)

    else:
        user_form = UserForm()

    # Render the template depending on the context.
    return render(request, 'register.html', {
        'user_form': user_form,
        'registered': registered
    })
Ejemplo n.º 40
0
def register(request):
    res = create_exception(
        request, __name__, exception="unknown request method")

    if request.method == "POST":
        form = UserForm(request.POST)
        if form.is_valid():
            user_obj = form.save()
            user_obj.first_name = user_obj.first_name.capitalize()
            user_obj.last_name = user_obj.last_name.capitalize()

            username = user_obj.first_name.lower(
            )[0] + user_obj.last_name.lower() + str(randint(1, 10000))
            user_obj.username = username
            user_details_obj = Personal_Info(username=username, date_of_birth=form.cleaned_data['date_of_birth'],
                                             pin_code=form.cleaned_data['pin_code'], address=form.cleaned_data['address'],
                                             city=form.cleaned_data['city'], email_verified=False)
            try:
                user_obj.save()
                user_details_obj.save()
                print("{} : {} {} added".format(
                    username, user_obj.first_name, user_obj.last_name))
            except Exception as e:
                print(e)
                res = create_exception(request, __name__, exception=e)
            else:
                res = redirect('dashboard')
        else:
            res = create_exception(request, __name__, str(
                ValueError("form data in request not valid")))
    elif request.method == "GET":
        empty_form = UserForm()
        res = render(request, "users/register.html", {"form": empty_form, "helper": empty_form.get_helper()})

    return res
Ejemplo n.º 41
0
def signup(request):
    form=UserForm(request.POST or None)
    if form.is_valid():
        save_it=form.save(commit=False)
        save_it.save()
        messages.success(request,'Thank you for Joining us')
        return HttpResponseRedirect('/signup/')
    return render_to_response("signup.html",locals(),context_instance=RequestContext(request))
Ejemplo n.º 42
0
def user_edit(request, pk):
    user = User.get(pk)
    form = UserForm(request.POST or None, instance=user)
    profile = ProfileForm(request.POST or None, instance=get_profile(user))
    if form.is_valid() and profile.is_valid():
        form.save()
        profile.save()
        return HttpResponseRedirect(reverse("user-list"))
    return direct_to_template(request,
                              "user_edit.html",
                              extra_context={
                                  "form": form,
                                  "profile": profile,
                                  "nav": {
                                      "selected": "users",
                                  },
                              })
Ejemplo n.º 43
0
def register(request):
    context = RequestContext(request)

    # Set boolean to false
    registered = False

    # if request is post
    if request.method == 'POST':
        # Initialize forms to collect user data
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # create user and userprofile classes to add data
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()

            user.set_password(user.password)
            user.save()
          
            profile = profile_form.save(commit=False)
            profile.user = user

            # retrieve profile registration information
            if 'first name' in request.FILES:
            	profile.fistName = request.FILES['first name']

            if 'last name' in request.FILES:
            	profile.lastName = request.FILES['last name']

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

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

            if 'are you a teacher?' in request.FILES:
            	profile.isTeacher = request.FILES['are you a teacher?']

            profile.save()
            registered = True
            
            # logs you in if your registration details check out
            user = authenticate(username=request.POST['username'], password=request.POST['password'])
            login(request, user)
            return HttpResponseRedirect('/forum/')
        else:
            print user_form.errors, profile_form.errors

    # if request is not post
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render_to_response(
            'users/register.html',
            {'user_form': user_form, 'profile_form': profile_form, 'registered': registered},
            context)
Ejemplo n.º 44
0
def registration(request):
    context = RequestContext(request)

    # A boolean value for telling the template whether the registration was successful.
    # Set to False initially. Code changes value to True when registration succeeds.
    registered = False

    # If it's a HTTP POST, we're interested in processing form data.
    if request.method == 'POST':
        # Attempt to grab information from the raw form information.
        # Note that we make use of both UserForm and UserProfileForm.
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # If the two forms are valid...
        if user_form.is_valid() and profile_form.is_valid():
            # Save the user's form data to the database.
            # Since we need to set the user attribute ourselves, we set commit=False.
            # This delays saving the model until we're ready to avoid integrity problems.
 
            user = user_form.save(commit=False)

           # Now we hash the password with the set_password method.
            user.set_password(user.password)

            profile = profile_form.save(commit=False)

            # Did the user provide a profile picture?
            # If so, we need to get it from the input form and put it in the UserProfile model.
            if 'avatar' in request.FILES:
                profile.avatar = request.FILES['avatar']

            # Now we save the UserProfile and User model instance.
            user.save()
            profile.user = user
            profile.save()
            
            # Update our variable to tell the template registration was successful.
            messages.success(request, _('Registration successful, you can log in.'))
            return HttpResponseRedirect(reverse('users:login'))
 


        # Invalid form or forms - mistakes or something else?
        # Print problems to the terminal.
        # They'll also be shown to the user.
        else:
            print user_form.errors, profile_form.errors

    # Not a HTTP POST, so we render our form using two ModelForm instances.
    # These forms will be blank, ready for user input.
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    # Render the template depending on the context.
    return render_to_response( 'users/registration.html', {'user_form': user_form, 'profile_form': profile_form, 'registered': registered}, context)
Ejemplo n.º 45
0
def user_edit(request):
    if request.method == 'POST':
        form = UserForm(request.POST, instance=request.user)
        if form.is_valid():
            form.save()
            messages.add_message(request, messages.SUCCESS,
                                 _("Your data has been successfully saved."))
            return redirect('home')
    else:
        form = UserForm(instance=request.user)

    context = {
        'cancel_url': reverse('user_profile'),
        'form': form,
    }

    return render_to_response('accounts/edit.jade', context,
                              context_instance=RequestContext(request))
Ejemplo n.º 46
0
def user_edit(request, pk):
    form = UserForm(request.POST or None, instance=User.get(pk))
    if form.is_valid():
        obj = form.save(commit=False)
        obj.save()
        return HttpResponseRedirect(reverse("user-list"))
    return direct_to_template(request, "user_edit.html", extra_context={
        "form": form,
        "nav": {"selected": "users",},
    })
Ejemplo n.º 47
0
def edit_profile(request, username):
    user = get_object_or_404(User, username=username)
    profile = user.get_profile()

    if request.user.pk != user.pk and request.user.has_perm("user.can_change") == False:
        return HttpResponseNotAllowed("You cannot edit this profile.")

    if request.method == "POST":
        this_user_form = UserForm(request.POST, instance=user)
        if this_user_form.is_valid():
            this_user_form.save()
            return redirect(profile)
    else:
        this_user_form = UserForm(instance=user)

    return render_to_response(
        "users/edit-profile.html",
        {"this_user": user, "this_user_form": this_user_form},
        context_instance=RequestContext(request),
    )
Ejemplo n.º 48
0
 def post(self, request):
     uform = UserForm(data=request.POST)
     if uform.is_valid():
         user = uform.save()
         user.set_password(user.password)
         user.save()
         self.registered = True
     else:
         print uform.errors
     context = self.get_context_data()
     context['registered'] = self.registered
     return render(request, self.template_name, context)
Ejemplo n.º 49
0
def register(request):
    # Initial value set to False. Code changes value to True when registration succeeds.
    registered = False

    if request.method == 'POST':
        # Get form information.
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)
        picture_form = PictureForm(data=request.POST)

        # If the forms are valid
        if user_form.is_valid() and profile_form.is_valid():
            # Save the user's form data to the database.
            user = user_form.save()

            # Hash the password with the set_password method.
            user.set_password(user.password)
            user.save()

            # Sort out the UserProfile instance.
            profile = profile_form.save(commit=False)
            image = picture_form.save(commit=False)
            profile.user_extended = user
            image.user = user

            # User provides a photo
            if 'file' in request.FILES:
                image.file = request.FILES['file']

            # Save the UserProfile model instance.
            profile.save()
            image.save()

            # Update our variable to tell the template registration was successful.
            registered = True
            return HttpResponseRedirect('/login/')

        # Print problems to the terminal, show to the user.
        else:
            print(user_form.errors, profile_form.errors)

    # Blank forms, ready for user input.
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()
        picture_form = PictureForm()

    # Render the template depending on the context.
    return render(request,
            'register.html',
            {'user_form': user_form, 'profile_form': profile_form, 'registered': registered,
             'picture_form': picture_form} )
Ejemplo n.º 50
0
def register(request):
    #Get the request context
    context = RequestContext(request)

    #Registration success/failure boolean
    registered = False

    #If HTTP POST, process form
    if request.method == 'POST':
        #Grab raw data from UserForm and UserProfileForm
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        #If the two forms are valid...
        if user_form.is_valid() and profile_form.is_valid():
            #Save the user's form data to the database
            user = user_form.save()

            #Hash the password and update the user object
            user.set_password(user.password)
            user.save()

            #Save UserProfile data
            profile = profile_form.save(commit=False)
            profile.user = user

            #Did the user provide a profile image
            if 'profile_image' in request.FILES:
                profile.profile_image = request.FILES['profile_image']

            #Save the UserProfile model instance
            profile.save()

            #Set registration boolean to true
            registered = True

        #Invalid forms?
        else:
            print(user_form.errors, profile_form.errors)

    #Not a HTTP POST? Render blank forms
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    #Render the template
    return render_to_response(
        'users/register.html',
        {'user_form': user_form, 'profile_form': profile_form, 'registered':registered},
        context)
Ejemplo n.º 51
0
def profile(request, slug):
    try:
        user = User.objects.get(slug=slug)
    except:
        raise Http404
    if request.user == user:
        # own profile
        if request.method == "POST":
            # if the form as been submitted
            form = UserForm(request.POST,
                            instance=request.user)
            if form.is_valid():
                form.save()
                url = reverse("user",
                              kwargs={"slug": request.user.slug})
                return HttpResponseRedirect(url)
            else:
                for field, error in form.errors.items():
                    messages.add_message(request, messages.ERROR, error)
                return render(request,
                              "own_profile.html",
                              {"profile": user,
                               "form": form})
        form = UserForm(instance=request.user)
        return render(request,
                      "own_profile.html",
                      {'profile': user,
                       'form': form})
    elif user.hasProfile:
        # another's (public) profile
        return render(request,
                      "profile.html",
                      {'profile': user})
    else:
        return render(request,
                      "no_profile.html",
                      {"profile": user})
Ejemplo n.º 52
0
def signup(request):
    template = 'users/signup.html'
    context_instance = RequestContext(request)

    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():
            new_user = form.save(commit=False)
            #Encript password before save it in the DB
            new_user.password = make(new_user.password)
            new_user.save()
            return HttpResponseRedirect('/users/login/')
    else:
        form = UserForm()

    return render_to_response(template, {'form': form}, context_instance)
Ejemplo n.º 53
0
def register(request):
  if request.method == "POST":
    user_form = UserForm(request.POST)
    if user_form.is_valid():
      user = user_form.save()
      password = make_password(request.POST['password'])
      user.password = password
      user.save()
      profile = UserProfile()
      profile.user = user
      api_key = hashlib.md5((user.username + str(datetime.now())).encode('utf-8')).hexdigest()
      profile.api_key = api_key
      print("*"*20)
      print(api_key)
      profile.save()
      return redirect('user_home', username=user)
  return HttpResponse("Couldn't register this user")
Ejemplo n.º 54
0
def register(request):
    # init vars
    register_failure = []
    registered = False

    if request.method == 'POST':
        # get main user form
        user_form = UserForm(data=request.POST)
        # get user profile form
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            # save main user details
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            # use the user details and save profile form
            profile = profile_form.save(commit=False)
            profile.user = user
            profile.save()
            # use the user details and create oauth
            new_oauth = Oauth(user=user)
            new_oauth.save()

            # login the new user
            user_login = auth.authenticate(username=request.POST.get('username'),password=request.POST.get('password'))
            loggedin = auth.login(request, user_login) 
            if loggedin:
                registered = True

        else:
            print user_form.errors, profile_form.errors


    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render(request,
            'users/register.html',
            {'user_form': user_form, 'profile_form': profile_form, 'registered': registered})
Ejemplo n.º 55
0
def edit(request, pk):
    """Edit or create an user"""

    try:
        object = User.objects.get(pk=pk)
    except:
        object = User()

    if request.method == 'POST':  # If the form has been submitted...
        form = UserForm(request.POST, instance=object)

        if form.is_valid():  # If the form is valid
            object = form.save()

            messages.success(request, _('The user has been saved.'))

            return redirect('users.views.list')
    else:
        form = UserForm(instance=object)

    return render(request, 'users/users/edit.html', {'form': form})
Ejemplo n.º 56
0
def edit_perfil(request):
    perfil = Perfil.objects.get(usuario = request.user)
    if request.method == 'POST':
        formperfil = PerfilEditForm(request.POST, request.FILES, instance=perfil)
        formuser = UserForm(request.POST, instance=request.user)
        if formuser.is_valid() and formperfil.is_valid():
            p = formperfil.save()
            u = formuser.save()
            p.user = request.user
            p.save()
            msm = "Perfil Completado Correctamente"
            messages.add_message(request, messages.INFO, msm)
            return HttpResponseRedirect(reverse(index_perfil))
    else:
        formperfil = PerfilEditForm(instance=perfil)
        formuser = UserForm(instance=request.user)
    return render(request, 'users/edit_perfil.html', {
        'formperfil':formperfil,
        'formuser':formuser,
        'perfil':perfil,
    })
Ejemplo n.º 57
0
def New(request):
    template_file = "user-new.html"
    context = RequestContext(request)

    form = UserForm(request.POST or None, request.FILES or None)
    if form.is_valid():
        mymodel = form.save()

        msg = u"User successfully created"
        messages.add_message(request, messages.SUCCESS, msg)
        return redirect("users:home")

    params = {
        'form': form,
    }

    return render_to_response (
        template_file,
        params,
        context_instance = context
    )
Ejemplo n.º 58
0
def register(request):
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        if user_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()

            # Login and redirect to root url
            user = auth.authenticate(
                username=request.POST['username'],
                password=request.POST['password'])
            auth.login(request, user)
            return HttpResponseRedirect('/')
    else:
        user_form = UserForm()

    return render(
        request,
        'users/register.html', {
            'form': user_form,
        })
Ejemplo n.º 59
0
def Edit(request,user_id):
    template_file = "user-edit.html"
    context = RequestContext(request)

    obj = User.objects.get(pk=user_id)

    form = UserForm(request.POST or None, request.FILES or None,instance=obj)
    if form.is_valid():
        mymodel = form.save()

        msg = u"User saved successfully"
        messages.add_message(request, messages.SUCCESS, msg)
        return redirect("users:home")

    params = {
        'form': form,
        'user_id': user_id,
    }

    return render_to_response (
        template_file,
        params,
        context_instance = context
    )
Ejemplo n.º 60
0
def register(request):
    # Like before, get the request's context.
    context = RequestContext(request)

    # A boolean value for telling the template whether the registration was successful.
    # Set to False initially. Code changes value to True when registration succeeds.
    registered = False

    # If it's a HTTP POST, we're interested in processing form data.
    if request.method == 'POST':
        # Attempt to grab information from the raw form information.
        # Note that we make use of both UserForm and UserProfileForm.
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # If the two forms are valid...
        if user_form.is_valid() and profile_form.is_valid():
        
            # Save the user's form data to the database.
            user = user_form.save()

            # Now we hash the password with the set_password method.
            # Once hashed, we can update the user object.
            user.set_password(user.password)
            user.save()

            # Now sort out the UserProfile instance.
            # Since we need to set the user attribute ourselves, we set commit=False.
            # This delays saving the model until we're ready to avoid integrity problems.
            profile = profile_form.save(commit=False)
            restaurant_boolean = find_restaurant(context, profile.address, profile.city, profile.state)

            if restaurant_boolean[0] == True:
            	profile.restaurant = restaurant_boolean[1]

            else:
            	return HttpResponse("Unfortunately, we are not currently serving your area. Please try again soon.")

            profile.user = user
            print profile.address


            # Now we save the UserProfile model instance.
            profile.save()
            r0 = randint(0, 9)
            r1 = randint(0, 9)
            r2 = randint(0, 9)
            r3 = randint(0, 9)
            str_sec = str(r0)+str(r1)+str(r2)+str(r3)

            account_sid = "ACd2d6a002416aad11df6d7b3d529506b2"
            auth_token = "616085bee1e2c14db70339a86bfa9dda"
            client = TwilioRestClient(account_sid, auth_token)
            message = client.sms.messages.create(body=user.first_name + ", thanks for signing up for Dormserv! Your code is " + str_sec, to= profile.phone, from_="+19146185355") # Replace with your Twilio number
            registered = True
            return render_to_response('confirm_account.html',
                {'profile': profile.id, 'user':profile.user.id, 'str_sec':str_sec},
                context)

        # Invalid form or forms - mistakes or something else?
        # Print problems to the terminal.
        # They'll also be shown to the user.
        else:
            print user_form.errors, profile_form.errors
    # Not a HTTP POST, so we render our form using two ModelForm instances.
    # These forms will be blank, ready for user input.
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    # Render the template depending on the context.
    return render_to_response(
            'register.html',
            {'user_form': user_form, 'profile_form': profile_form, 'registered': registered},
            context)