Beispiel #1
0
def register(request):
    query_is_from_browser = True
    if request.method == 'POST':
        email = request.POST.get('email', '')
        password = request.POST.get('password', '')
        first_name = request.POST.get('first_name', 'Walter')
        last_name = request.POST.get('last_name', 'White')
        if request.path[1:4] == 'api':
            query_is_from_browser = False
            resp = HttpResponse(mimetype='application/json')
    if not validate_form(email, password, first_name, last_name):
        if not query_is_from_browser:
            resp.content = json.dumps(LOGIN_RESPONSE_DICT['3'])
            resp.status_code = 400
            return resp
        request.session['error'] = '3'
        return HttpResponseRedirect('/user/landing/')
    user = register_user(email, password, first_name, last_name)
    if user != None:
        create_default_groups(user)
        if not query_is_from_browser:
            resp.content = json.dumps(get_api_key(user))
            resp.status_code = 200
            return resp
        response = login_user(request, email, password)
        if response == USER_LOGGED_IN:
            request.session['error'] = '0'
            return HttpResponseRedirect('/tasks/main/')
    request.session['error'] = '4'
    return HttpResponseRedirect('/user/landing/')
Beispiel #2
0
def custom_auth_for_gtg(request):
    email = request.POST.get('email', '')
    password = request.POST.get('password', '')
    user_object = authenticate_user(email, password)
    resp = HttpResponse(mimetype='application/json')
    if user_object != None:
        resp.content = json.dumps(get_api_key(user_object))
        resp.status_code = 200
        return resp
    resp.status_code = 400
    return resp