Beispiel #1
0
def profile_edit(request, group, user_id, profile_edit_template_name = 'sphene/community/profile_edit.html',frm = None):
    if user_id:
        user = get_object_or_404(User, pk = user_id)
    else:
        user = request.user

    if user is None or user != request.user or not user.is_authenticated():
        raise PermissionDenied()

    if request.method == 'POST':
        reqdata = request.POST.copy()
        reqdata.update(request.FILES)
        form = EditProfileForm(user, request.POST, request.FILES)
    else:
        form = EditProfileForm(user)

    if frm:
	mainsite_edit_init_form.send(sender = EditProfileForm,
		                        instance = form,
		                        request = request,
		                        )
    else:
	profile_edit_init_form.send(sender = EditProfileForm,
		                        instance = form,
		                        request = request,
		                        )
    
    if request.method == 'POST':
        if form.is_valid():
            data = form.cleaned_data
            user.first_name = data['first_name']
            user.last_name = data['last_name']

            if user.email != data['email_address']:
                # Require email validation ...
                pass

            if data['new_password']:
                # Check was already made in form, we only need to change the password.
                user.set_password( data['new_password'] )
	
	    if frm:
            	mainsite_edit_save_form.send(sender = EditProfileForm,
                                        instance = form,
                                        request = request,
                                        )
	    else:
            	profile_edit_save_form.send(sender = EditProfileForm,
                                        instance = form,
                                        request = request,
                                        )

            user.save()
            request.user.message_set.create( message = _(u'Successfully changed user profile.') )
            if frm:
		return HttpResponseRedirect('/accounts/profile/%d/'%(user.id,))
	    else:
            	return HttpResponseRedirect( sph_user_profile_link( user ) )

    else:
        form.fields['first_name'].initial = user.first_name
        form.fields['last_name'].initial = user.last_name
        form.fields['email_address'].initial = user.email

    
    """
    form = EditProfileForm( { 'first_name': user.first_name,
                              'last_name': user.last_name,
                              'email_address': user.email,
                              } )
    """
    
    return render_to_response( profile_edit_template_name,
                               { 'user': user,
                                 'form': form,
                                 },
                               context_instance = RequestContext(request) )
Beispiel #2
0
def profile_edit(request, group, user_id):
    requester = request.user

    if user_id:
        user = get_object_or_404(User, pk=user_id)
    else:
        user = requester

    if user is None or user != requester or not requester.is_authenticated:
        if not (requester and requester.is_authenticated and (
                requester.is_superuser or has_permission_flag(requester, 'community_manage_users'))):
            raise PermissionDenied()

    if request.method == 'POST':
        reqdata = request.POST.copy()
        reqdata.update(request.FILES)
        form = EditProfileForm(user, request.POST, request.FILES)
    else:
        form = EditProfileForm(user)

    profile_edit_init_form.send(sender=EditProfileForm,
                                instance=form,
                                request=request,
                                )

    if request.method == 'POST':
        if form.is_valid():
            data = form.cleaned_data
            user.first_name = data['first_name']
            user.last_name = data['last_name']

            if user.email != data['email_address']:
                email_address = data['email_address']
                mail_domain = email_address.split('@')[1]
                logger.info('change e-mail request ip: %s, email: %s' % (get_client_ip(request), email_address))

                s = URLSafeTimedSerializer(getattr(settings, 'EMAIL_CHANGE_SECRET', '87fuhaidfhahfokhh3u'))
                email_change_hash = s.dumps({'email': email_address,
                                             'user_id': user.pk})

                # do not tell spammers that we have not sent email :)
                if mail_domain not in getattr(settings, 'BLACKLISTED_EMAIL_DOMAINS', []):
                    if not group:
                        subject = ugettext(u'Email verification required')
                    else:
                        subject = ugettext(u'Email verification required for site %(site_name)s') % {
                            'site_name': group.get_name()}

                    mail_context = RequestContext(request, {
                        'email': email_address,
                        'baseurl': group.baseurl,
                        'path': sph_reverse('sphene.community.views.email_change_hash', (),
                                            {"email_change_hash": email_change_hash}),
                        'group': group,
                    })
                    text_part = loader.get_template(
                        'sphene/community/accounts/account_email_change.txt') \
                        .render(mail_context)
                    html_part = loader.get_template(
                        'sphene/community/accounts/account_email_change.html') \
                        .render(mail_context)

                    msg = EmailMultiAlternatives(subject, text_part, None, [email_address])
                    msg.attach_alternative(html_part, "text/html")
                    msg.send()
                    messages.info(request, message=ugettext(
                        u'E-mail with verification link has been sent to change your e-mail address.'))

            if data['new_password']:
                # Check was already made in form, we only need to change the password.
                user.set_password(data['new_password'])

            profile_edit_save_form.send(sender=EditProfileForm,
                                        instance=form,
                                        request=request,
                                        )

            user.save()
            messages.success(request, message=ugettext(u'Successfully changed user profile.'))

            return HttpResponseRedirect(sph_user_profile_link(user))

    else:
        form.fields['first_name'].initial = user.first_name
        form.fields['last_name'].initial = user.last_name
        form.fields['email_address'].initial = user.email

    """
    form = EditProfileForm( { 'first_name': user.first_name,
                              'last_name': user.last_name,
                              'email_address': user.email,
                              } )
    """

    return render(
        request,
        'sphene/community/profile_edit.html',
        {'profile_user': user,
         'form': form,
         'is_sphboard': 'sphene.sphboard' in settings.INSTALLED_APPS
        }
    )
