Ejemplo n.º 1
0
def unfollow_view(request, the_creep):
    if request.method == 'POST':
        luser = UserProfile.get_user_by_id(request.user.username)
        try:
            ruser = UserProfile.get_user_by_id(the_creep)
        except UserProfile.DoesNotExist:
            raise Http404

        unfollow(follower=luser, followee=ruser)
        return redirect('/%s/' % the_creep)
Ejemplo n.º 2
0
def follow_view(request, to_follow):
    print(request.method)
    if request.method == 'POST':
        luser = UserProfile.get_user_by_id(request.user.username)
        try:
            ruser = UserProfile.get_user_by_id(to_follow)
        except UserProfile.DoesNotExist:
            raise Http404

        follow(follower=luser, followee=ruser)
        return redirect('/%s/' % to_follow)
Ejemplo n.º 3
0
def verify(request):
    username, verify_hash = (request.GET.get("username", None),
                             request.GET.get("verify", None))
    u = UserProfile.find(username)
    if not u:
        msg = "Sorry, that email — {0} — is not in our database.".format(username)
    else:
        if u.verified:
            msg = "We believe that this email — {0} — is already activated."
        else:
            if u.verify_hash == verify_hash:
                u.verified = True
                u.api_key = uuid.uuid4().hex
                u.save()
                body = settings.POST_VERIFICATION_MAIL_BODY_TEMPLATE.render(
                    Context({
                        "api_key": u.api_key
                    })
                )
                EmailMessage('cloud.js API key', body, to=[username]).send()
                msg = ('A mail with the API key has been sent to your email'
                    + ' account. You can also <a href="/">login</a> and submit'
                    + ' jobs from the web interface now.')
            else:
                msg = 'Sorry, invalid attempt.'
    return render_to_response("message.html", {"message": msg})
Ejemplo n.º 4
0
def home(request):
    if request.user.is_authenticated():
        user = UserProfile.objects.get(username=request.user.username)
        jobs = Job.objects.filter(owner=user.username)

        return render_to_response("home.html", 
                                 {"user": user, "jobs": jobs, "job_form": JobSubmitForm()},
                                   RequestContext(request))
    
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            email, password = cd['email'], cd['password']
            user = UserProfile.find(email)
            if user:
                if user.check_password(password):
                    user.backend = 'mongoengine.django.auth.MongoEngineBackend'
                    login(request, user)
                    if request.GET.get('next', None):
                        return redirect(request.GET['next'])
                    return redirect('/')
            return HttpResponse("invalid login")
        return redirect('/') 
    return render_to_response("login.html", 
                              {"login_form": LoginForm(),
                               "registration_form": RegistrationForm()},
                                RequestContext(request))
Ejemplo n.º 5
0
def status(request, username, tweet_id):
    try:
        tweet = Post.get_post_by_id(tweet_id)
        ruser = UserProfile.get_user_by_id(username)
    except:
        raise Http404
    
    luser = UserProfile.get_user_by_id(request.user.username)
    tpl_vars = {
            'luser': luser,
            'ruser': ruser,
            'all_users': UserProfile.objects.all(),
            'header': 'page',
            'logged': luser.is_authenticated(),
            'tweet': tweet
        }
    return render_to_response('twtapp/single.html',
                             RequestContext(request, tpl_vars))
Ejemplo n.º 6
0
def post(request):
    '''The view that makes the tweet happen!'''
    if request.method == 'POST':
        user = UserProfile.get_user_by_id(request.user.username)
        if request.POST.get('content', None):
            tweet = user.add_post(request.POST['content'])
            user.add_to_timeline(tweet)
            # Now let the followers know
            for follower in user.get_followers():
                follower.add_to_timeline(tweet)

    return redirect('/home/')
Ejemplo n.º 7
0
def login_view(request, next_page=None):
    tpl_vars = {'header': 'page', 'logged': False, 'signupform': SignupForm()}

    if request.method == 'POST':
        loginform = LoginForm(request.POST)
        tpl_vars['loginform'] = loginform

        if loginform.is_valid():
            cd = loginform.cleaned_data
            username, password = cd['username'], cd['password']
            
            user = UserProfile.find(username)
            if user:
                if user.check_password(password):
                    user.backend = 'mongoengine.django.auth.MongoEngineBackend'
                    login(request, user)
                    if next_page:
                        return redirect(next_page)
                
                    return redirect('/')

            loginform.errors['username'] = ['invalid username/password']
            return render_to_response('twtapp/login.html',
                                      RequestContext(request, tpl_vars))
        
        # Invalid form data
        return render_to_response('twtapp/login.html', 
                                  RequestContext(request, tpl_vars))

    # We don't have a POST(so, it's most probably, a GET!)
    if request.GET.get('next', None):
        tpl_vars['hidden_next'] = request.GET['next']

    tpl_vars['loginform'] = LoginForm()
    return render_to_response('twtapp/login.html',
                              RequestContext(request, tpl_vars))
Ejemplo n.º 8
0
def signup(request):
    tpl_vars = {
                'header': 'page', 
                'logged': False, 
                'signupform': SignupForm()
            }

    if request.method == 'POST':
        signupform = SignupForm(request.POST)
        if signupform.is_valid():
            cd = signupform.cleaned_data
            username, password = cd['username'], cd['password']
            if not UserProfile.find(username):
                user = UserProfile.objects.create(username=username,
                                           email='{0}@djangomongotwt.com'
                                                 .format(username))
                user.set_password(password)
                return login_view(request)

            signupform.errors['username'] = ['Oops! That id seems to be taken!']

        tpl_vars['signupform'] = signupform
    return render_to_response('twtapp/login.html',
                              RequestContext(request, tpl_vars))