Exemplo n.º 1
0
def createResponseNotif(sourceObj, recipientProfile, content, options):
    if isinstance(sourceObj, Shed):
        newNotification = Notification(sourceShed=sourceObj,
                                       options=options,
                                       content=content,
                                       recipient=recipientProfile,
                                       notificationType="request")
    elif isinstance(sourceObj, Tool):
        newNotification = Notification(sourceTool=sourceObj,
                                       options=options,
                                       content=content,
                                       recipient=recipientProfile,
                                       notificationType="request")
    elif isinstance(sourceObj, Profile):
        newNotification = Notification(sourceProfile=sourceObj,
                                       options=options,
                                       content=content,
                                       recipient=recipientProfile,
                                       notificationType="request")
    elif isinstance(sourceObj, Action):
        newNotification = Notification(sourceAction=sourceObj,
                                       options=options,
                                       content=content,
                                       recipient=recipientProfile,
                                       notificationType="request")

    newNotification.save()
    sendMail(recipientProfile, "You have a new notification!", content)
    #actionManager.processActions()
    return newNotification
Exemplo n.º 2
0
def user_register(request):
    if request.user.is_anonymous():
        if request.method == 'POST':
            form = UserRegistrationForm(request.POST)
            if form.is_valid():
                userAccount = form.save()
                user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password1'])
                if user is not None:
                    login(request, user)
                #send confirmation email
                sendMail(profileUtil.getProfileFromUser(userAccount), \
                    "Welcome aboard! ", "Thank you for registering with ToolCloud.")
                shedName = form.cleaned_data['username'] + "'s Shed"
                userProfile = profileUtil.getProfileFromUser(userAccount)
                newShedObject = Shed(name=shedName, owner=userProfile, location='location', sharezone=form.cleaned_data['zip_code'],\
                    status='status')
                newShedObject.save()
                newShedObject.members.add(userProfile)
                newShedObject.admins.add(userProfile)
                newShedObject.save()
                userProfile.personalShed = newShedObject
                context = {}
                context.update(content.genUserHome(request))
                context.update(content.addGoodRegisterNoti(dict()))
                return render_to_response('userHome.html', context)
        else:
            form = UserRegistrationForm()
        context = {}
        context.update(csrf(request))
        context['form'] = form
        context.update(content.genSuper())
        #Pass the context to a template
        return render_to_response('register.html', context)
    else:
        return HttpResponseRedirect('/')
Exemplo n.º 3
0
def createInfoNotif(sourceObj, recipientProfile, content):
    if isinstance(sourceObj, Shed):
        newNotification = Notification(sourceShed=sourceObj,
                                       content=content,
                                       recipient=recipientProfile,
                                       notificationType="info")
    elif isinstance(sourceObj, Tool):
        newNotification = Notification(sourceTool=sourceObj,
                                       content=content,
                                       recipient=recipientProfile,
                                       notificationType="info")
    elif isinstance(sourceObj, Profile):
        newNotification = Notification(sourceProfile=sourceObj,
                                       content=content,
                                       recipient=recipientProfile,
                                       notificationType="info")
    elif isinstance(sourceObj, Action):
        newNotification = Notification(sourceAction=sourceObj,
                                       content=content,
                                       recipient=recipientProfile,
                                       notificationType="info")

    newNotification.save()

    #send confirmation email
    sendMail(recipientProfile, "You have a new notification!", content)
    #actionManager.processActions()
    return newNotification
Exemplo n.º 4
0
def create_tool_shed(request):
    if request.user.is_anonymous():
        #tell user they need to be logged in to do that
        #add message flag that will display to user "you must be logged in to..."
        return HttpResponseRedirect(
            '/accounts/login/')  #redirect to login page
    else:
        if request.method == 'POST':
            form = ShedCreationForm(request.user, request.POST)

            if form.is_valid():
                shed = form.save()
                profileObj = profileUtil.getProfileFromUser(request.user)
                shed.members.add(profileObj)
                shed.admins.add(profileObj)
                #send email
                sendMail(profileUtil.getProfileFromUser(request.user), \
                    "Your shed has been created! ", \
                    "Thanks for creating " + shed.name + \
                    " on ToolCloud.  We'll let you know when someone wants to join.")
                return HttpResponseRedirect('/sheds/' + str(shed.id) +
                                            '/success')
        else:
            form = ShedCreationForm(request.user)
        context = {}
        context.update(csrf(request))
        context['form'] = form
        context.update(content.genBaseLoggedIn(request))
        return render_to_response('shed_creation.html', context)
