Esempio n. 1
0
def setup(request):
    sans_facebook = True if request.GET.has_key(
        'sans_facebook') and request.GET['sans_facebook'] else False
    redirect_to = request.GET.get('redirect_to', "/")

    form = CreateAccountForm(initial={
        'redirect_to': redirect_to,
    })
    if request.POST:
        sans_facebook = True if request.POST.has_key(
            'sans_facebook') and request.POST['sans_facebook'] else False
        form = CreateAccountForm(request.POST)
        if form.is_valid():
            u = User()
            u.bio = form.cleaned_data['bio']
            u.birth_year = form.cleaned_data['birth_year']
            u.email = u.long_email = form.cleaned_data['email']
            u.fb_access_token = form.cleaned_data['fb_access_token']
            u.gender = form.cleaned_data['gender']
            u.first_name = form.cleaned_data['first_name']
            u.last_name = form.cleaned_data['last_name']
            u.facebook_id = form.cleaned_data['fbid']
            u.bio = u.bio.encode('utf-8') if u.bio else ""
            u.first_name = u.first_name.encode('utf-8') if u.first_name else ""
            u.last_name = u.last_name.encode('utf-8') if u.last_name else ""
            if form.cleaned_data['location_data']:
                u.location = Location.get_or_create(
                    form.cleaned_data['location_data'])
            u.next_email_time = datetime.datetime.now() + timedelta(days=1)
            u.username = create_handle('%s%s' % (u.first_name, u.last_name))
            u.password = hash_password(form.cleaned_data['password'])
            u.save()

            Subscription.get_or_create(user=u, pub_id=NOTIFICATIONS_PUB)

            #Post to Facebook
            if form.cleaned_data['post_to_facebook']:
                fb_helpers.post_joined_to_wall(u)

            cache.put_on_handle(u, u.username)

            redirect_to = form.cleaned_data['redirect_to'] or '/'
            #perform for all that login magic that happens under the covers
            attempt_login(request, u.username, form.cleaned_data["password"])
            return set_auth_cookies(HttpResponseRedirect(redirect_to), u)

    return render(
        request, 'user/setup.html', {
            'title': 'Setup your account',
            'create_form': form,
            'sans_facebook': sans_facebook,
        })
Esempio n. 2
0
def login_permalink(request):
    form = LoginForm()
    post_auth_action = request.GET.get('post_auth_action', 'redirect');
    redirect_to = request.GET.get('redirect_to', None)
    redirect_to = redirect_to if redirect_to != "/login" else None
    if request.POST:
        form = LoginForm(request.POST)
        if form.is_valid():
            email_or_username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            redirect_to = form.cleaned_data['redirect_to']
            post_auth_action = form.cleaned_data['post_auth_action']

            if redirect_to == None or redirect_to == 'None':
                redirect_to = "/"

            user = attempt_login(request, email_or_username, password)
            if user is not None and user.is_active:
                response = HttpResponseRedirect(redirect_to)
                if post_auth_action == 'close':
                    response = render(request, 'util/closing_window.html')

                return set_auth_cookies(response, user)
            else:
                form._errors["username"] = form.error_class(['The username and password you entered are incorrect.'])

    return render(request, 'user/login.html', {
        'title' : 'Login',
        'redirect_to' : redirect_to,
        'post_auth_action' : post_auth_action,
        'login_form': form})
Esempio n. 3
0
def login_permalink(request):
    form = LoginForm()
    post_auth_action = request.GET.get('post_auth_action', 'redirect')
    redirect_to = request.GET.get('redirect_to', None)
    redirect_to = redirect_to if redirect_to != "/login" else None
    if request.POST:
        form = LoginForm(request.POST)
        if form.is_valid():
            email_or_username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            redirect_to = form.cleaned_data['redirect_to']
            post_auth_action = form.cleaned_data['post_auth_action']

            if redirect_to == None or redirect_to == 'None':
                redirect_to = "/"

            user = attempt_login(request, email_or_username, password)
            if user is not None and user.is_active:
                response = HttpResponseRedirect(redirect_to)
                if post_auth_action == 'close':
                    response = render(request, 'util/closing_window.html')

                return set_auth_cookies(response, user)
            else:
                form._errors["username"] = form.error_class(
                    ['The username and password you entered are incorrect.'])

    return render(
        request, 'user/login.html', {
            'title': 'Login',
            'redirect_to': redirect_to,
            'post_auth_action': post_auth_action,
            'login_form': form
        })
