Exemplo n.º 1
0
def editAccount(request):
    accountEditForm = AccountEditForm(instance=request.user)
    usernameEditForm = UserNameEditForm(instance=request.user)
    usrAccount = Account.getByID(request.user)
    otherInfoEditForm = OtherInfoEditForm(instance=usrAccount)
    passwordChangeForm = PasswordChangeForm()

    if request.method == 'POST' and 'account_update' in request.POST:
        accountEditForm = AccountEditForm(request.POST, instance=request.user)
        if accountEditForm.is_valid():
            accountEditForm.firstName = MySQLdb.escape_string(request.POST['first_name'])
            accountEditForm.last_name = MySQLdb.escape_string(request.POST['last_name'])
            accountEditForm.email = MySQLdb.escape_string(request.POST['email'])
            accountEditForm.save()
            messages.add_message(request, messages.INFO, 'Account was successfully updated.')
            return HttpResponseRedirect('')

    elif request.method == 'POST' and 'username_update' in request.POST:
        usernameEditForm = UserNameEditForm(request.POST, instance=request.user)
        if usernameEditForm.is_valid():
            usernameEditForm.username = MySQLdb.escape_string(request.POST['username'])
            usernameEditForm.save()
            messages.add_message(request, messages.INFO, 'Username was successfully updated.')
            return HttpResponseRedirect('/establishment')

    elif request.method == 'POST' and 'other_info_update' in request.POST:
        otherInfoEditForm = OtherInfoEditForm(request.POST, instance=usrAccount)
        if otherInfoEditForm.is_valid():
            otherInfoEditForm.company = MySQLdb.escape_string(request.POST['company'])
            otherInfoEditForm.address = MySQLdb.escape_string(request.POST['address'])
            otherInfoEditForm.postal_code = MySQLdb.escape_string(request.POST['postal_code'])
            otherInfoEditForm.phone = MySQLdb.escape_string(request.POST['phone'])
            otherInfoEditForm.save()
            messages.add_message(request, messages.INFO, 'Username was successfully updated.')
            return HttpResponseRedirect('/establishment')

    elif request.method == 'POST' and 'password_update' in request.POST:
        password1 = request.POST.get('password', '')
        password2 = request.POST.get('confirm_password', '')

        if password1 != password2:
            messages.add_message(request, messages.ERROR, 'Password did not match.')
            return HttpResponseRedirect('')
        elif len(password1) < 4:
            messages.add_message(request, messages.ERROR, 'Password too short.')
            return HttpResponseRedirect('')
        else:
            u = User.objects.get(username=request.user)
            u.set_password(password1)
            u.save()
            messages.add_message(request, messages.INFO, 'Password successfully updated')
            return HttpResponseRedirect('/establishment')

    return render_to_response('establishment/edit_account.html',
                              {
                                  'accountEditForm': accountEditForm,
                                  'usernameEditForm': usernameEditForm,
                                  'otherInfoEditForm': otherInfoEditForm,
                                  'passwordChangeForm': passwordChangeForm},
                              context_instance=RequestContext(request))
Exemplo n.º 2
0
def profile_edit(request):
    if request.method == "POST":
        form = AccountEditForm(request.POST, request.FILES, instance=request.user)
        if form.is_valid():
            account = form.save()
            return redirect('account_index')
    else:
        form = AccountEditForm(instance=request.user)
        
    return {'form': form
            }
Exemplo n.º 3
0
def account_edit(request, slug):
	"Set a new password for an email account"
	account = Account.objects.get(pk=slug)
	if account.domain.owner() != request.user:
		return redirect('limeade_mail_account_list')		
	form = AccountEditForm(request.POST or None, instance=account)
	if form.is_valid():
		ac = form.save(commit=False)
		ac.set_password(form.cleaned_data['password'])
		ac.save()
		return redirect('limeade_mail_account_list')
	return render_to_response("limeade_mail/account_edit.html",
		{"form": form}, context_instance = RequestContext(request))
Exemplo n.º 4
0
def editAccountInfo(request):
    form = AccountEditForm(instance=request.user)

    if 'ok' in request.POST:
        form = AccountEditForm(request.POST, instance=request.user)
        if form.is_valid():
            form.firstName = MySQLdb.escape_string(request.POST['first_name'])
            form.last_name = MySQLdb.escape_string(request.POST['last_name'])
            form.email = MySQLdb.escape_string(request.POST['email'])
            form.save()
            return HttpResponse(status=201)

    return render_to_response("establishment/accounts/edit_account.html",
                              {'form': form},
                              context_instance=RequestContext(request))
Exemplo n.º 5
0
def accountsettings_view(request):
    if request.method == 'POST':
        form = AccountEditForm(data=request.POST, instance=request.user)
        if form.is_valid():
            password = form.cleaned_data['password1']
            editUser = authenticate(
                username=request.user.username, password=password)
            if editUser is not None:
                form.save()
                return redirect('/profile/')
            else:
                return settingsautherror_view(request, form)
        else:
            return settingsbadfielderror_view(request, form)
    else:
        form = AccountEditForm(initial={'username': request.user.username, 'first_name': request.user.first_name,
                                        'last_name': request.user.last_name, 'email': request.user.email})
        return render(request, 'accountsettings.html', {'form': form})
Exemplo n.º 6
0
def account_edit(request, slug):
    """Change an ftp accounts password.
    
    :param request: the request object
    :param slug: the id of the ftp account
    
    :returns: an edit form template
    """
    account = Account.objects.get(pk=slug)
    if account.vhost.domain.owner() != request.user:
        return redirect('limeade_ftp_account_list')
    form = AccountEditForm(request.POST or None, instance=account)
    if form.is_valid():
        ac = form.save(commit=False)
        ac.set_password(form.cleaned_data['password'])
        ac.save()
        return redirect('limeade_ftp_account_list')
    return render_to_response("limeade_ftp/account_edit.html",
        {"form": form}, context_instance = RequestContext(request))
Exemplo n.º 7
0
def account_edit(request, slug):
    """Set a new password for an email account.
    
    :param request: the request object
    :param slug: the id of the account
    
    :returns: an edit form template
    """
    account = Account.objects.get(pk=slug)
    if account.domain.owner() != request.user:
        return redirect('limeade_mail_account_list')        
    form = AccountEditForm(request.POST or None, instance=account)
    if form.is_valid():
        ac = form.save(commit=False)
        ac.set_password(form.cleaned_data['password'])
        ac.save()
        return redirect('limeade_mail_account_list')
    return render_to_response("limeade_mail/account_edit.html",
        {"form": form}, context_instance = RequestContext(request))