Exemple #1
0
def request_account_retrieval(request):
    """
    Request account retrieval view.
    """

    navbarlinks = list_navbarlinks(request, [])
    shortcutlinks = list_shortcutlinks(request, [])

    if request.method == 'POST':
        form = AccountRetrieveForm(data=request.POST)
        if form.is_valid():
            c = {'form': form,}
            email_template_name = 'accounts/account_retrieve_email.html'
            # copied from django/contrib/admin/templates/registration/password_reset_email.html to templates directory
            # Email subject *must not* contain newlines
            email = loader.render_to_string(email_template_name, c)
            send_mail('B2Note user request account retrieval',
                      email, DEFAULT_FROM_EMAIL,
                      ['*****@*****.**'],
                      fail_silently=False)
            messages.success(request,
                             '''The information was sent to the service support team.
                             Unfortunately, for the time being, your access to your B2Note account can not be granted.
                             The support team shall get in contact with you shortly and provide more assistance.
                             Thank you for your interest in B2Note and your understanding.''')
            form = None
        else:
            messages.error(request, "Information does not qualify.")
    else:
        form = AccountRetrieveForm()
    return render_to_response('accounts/request_account_retrieval.html', {
        'shortcutlinks': shortcutlinks,
        'navbarlinks': navbarlinks,
        'form': form,}, context_instance=RequestContext(request))
Exemple #2
0
def old_register(request):
    """
    User registration view.
    """

    navbarlinks = list_navbarlinks(request, ["Registration", "Help page"])
    navbarlinks.append({"url": "/help#helpsection_registrationpage", "title": "Help page", "icon": "question-sign"})
    shortcutlinks = list_shortcutlinks(request, ["Registration"])

    if request.method == 'POST':
        form = OldRegistrationForm(data=request.POST)
        if form.is_valid():
            try:
                user = form.save()
            except IntegrityError:
                # catch "UNIQUE constraint failed" error
                # May catch other errors in which case the error message displayed in the UI would not be accurate
                return render_to_response(
                    'accounts/old_register.html',
                    {'navbarlinks': navbarlinks, 'shortcutlinks': shortcutlinks, 'form': form, 'alreadytaken': True},
                    context_instance=RequestContext(request)
                )
            return redirect('/login')
        else:
            print form.errors
    else:
        form = OldRegistrationForm()
    return render_to_response('accounts/old_register.html', {
        'navbarlinks': navbarlinks,
        'shortcutlinks': shortcutlinks,
        'form': form,}, context_instance=RequestContext(request))
Exemple #3
0
def old_login(request):
    """
    Log in view
    """
    navbarlinks = list_navbarlinks(request, ["Login", "Help page"])
    navbarlinks.append({"url": "/help#helpsection_loginpage", "title": "Help page", "icon": "question-sign"})
    shortcutlinks = []

    login_failed_msg = False

    if request.method == 'POST':
        login_failed_msg = True
        form = AuthenticationForm(data=request.POST)
        if form.is_valid():
            user = authenticate(email=request.POST['username'], password=request.POST['password'])
            if user is not None:
                if user.is_active:
                    django_login(request, user)
                    request.session["user"] = user.annotator_id.annotator_id
                    login_failed_msg = False
                    return redirect('/interface_main')
    else:
        if request.session.get("user"):
            return redirect('/interface_main', context=RequestContext(request))
        else:
            form = AuthenticationForm()

    return render_to_response('accounts/old_login.html',{'form': form},
                              context_instance=RequestContext(request, {
                                  'login_failed_msg': login_failed_msg,
                                  'navbarlinks': navbarlinks,
                                  'shortcutlinks': shortcutlinks,
                                  "pid_tofeed": request.session.get("pid_tofeed"),
                                  "subject_tofeed": request.session.get("subject_tofeed")
                              }))
Exemple #4
0
def register(request):
    """
    User registration view.
    """

    navbarlinks = list_navbarlinks(request, ["Registration", "Help page"])
    navbarlinks.append({
        "url": "/help#helpsection_registrationpage",
        "title": "Help page",
        "icon": "question-sign"
    })
    shortcutlinks = list_shortcutlinks(request, ["Registration"])

    if request.method == 'POST':
        form = RegistrationForm(data=request.POST)
        if form.is_valid():
            user = form.save()
            return redirect('/login')
        else:
            print form.errors
    else:
        form = RegistrationForm()
    return render_to_response('accounts/register.html', {
        'navbarlinks': navbarlinks,
        'shortcutlinks': shortcutlinks,
        'form': form,
    },
                              context_instance=RequestContext(request))