Beispiel #3
0
def profile_edit(request, group, user_id):
    requester = request.user

    if user_id:
        user = get_object_or_404(User, pk=user_id)
    else:
        user = requester

    if user is None or user != requester or not requester.is_authenticated:
        if not (requester and requester.is_authenticated and
                (requester.is_superuser
                 or has_permission_flag(requester, 'community_manage_users'))):
            raise PermissionDenied()

    if request.method == 'POST':
        reqdata = request.POST.copy()
        reqdata.update(request.FILES)
        form = EditProfileForm(user, request.POST, request.FILES)
    else:
        form = EditProfileForm(user)

    profile_edit_init_form.send(
        sender=EditProfileForm,
        instance=form,
        request=request,
    )

    if request.method == 'POST':
        if form.is_valid():
            data = form.cleaned_data
            user.first_name = data['first_name']
            user.last_name = data['last_name']

            if user.email != data['email_address']:
                email_address = data['email_address']
                mail_domain = email_address.split('@')[1]
                logger.info('change e-mail request ip: %s, email: %s' %
                            (get_client_ip(request), email_address))

                s = URLSafeTimedSerializer(
                    getattr(settings, 'EMAIL_CHANGE_SECRET',
                            '87fuhaidfhahfokhh3u'))
                email_change_hash = s.dumps({
                    'email': email_address,
                    'user_id': user.pk
                })

                # do not tell spammers that we have not sent email :)
                if mail_domain not in getattr(settings,
                                              'BLACKLISTED_EMAIL_DOMAINS', []):
                    if not group:
                        subject = ugettext(u'Email verification required')
                    else:
                        subject = ugettext(
                            u'Email verification required for site %(site_name)s'
                        ) % {
                            'site_name': group.get_name()
                        }

                    mail_context = RequestContext(
                        request, {
                            'email':
                            email_address,
                            'baseurl':
                            group.baseurl,
                            'path':
                            sph_reverse(
                                'sphene.community.views.email_change_hash',
                                (), {"email_change_hash": email_change_hash}),
                            'group':
                            group,
                        })
                    text_part = loader.get_template(
                        'sphene/community/accounts/account_email_change.txt') \
                        .render(mail_context)
                    html_part = loader.get_template(
                        'sphene/community/accounts/account_email_change.html') \
                        .render(mail_context)

                    msg = EmailMultiAlternatives(subject, text_part, None,
                                                 [email_address])
                    msg.attach_alternative(html_part, "text/html")
                    msg.send()
                    messages.info(
                        request,
                        message=ugettext(
                            u'E-mail with verification link has been sent to change your e-mail address.'
                        ))

            if data['new_password']:
                # Check was already made in form, we only need to change the password.
                user.set_password(data['new_password'])

            profile_edit_save_form.send(
                sender=EditProfileForm,
                instance=form,
                request=request,
            )

            user.save()
            messages.success(
                request,
                message=ugettext(u'Successfully changed user profile.'))

            return HttpResponseRedirect(sph_user_profile_link(user))

    else:
        form.fields['first_name'].initial = user.first_name
        form.fields['last_name'].initial = user.last_name
        form.fields['email_address'].initial = user.email
    """
    form = EditProfileForm( { 'first_name': user.first_name,
                              'last_name': user.last_name,
                              'email_address': user.email,
                              } )
    """

    return render(
        request, 'sphene/community/profile_edit.html', {
            'profile_user': user,
            'form': form,
            'is_sphboard': 'sphene.sphboard' in settings.INSTALLED_APPS
        })
