Exemple #1
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})
Exemple #2
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))
Exemple #3
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))
Exemple #4
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))