Esempio n. 4
0
def setup(request):
    sans_facebook = True if request.GET.has_key('sans_facebook') and request.GET['sans_facebook'] else False
    redirect_to = request.GET.get('redirect_to', "/")

    form = CreateAccountForm(initial={'redirect_to': redirect_to,})
    if request.POST:
        sans_facebook = True if request.POST.has_key('sans_facebook') and request.POST['sans_facebook'] else False
        form = CreateAccountForm(request.POST)
        if form.is_valid():
            u = User()
            u.bio = form.cleaned_data['bio']
            u.birth_year = form.cleaned_data['birth_year']
            u.email = u.long_email = form.cleaned_data['email']
            u.fb_access_token = form.cleaned_data['fb_access_token']
            u.gender = form.cleaned_data['gender']
            u.first_name = form.cleaned_data['first_name']
            u.last_name = form.cleaned_data['last_name']
            u.facebook_id = form.cleaned_data['fbid']
            u.bio = u.bio.encode('utf-8') if u.bio else ""
            u.first_name = u.first_name.encode('utf-8') if u.first_name else ""
            u.last_name = u.last_name.encode('utf-8') if u.last_name else ""
            if form.cleaned_data['location_data']:
                u.location = Location.get_or_create(form.cleaned_data['location_data'])
            u.next_email_time = datetime.datetime.now() + timedelta(days = 1)
            u.username = create_handle('%s%s' % (u.first_name, u.last_name))
            u.password = hash_password(form.cleaned_data['password'])
            u.save()

            Subscription.get_or_create(user = u, pub_id = NOTIFICATIONS_PUB)

            #Post to Facebook
            if form.cleaned_data['post_to_facebook']:
                fb_helpers.post_joined_to_wall(u)

            cache.put_on_handle(u, u.username)

            redirect_to = form.cleaned_data['redirect_to'] or '/'
            #perform for all that login magic that happens under the covers
            attempt_login(request, u.username, form.cleaned_data["password"])
            return set_auth_cookies(HttpResponseRedirect(redirect_to), u)

    return render(request, 'user/setup.html', {
        'title' : 'Setup your account',
        'create_form' : form,
        'sans_facebook': sans_facebook,
        })
Esempio n. 5
0
def reset_password(request, reset_id):
    error = None
    if request.method == 'POST' and 'password' in request.POST and request.POST['password']:
        try:
            p = PasswordResetRequest.objects.get(uid = reset_id)
            u = p.user
            u.password = hash_password(request.POST['password'].strip())
            u.save()

            #perform for all that login magic that happens under the covers
            user = attempt_login(request, u.username, request.POST['password'].strip())
            p.delete()
            return set_auth_cookies(HttpResponseRedirect('/'), user)
        except Exception:
            logging.exception("Error In Reset Password")
            error = 'There was an error resetting your password.'

    return render(request, 'user/reset_password.html', {
        'error' : error,
        'reset_token' : reset_id,
    })
Esempio n. 6
0
def reset_password(request, reset_id):
    error = None
    if request.method == 'POST' and 'password' in request.POST and request.POST[
            'password']:
        try:
            p = PasswordResetRequest.objects.get(uid=reset_id)
            u = p.user
            u.password = hash_password(request.POST['password'].strip())
            u.save()

            #perform for all that login magic that happens under the covers
            user = attempt_login(request, u.username,
                                 request.POST['password'].strip())
            p.delete()
            return set_auth_cookies(HttpResponseRedirect('/'), user)
        except Exception:
            logging.exception("Error In Reset Password")
            error = 'There was an error resetting your password.'

    return render(request, 'user/reset_password.html', {
        'error': error,
        'reset_token': reset_id,
    })