Exemple #5
0
def profilepage(request):
    """
    User profile view.
    """

    navbarlinks = list_navbarlinks(request, ["Help page"])
    navbarlinks.append({
        "url": "/help#helpsection_useraccountpage",
        "title": "Help page",
        "icon": "question-sign"
    })
    shortcutlinks = list_shortcutlinks(request, [])

    try:
        if request.session.get("user"):
            userprofile = AnnotatorProfile.objects.using('users').get(
                pk=request.session.get("user"))
            form = ProfileForm(initial=model_to_dict(userprofile))
            return render_to_response('accounts/profilepage.html', {
                'user_nickname': userprofile.nickname,
                'navbarlinks': navbarlinks,
                'shortcutlinks': shortcutlinks,
                'form': form
            },
                                      context_instance=RequestContext(request))
        else:
            return redirect('/logout')
    except Exception:
        print "Could not load or redirect from profilepage view."
        stdlogger.error("Could not load or redirect from profilepage view.")
        return False
Exemple #6
0
def register(request):
    """
    User registration view.
    """

    navbarlinks = list_navbarlinks(request, ["Registration", "Help page"])
    navbarlinks.append({"url": "/help#helpsection_registrationpage", "title": "Help page", "icon": "question-sign"})
    shortcutlinks = list_shortcutlinks(request, ["Registration"])


    auth_email = request.session["auth_email"]
    auth_firstname = request.session["auth_firstname"]
    auth_surname = request.session["auth_surname"]
    auth_data = {"auth_email": auth_email, "auth_firstname": auth_firstname, "auth_lastname": auth_surname}

    if request.method == 'POST':
        data = request.POST.copy()
        data.update(auth_data)
        form = RegistrationForm(data=data)
        if form.is_valid():
            try:
                user = form.save()
                request.session["registration_state"] = "done"
                user = authenticate(email=auth_email, password="******")
                if user.is_active:
                    django_login(request, user)
                    request.session["user"] = user.annotator_id.annotator_id
            except IntegrityError:
                # catch "UNIQUE constraint failed" error
                # May catch other errors in which case the error message displayed in the UI would not be accurate
                return render_to_response(
                    'accounts/register.html',
                    {'navbarlinks': navbarlinks, 'shortcutlinks': shortcutlinks, 'form': form, 'alreadytaken': True},
                    context_instance=RequestContext(request)
                )

            return redirect('/interface_main')
        else:
            print form.errors
    else:
        form = RegistrationForm(data=auth_data)
    return render_to_response('accounts/register.html', {
        'navbarlinks': navbarlinks,
        'shortcutlinks': shortcutlinks,
        'auth_email': auth_email,
        'auth_firstname': auth_firstname,
        'auth_lastname': auth_surname,
        'form': form,}, context_instance=RequestContext(request))
Exemple #7
0
def profilepage(request):
    """
    User profile view.
    """

    navbarlinks = list_navbarlinks(request, ["Help page"])
    navbarlinks.append({"url": "/help#helpsection_useraccountpage", "title": "Help page", "icon": "question-sign"})
    shortcutlinks = list_shortcutlinks(request, [])

    try:
        if request.session.get("user"):
            userprofile = AnnotatorProfile.objects.using('users').get(pk=request.session.get("user"))
            form = ProfileForm(initial = model_to_dict(userprofile) )
            return render_to_response('accounts/profilepage.html', {
                'user_nickname': userprofile.nickname,
                'navbarlinks': navbarlinks,
                'shortcutlinks': shortcutlinks,
                'form': form}, context_instance=RequestContext(request))
        else:
            return redirect('/logout')
    except Exception:
        print "Could not load or redirect from profilepage view."
        stdlogger.error("Could not load or redirect from profilepage view.")
        return False