Exemplo n.º 5
0
def create_tool_shed(request):
    if request.user.is_anonymous():
        #tell user they need to be logged in to do that
        #add message flag that will display to user "you must be logged in to..."
        return HttpResponseRedirect('/accounts/login/') #redirect to login page
    else:
        if request.method == 'POST':
            form = ShedCreationForm(request.user, request.POST)
            
            if form.is_valid():
                shed = form.save()
                profileObj = profileUtil.getProfileFromUser(request.user)
                shed.members.add(profileObj)
                shed.admins.add(profileObj)
                #send email
                sendMail(profileUtil.getProfileFromUser(request.user), \
                    "Your shed has been created! ", \
                    "Thanks for creating " + shed.name + \
                    " on ToolCloud.  We'll let you know when someone wants to join.")
                return HttpResponseRedirect('/sheds/' + str(shed.id) + '/success')
        else:
            form = ShedCreationForm(request.user)
        context = {}
        context.update(csrf(request))
        context['form'] = form
        context.update(content.genBaseLoggedIn(request))
        return render_to_response('shed_creation.html', context)
Exemplo n.º 6
0
def tool_submission(request):
    if request.user.is_anonymous():
        #tell user they need to be logged in to do that
        #add message flag that will display to user "you must be logged in to..."
        return HttpResponseRedirect(
            '/accounts/login/')  #redirect to login page
    else:
        if request.method == 'POST':
            form = ToolCreationForm(request.user, request.POST)
            if form.is_valid():
                tool = form.save()
                tool.save()
                #send email
                sendMail(profileUtil.getProfileFromUser(request.user), \
                    "Your tool has been submitted! ",\
                     "Thanks for submitting your " + tool.name + \
                      " to ToolCloud.  We'll let you know when someone wants to borrow it.")
                return HttpResponseRedirect('/tools/' + str(tool.id) +
                                            '/success')
        else:
            form = ToolCreationForm(request.user)
        context = {}
        context.update(csrf(request))
        context.update(content.genBaseLoggedIn(request))
        context['form'] = form
        return render_to_response('tool_creation.html', context)
def createResponseNotif(sourceObj,recipientProfile,content,options):
    if isinstance(sourceObj, Shed):
        newNotification = Notification(sourceShed = sourceObj, options=options, content = content, recipient = recipientProfile, notificationType = "request")
    elif isinstance(sourceObj, Tool):
        newNotification = Notification(sourceTool = sourceObj, options=options, content = content, recipient = recipientProfile, notificationType = "request")
    elif isinstance(sourceObj, Profile):
       newNotification = Notification(sourceProfile = sourceObj, options=options, content = content, recipient = recipientProfile, notificationType = "request")
    elif isinstance(sourceObj, Action):
        newNotification = Notification(sourceAction = sourceObj, options=options, content = content, recipient = recipientProfile, notificationType = "request")

    newNotification.save()
    sendMail(recipientProfile, "You have a new notification!", content)
    #actionManager.processActions()
    return newNotification
def createInfoNotif(sourceObj,recipientProfile,content):
    if isinstance(sourceObj, Shed):
        newNotification = Notification(sourceShed = sourceObj, content = content, recipient = recipientProfile, notificationType = "info")
    elif isinstance(sourceObj, Tool):
        newNotification = Notification(sourceTool = sourceObj, content = content, recipient = recipientProfile, notificationType = "info")
    elif isinstance(sourceObj, Profile):
       newNotification = Notification(sourceProfile = sourceObj, content = content, recipient = recipientProfile, notificationType = "info")
    elif isinstance(sourceObj, Action):
        newNotification = Notification(sourceAction = sourceObj, content = content, recipient = recipientProfile, notificationType = "info")

    newNotification.save()

    #send confirmation email
    sendMail(recipientProfile, "You have a new notification!", content)
    #actionManager.processActions()
    return newNotification