Beispiel #4
0
def profile_edit(request, group, user_id):
    requester = request.user
    
    if user_id:
        user = get_object_or_404(User, pk = user_id)
    else:
        user = requester

    if user is None or user != requester or not requester.is_authenticated():
        if not (requester and requester.is_authenticated() and (requester.is_superuser or has_permission_flag(requester, 'community_manage_users'))):
            raise PermissionDenied()

    if request.method == 'POST':
        reqdata = request.POST.copy()
        reqdata.update(request.FILES)
        form = EditProfileForm(user, request.POST, request.FILES)
    else:
        form = EditProfileForm(user)

    profile_edit_init_form.send(sender = EditProfileForm,
                                instance = form,
                                request = request,
                                )
    
    if request.method == 'POST':
        if form.is_valid():
            data = form.cleaned_data
            user.first_name = data['first_name']
            user.last_name = data['last_name']

            if user.email != data['email_address']:
                # Require email validation ...
                pass

            if data['new_password']:
                # Check was already made in form, we only need to change the password.
                user.set_password( data['new_password'] )

            profile_edit_save_form.send(sender = EditProfileForm,
                                        instance = form,
                                        request = request,
                                        )

            user.save()
            messages.success(request,  message = ugettext(u'Successfully changed user profile.') )
            
            return HttpResponseRedirect( sph_user_profile_link( user ) )

    else:
        form.fields['first_name'].initial = user.first_name
        form.fields['last_name'].initial = user.last_name
        form.fields['email_address'].initial = user.email

    
    """
    form = EditProfileForm( { 'first_name': user.first_name,
                              'last_name': user.last_name,
                              'email_address': user.email,
                              } )
    """
    
    return render_to_response( 'sphene/community/profile_edit.html',
                               { 'profile_user': user,
                                 'form': form,
                                 'is_sphboard':'sphene.sphboard' in settings.INSTALLED_APPS
                                 },
                               context_instance = RequestContext(request) )
Beispiel #5
0
def profile_edit(
        request,
        group,
        user_id,
        profile_edit_template_name='sphene/community/profile_edit.html',
        frm=None):
    if user_id:
        user = get_object_or_404(User, pk=user_id)
    else:
        user = request.user

    if user is None or user != request.user or not user.is_authenticated():
        raise PermissionDenied()

    if request.method == 'POST':
        reqdata = request.POST.copy()
        reqdata.update(request.FILES)
        form = EditProfileForm(user, request.POST, request.FILES)
    else:
        form = EditProfileForm(user)

    if frm:
        mainsite_edit_init_form.send(
            sender=EditProfileForm,
            instance=form,
            request=request,
        )
    else:
        profile_edit_init_form.send(
            sender=EditProfileForm,
            instance=form,
            request=request,
        )

    if request.method == 'POST':
        if form.is_valid():
            data = form.cleaned_data
            user.first_name = data['first_name']
            user.last_name = data['last_name']

            if user.email != data['email_address']:
                # Require email validation ...
                pass

            if data['new_password']:
                # Check was already made in form, we only need to change the password.
                user.set_password(data['new_password'])

            if frm:
                mainsite_edit_save_form.send(
                    sender=EditProfileForm,
                    instance=form,
                    request=request,
                )
            else:
                profile_edit_save_form.send(
                    sender=EditProfileForm,
                    instance=form,
                    request=request,
                )

            user.save()
            request.user.message_set.create(
                message=_(u'Successfully changed user profile.'))
            if frm:
                return HttpResponseRedirect('/accounts/profile/%d/' %
                                            (user.id, ))
            else:
                return HttpResponseRedirect(sph_user_profile_link(user))

    else:
        form.fields['first_name'].initial = user.first_name
        form.fields['last_name'].initial = user.last_name
        form.fields['email_address'].initial = user.email
    """
    form = EditProfileForm( { 'first_name': user.first_name,
                              'last_name': user.last_name,
                              'email_address': user.email,
                              } )
    """

    return render_to_response(profile_edit_template_name, {
        'user': user,
        'form': form,
    },
                              context_instance=RequestContext(request))
Beispiel #6
0
def profile_edit(request, group, user_id):
    requester = request.user

    if user_id:
        user = get_object_or_404(User, pk=user_id)
    else:
        user = requester

    if user is None or user != requester or not requester.is_authenticated():
        if not (requester and requester.is_authenticated() and
                (requester.is_superuser
                 or has_permission_flag(requester, 'community_manage_users'))):
            raise PermissionDenied()

    if request.method == 'POST':
        reqdata = request.POST.copy()
        reqdata.update(request.FILES)
        form = EditProfileForm(user, request.POST, request.FILES)
    else:
        form = EditProfileForm(user)

    profile_edit_init_form.send(
        sender=EditProfileForm,
        instance=form,
        request=request,
    )

    if request.method == 'POST':
        if form.is_valid():
            data = form.cleaned_data
            user.first_name = data['first_name']
            user.last_name = data['last_name']

            if user.email != data['email_address']:
                # Require email validation ...
                pass

            if data['new_password']:
                # Check was already made in form, we only need to change the password.
                user.set_password(data['new_password'])

            profile_edit_save_form.send(
                sender=EditProfileForm,
                instance=form,
                request=request,
            )

            user.save()
            messages.success(
                request,
                message=ugettext(u'Successfully changed user profile.'))

            return HttpResponseRedirect(sph_user_profile_link(user))

    else:
        form.fields['first_name'].initial = user.first_name
        form.fields['last_name'].initial = user.last_name
        form.fields['email_address'].initial = user.email
    """
    form = EditProfileForm( { 'first_name': user.first_name,
                              'last_name': user.last_name,
                              'email_address': user.email,
                              } )
    """

    return render_to_response(
        'sphene/community/profile_edit.html', {
            'profile_user': user,
            'form': form,
            'is_sphboard': 'sphene.sphboard' in settings.INSTALLED_APPS
        },
        context_instance=RequestContext(request))