Exemple #1
0
def renewapikey(request):
    profile = Profile.objects.get(user=request.user)
    profile.regen_apikey()
    profile.save()

    flash.set_flash(request, "ApiKey changed.")
    return HttpResponseRedirect(reverse('ublogging.views.profile'))
Exemple #2
0
def index(request):
    if request.method == 'GET':
        return render_to_response("recover.html", {},
        context_instance=RequestContext(request))

    username = request.POST['username']

    u = User.objects.filter(username=username)
    if len(u):
        u = u[0]
    else:
        return HttpResponseRedirect(reverse('ublogging.views.index'))

    try:
        r = Recover.objects.filter(user=u)[0]
        r.regen_key()
    except:
        r = Recover(user=u)

    r.save()

    mail = u.email
    key = r.key

    subject = "sweetter 3.0 password recovery"
    from_email = settings.MSG_FROM
    vars = {'username': u.username, 'key': key}
    message = settings.RECOVERY_MSG % vars

    to_email = mail
    send_mail(subject, message, from_email, [to_email], fail_silently=False)

    flash.set_flash(request, "Recovery proccess starts, you'll receive a confirmation email")
    return HttpResponseRedirect(reverse('ublogging.views.index'))
Exemple #3
0
def renewapikey(request):
    profile = Profile.objects.get(user=request.user)
    profile.regen_apikey()
    profile.save()

    flash.set_flash(request, "ApiKey changed.")
    return HttpResponseRedirect(reverse('ublogging.views.profile'))
Exemple #4
0
def join(request):
    if request.method == 'POST':
        form = RegisterUserForm(request.POST)
        if form.is_valid():
            user = form.save()

            user.is_active = False
            user.save()

            send_confirmation(user)

            flash.set_flash(request, "Thanks for register, you'll receive a confirmation email")
            form = RegisterUserForm()
            return render_to_response('join.html', {
                'form': form,
            }, context_instance=RequestContext(request))
        else:
            flash.set_flash(request, "Validation error", "error")
            return render_to_response('join.html', {
                'form': form
            }, context_instance=RequestContext(request))
    else:
        form = RegisterUserForm()
        return render_to_response('join.html', {
            'form': form,
        }, context_instance=RequestContext(request))
Exemple #5
0
def join(request):
    if request.method == 'POST':
        form = RegisterUserForm(request.POST)
        if form.is_valid():
            user = form.save()

            user.is_active = False
            user.save()

            send_confirmation(user)

            flash.set_flash(
                request,
                "Thanks for register, you'll receive a confirmation email")
            form = RegisterUserForm()
            return render_to_response('join.html', {
                'form': form,
            },
                                      context_instance=RequestContext(request))
        else:
            flash.set_flash(request, "Validation error", "error")
            return render_to_response('join.html', {'form': form},
                                      context_instance=RequestContext(request))
    else:
        form = RegisterUserForm()
        return render_to_response('join.html', {
            'form': form,
        },
                                  context_instance=RequestContext(request))
Exemple #6
0
def profile(request):
    profile = Profile.objects.get(user=request.user)
    if request.method == 'GET':
        opts = {}
        for p in ublogging.plugins:
            options = [
                OPT(getattr(p, i), request) for i in dir(p)
                if isinstance(getattr(p, i), api.PluginOpt)
            ]
            try:
                opts[p.__plugin_name__] = options
            except:
                pass

        apikey = profile.apikey

        return render_to_response('profile.html', {
            'options': opts,
            'apikey': apikey,
        },
                                  context_instance=RequestContext(request))
    else:
        email = request.POST["email"]
        url = request.POST["url"]
        location = request.POST["location"]
        pw = request.POST["pw"]
        pw2 = request.POST["pw2"]

        if pw and pw != pw2:
            flash.set_flash(request,
                            "Password confirmation fails. Changes not saved",
                            "error")
            return HttpResponseRedirect(reverse('ublogging.views.profile'))
        elif pw:
            request.user.set_password(pw)
            request.user.save()

        profile.email = email
        profile.url = url
        profile.location = location
        profile.save()

        for p in ublogging.plugins:
            options = [
                getattr(p, i) for i in dir(p)
                if isinstance(getattr(p, i), api.PluginOpt)
            ]
            if options:
                for opt in options:
                    try:
                        v = request.POST[opt.id]
                        opt.set(v, request.user.username)
                    except:
                        # checkbox to false
                        opt.set(False, request.user.username)

        flash.set_flash(request, "Preferences saved")
        return HttpResponseRedirect(reverse('ublogging.views.profile'))
Exemple #7
0
def validate(request, apikey):
    try:
        profile = Profile.objects.get(apikey=apikey)
        profile.user.is_active = True
        profile.user.save()
        flash.set_flash(request, "User validated, now you can loggin")
    except:
        flash.set_flash(request, "Invalid apikey", "error")

    return HttpResponseRedirect(reverse('ublogging.views.index'))
Exemple #8
0
def validate(request, apikey):
    try:
        profile = Profile.objects.get(apikey=apikey)
        profile.user.is_active = True
        profile.user.save()
        flash.set_flash(request, "User validated, now you can loggin")
    except:
        flash.set_flash(request, "Invalid apikey", "error")

    return HttpResponseRedirect(reverse('ublogging.views.index'))
Exemple #9
0
def profile(request):
    profile = Profile.objects.get(user=request.user)
    if request.method == 'GET':
        opts = {}
        for p in ublogging.plugins:
            options = [getattr(p, i) for i in dir(p) if isinstance(getattr(p, i), api.PluginOpt)]
            options = [OPT(i.id, i.id.replace('_', ' '), i.get_html_type(), i.get_html_value(request)) for i in options]
            try:
                opts[p.__plugin_name__] = options
            except:
                pass

        apikey = profile.apikey

        return render_to_response('profile.html',
                {'options': opts,
                 'apikey': apikey,
                },
                context_instance=RequestContext(request))
    else:
        email = request.POST["email"]
        url = request.POST["url"]
        location = request.POST["location"]
        pw = request.POST["pw"]
        pw2 = request.POST["pw2"]

        if pw and pw != pw2:
            flash.set_flash(request, "Password confirmation fails. Changes not saved", "error")
            return HttpResponseRedirect(reverse('ublogging.views.profile'))
        elif pw:
            request.user.set_password(pw)
            request.user.save()

        profile.email = email
        profile.url = url
        profile.location = location
        profile.save()

        for p in ublogging.plugins:
            options = [getattr(p, i) for i in dir(p) if isinstance(getattr(p, i), api.PluginOpt)]
            if options:
                for opt in options:
                    try:
                        v = request.POST[opt.id]
                        opt.set(v, request.user.username)
                    except:
                        # checkbox to false
                        opt.set(False, request.user.username)

        flash.set_flash(request, "Preferences saved")
        return HttpResponseRedirect(reverse('ublogging.views.profile'))
Exemple #10
0
def validate(request, key):
    k = Recover.objects.filter(key=key)
    if len(k):
        k = k[0]
    else:
        flash.set_flash(request, "wrong recovery key", "error")
        return HttpResponseRedirect(reverse('ublogging.views.index'))

    u = k.user
    chars = string.letters + string.digits
    newp = ''.join([random.choice(chars) for i in range(11)])

    u.set_password(newp)
    u.save()

    k.delete()

    flash.set_flash(request, "'%s' your new password is '%s', login and change it." % (u.username, newp))
    return HttpResponseRedirect(reverse('ublogging.views.index'))