Exemplo n.º 9
0
def password_reset(request):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login')
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = passwordResetForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            passone = form.cleaned_data.get ("password")
            passtoo = form.cleaned_data.get ("confirm_password")
            if (passone == passtoo):
                request.user.set_password (passone)
                request.user.save()
                sendMail(profileUtil.getProfileFromUser(request.user), \
                    "Your password has been changed", \
                    "Your password has been changed on ToolCloud.")
            return HttpResponseRedirect('/accounts/my_account/password_changed')
    # if a GET (or any other method) we'll create a blank form
    else:
        form = passwordResetForm()

    return render(request, 'password_reset.html', {'form': form})
Exemplo n.º 10
0
def tool_submission(request):
    if request.user.is_anonymous():
        #tell user they need to be logged in to do that
        #add message flag that will display to user "you must be logged in to..."
        return HttpResponseRedirect('/accounts/login/') #redirect to login page
    else:
        if request.method == 'POST':
            form = ToolCreationForm(request.user, request.POST)
            if form.is_valid():
                tool = form.save()
                tool.save()
                #send email
                sendMail(profileUtil.getProfileFromUser(request.user), \
                    "Your tool has been submitted! ",\
                     "Thanks for submitting your " + tool.name + \
                      " to ToolCloud.  We'll let you know when someone wants to borrow it.")
                return HttpResponseRedirect('/tools/' + str(tool.id) + '/success')
        else:
            form = ToolCreationForm(request.user)
        context = {}
        context.update(csrf(request))
        context.update(content.genBaseLoggedIn(request))
        context['form'] = form
        return render_to_response('tool_creation.html', context)
Exemplo n.º 11
0
def password_reset(request):
    if request.user.is_anonymous():
        return HttpResponseRedirect('/accounts/login')
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = passwordResetForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            passone = form.cleaned_data.get("password")
            passtoo = form.cleaned_data.get("confirm_password")
            if (passone == passtoo):
                request.user.set_password(passone)
                request.user.save()
                sendMail(profileUtil.getProfileFromUser(request.user), \
                    "Your password has been changed", \
                    "Your password has been changed on ToolCloud.")
            return HttpResponseRedirect(
                '/accounts/my_account/password_changed')
    # if a GET (or any other method) we'll create a blank form
    else:
        form = passwordResetForm()

    return render(request, 'password_reset.html', {'form': form})
Exemplo n.º 12
0
def user_register(request):
    if request.user.is_anonymous():
        if request.method == 'POST':
            form = UserRegistrationForm(request.POST)
            if form.is_valid():
                userAccount = form.save()
                user = authenticate(username=form.cleaned_data['username'],
                                    password=form.cleaned_data['password1'])
                if user is not None:
                    login(request, user)
                #send confirmation email
                sendMail(profileUtil.getProfileFromUser(userAccount), \
                    "Welcome aboard! ", "Thank you for registering with ToolCloud.")
                shedName = form.cleaned_data['username'] + "'s Shed"
                userProfile = profileUtil.getProfileFromUser(userAccount)
                newShedObject = Shed(name=shedName, owner=userProfile, location='location', sharezone=form.cleaned_data['zip_code'],\
                    status='status')
                newShedObject.save()
                newShedObject.members.add(userProfile)
                newShedObject.admins.add(userProfile)
                newShedObject.save()
                userProfile.personalShed = newShedObject
                context = {}
                context.update(content.genUserHome(request))
                context.update(content.addGoodRegisterNoti(dict()))
                return render_to_response('userHome.html', context)
        else:
            form = UserRegistrationForm()
        context = {}
        context.update(csrf(request))
        context['form'] = form
        context.update(content.genSuper())
        #Pass the context to a template
        return render_to_response('register.html', context)
    else:
        return HttpResponseRedirect('/')