Exemple #8
0
def feedbackpage(request):
    """
    Page for users to provide feedbacks on their epxerience of the service.
    One form for each of the 3 tabs (user-feedback, feature request and bug report).

    :param request:
    :return:
    """

    navbarlinks = list_navbarlinks(request, ["Help page"])
    navbarlinks.append({"url": "/help#helpsection_fedbackpage", "title": "Help page", "icon": "question-sign"})
    shortcutlinks = list_shortcutlinks(request, [])

    try:

        if request.session.get("user"):
            userprofile = AnnotatorProfile.objects.using('users').get(pk=request.session.get("user"))

            if request.method == 'POST':

                dest = SUPPORT_DEST_EMAIL

                if request.POST.get("feedback_submit") != None:

                    feedback_f = FeedbackForm(data=request.POST)

                    if feedback_f.is_valid():
                        names_t = {}
                        for fname in ["id_eval_overall", "id_eval_usefull", "id_eval_experience", "id_eval_interface", "id_eval_efficiency"]:
                            names_t[fname] = 0
                            if fname in request.POST:
                                if request.POST[fname] and isinstance(int(str(request.POST[fname])), int):
                                    names_t[fname] = int(str(request.POST[fname]))


                        fdbck = UserFeedback( email=userprofile,
                                              general_comment=feedback_f.cleaned_data["general_comment"],
                                              eval_overall=names_t["id_eval_overall"],
                                              eval_usefull=names_t["id_eval_usefull"],
                                              eval_experience=names_t["id_eval_experience"],
                                              eval_interface=names_t["id_eval_interface"],
                                              eval_efficiency=names_t["id_eval_efficiency"],
                                              )

                        fdbck.save()

                        c = {'form': feedback_f, 'names_t': names_t, 'nl': names_t.keys(),
                             'user_contact': userprofile.email, 'user_experience': userprofile.annotator_exp}
                        email_template_name = 'accounts/userfeedback_email.html'
                        # copied from django/contrib/admin/templates/registration/password_reset_email.html to templates directory
                        # Email subject *must not* contain newlines
                        email = loader.render_to_string(email_template_name, c)
                        send_mail('B2Note user evaluation feedback',
                                  email, DEFAULT_FROM_EMAIL,
                                  [dest], fail_silently=False)

                        msg = "Thank you for providing us your feedback."

                        data_dict = {"navbarlinks":  navbarlinks,
                                     "shortcutlinks": shortcutlinks,
                                     "msg": msg}

                        return render_to_response('accounts/feedback_page.html', data_dict, context_instance=RequestContext(request))

                if request.POST.get("feature_submit") != None:

                    feature_f = FeatureForm(data=request.POST)

                    if feature_f.is_valid():

                        featr = FeatureRequest( email=userprofile,
                                              title             = feature_f.cleaned_data["title"],
                                              short_description = feature_f.cleaned_data["short_description"],
                                              extra_description = feature_f.cleaned_data["extra_description"],
                                              alt_contact       = feature_f.cleaned_data["alt_contact"],
                                              )

                        featr.save()

                        c = {'form': feature_f, 'user_contact': userprofile.email, 'user_experience': userprofile.annotator_exp}
                        email_template_name = 'accounts/userfeedback_email.html'
                        # copied from django/contrib/admin/templates/registration/password_reset_email.html to templates directory
                        # Email subject *must not* contain newlines
                        email = loader.render_to_string(email_template_name, c)
                        send_mail('B2Note user feature request',
                                  email, DEFAULT_FROM_EMAIL,
                                  [dest], fail_silently=False)

                        msg = "Thank you for submitting a feature request."

                        data_dict = {"navbarlinks":  navbarlinks,
                                     "shortcutlinks": shortcutlinks,
                                     "msg": msg}

                        return render_to_response('accounts/feedback_page.html', data_dict, context_instance=RequestContext(request))

                if request.POST.get("bug_submit") != None:

                    bugreport_f = BugReportForm(data=request.POST)

                    if bugreport_f.is_valid():

                        names_t = {}
                        for fname in ["id_severity", "id_affected_function"]:
                            names_t[fname] = 0
                            if fname in request.POST:
                                if request.POST[fname]:
                                    if str(request.POST[fname]) in [str(x) for x in range(5)]:
                                        names_t[fname] = int(str(request.POST[fname]))
                                    elif isinstance(str(request.POST[fname]), (str, unicode)):
                                        names_t[fname] = str(request.POST[fname])

                        bugrep = BugReport( email               = userprofile,
                                            affected_function   = str(names_t["id_affected_function"]),
                                            short_description   = bugreport_f.cleaned_data["short_description"],
                                            extra_description   = bugreport_f.cleaned_data["extra_description"],
                                            severity            = int(names_t["id_severity"]),
                                            browser             = bugreport_f.cleaned_data["browser"],
                                            alt_contact         = bugreport_f.cleaned_data["alt_contact"],
                                            )

                        bugrep.save()

                        c = {'form': bugreport_f, 'names_t': names_t, 'nl': names_t.keys(),
                             'user_contact': userprofile.email, 'user_experience': userprofile.annotator_exp}
                        email_template_name = 'accounts/userfeedback_email.html'
                        # copied from django/contrib/admin/templates/registration/password_reset_email.html to templates directory
                        # Email subject *must not* contain newlines
                        email = loader.render_to_string(email_template_name, c)
                        send_mail('B2Note user bug report',
                                  email, DEFAULT_FROM_EMAIL,
                                  [dest], fail_silently=False)

                        msg = "Thank you for submitting a bug report."

                        data_dict = {"navbarlinks":  navbarlinks,
                                     "shortcutlinks": shortcutlinks,
                                     "msg": msg}

                        return render_to_response('accounts/feedback_page.html', data_dict, context_instance=RequestContext(request))


            feedback_f  = FeedbackForm()
            feature_f   = FeatureForm()
            bugreport_f = BugReportForm()

            data_dict = {"navbarlinks": navbarlinks,
                         "shortcutlinks": shortcutlinks,
                         "feedback_f": feedback_f,
                         "feature_f": feature_f,
                         "bugreport_f": bugreport_f }

            return render_to_response('accounts/feedback_page.html', data_dict, context_instance=RequestContext(request))

        else:
            return redirect('/logout')
    except Exception:
        print "Could not load or redirect from fedebackpage view."
        stdlogger.error("Could not load or redirect from fedebackpage view.")
        return False
Exemple #9
0
 def get_context_data(self, **kwargs):
     context = super(ResetPasswordRequestView, self).get_context_data(**kwargs)
     context['navbarlinks'] = list_navbarlinks()
     context['shortcutlinks'] = list_shortcutlinks()
     return context