Exemplo n.º 1
0
def addCourse(request):
    payload = {'name': 'electrical Engineering', 'Description': 'electrical engineering course', 'createDate': 'DATE',
               'status': '0'}
    r = requestsUtil.makePostRequest("course", data=json.dumps(payload))

    ctx = r.json()
    return render_to_response('??.html', ctx, context_instance=RequestContext(request))
Exemplo n.º 2
0
def signIn(request):
    error_status = False
    login_status = False
    if request.method == "POST":
        login_form = LoginForm(request.POST)
        if login_form.is_valid():
            username = login_form.cleaned_data['username']
            password = login_form.cleaned_data['password']
            request.session["contact_sent"] = True
            login_form_data = {'email': username, 'pwd': password}
            r = requestsUtil.makePostRequest("auth", data=json.dumps(login_form_data))
            code = r.status_code
            if code == 200:
                request.session["username"]=username
                login_status = True
                return login_index(request)
            elif code == 500:
                error_status = True
                ctx = {'login_form': login_form, 'error_status': error_status, 'error': r.json()}
                return render_to_response('login.html', ctx, context_instance=RequestContext(request))
            elif code == 401:
                error_status = True
                ctx = {'login_form': login_form, 'error_status': error_status, 'error': r.json()}
                return render_to_response('login.html', ctx, context_instance=RequestContext(request))

    else:

        login_form = LoginForm()

    ctx = {'login_form': login_form, 'error_status': error_status}
    return render_to_response('login.html', ctx, context_instance=RequestContext(request))
Exemplo n.º 3
0
def createUser(request):
    error_status = False
    login_status = False
    createUser_status = False
    if request.method == "POST":
        createUser_form = createUserForm(request.POST)
        if createUser_form.is_valid():
            email = createUser_form.cleaned_data['email']
            password = createUser_form.cleaned_data['password']
            fname = createUser_form.cleaned_data['fname']
            lname = createUser_form.cleaned_data['lname']
            request.session["contact_sent"] = True
            createUser_form_data = {'email': email, 'pwd': password, 'fname': fname, 'lname': lname}
            r = requestsUtil.makePostRequest("user", data=json.dumps(createUser_form_data))
            code = r.status_code
            if code == 201:
                login_status = False
                createUser_status = True
                request.session['teamName'] = 'Pinnacle'
                ctx = {'data': r.json(), 'error_status': error_status, 'createUser_status': createUser_status,
                       'login_status': login_status,"mooc_select":MoocForm(request.session['teamName'])}
                return render_to_response('loggedOutIndex.html', ctx, context_instance=RequestContext(request))
            elif code == 500:
                error_status = True
                ctx = {'createUser_form': createUser_form, 'error_status': error_status,
                       'error': 'Internal Error Occurs. Please try after sometime.'}
                return render_to_response('createUser.html', ctx, context_instance=RequestContext(request))
            elif code == 409:
                error_status = True
                ctx = {'createUser_form': createUser_form, 'error_status': error_status, 'error': r.json()}
                return render_to_response('createUser.html', ctx, context_instance=RequestContext(request))

    else:

        createUser_form = createUserForm()

    ctx = {'createUser_form': createUser_form, 'error_status': error_status}
    return render_to_response('createUser.html', ctx, context_instance=RequestContext(request))