def registrant_owner_redirect_mutual(request, regist_callback_me): user = request.user regist_type = request_get(request.REQUEST, url_keys.regist_type) registrant_request_token = request_get(request.REQUEST, url_keys.registrant_request_token) register_access_token = request_get(request.REQUEST, url_keys.register_access_token) register_access_validate = request_get(request.REQUEST, url_keys.register_access_validate) if (check_compulsory((regist_type, registrant_request_token, register_access_token, register_access_validate))) == False: return error_response(5, ()) if (check_choice(REGIST_TYPE, regist_type)) == False: return error_response(2, (url_keys.regist_type, regist_type)) try: registration = Registration.objects.get(registrant_request_token=registrant_request_token) if registration.regist_status >= find_key_by_value_regist_status(REGIST_STATUS['registrant_confirm']): # if this token is too old return error_response(7, (url_keys.registrant_request_token, registrant_request_token)) except ObjectDoesNotExist: return error_response(3, (url_keys.registrant_request_token, registrant_request_token)) if registration.user != user: return error_response(6, ()) ## register_request_token = request_get(request.REQUEST, url_keys.register_request_token) register_request_scope = request_get(request.REQUEST, url_keys.register_request_scope) register_request_reminder = request_get(request.REQUEST, url_keys.register_request_reminder) register_request_user_public = request_get(request.REQUEST, url_keys.register_request_user_public) registration.register_access_token = register_access_token registration.register_access_validate = register_access_validate registration.register_request_token = register_request_token registration.register_request_scope = register_request_scope registration.register_request_reminder = register_request_reminder registration.register_request_user_public = register_request_user_public ## look like it not need here registration.save() ## if registration.registrant_redirect_token == None or registration.registrant_redirect_token == '': registrant_redirect_token = dwlib.token_create(registration.registrant_callback, regist_callback_me, TOKEN_TYPE['redirect']) registration.registrant_redirect_token = registrant_redirect_token registration.save() ## regist_type_key = find_key_by_value_regist_type(regist_type) regist_status_key = find_key_by_value_regist_status(REGIST_STATUS['registrant_owner_redirect']) registration.regist_status=regist_status_key registration.save() ## params = { url_keys.regist_status: REGIST_STATUS['registrant_owner_grant'], url_keys.regist_type: regist_type, url_keys.register_redirect_token:registration.registrant_redirect_token, } url_params = dwlib.urlencode(params) url = '%s?%s'%(regist_callback_me, url_params) ## c = get_context_base_regist() c['regist_redirect_token']['value'] = registration.registrant_redirect_token c['regist_redirect_url']['value'] = url c['regist_status']['value'] = REGIST_STATUS['registrant_owner_grant'] # c['regist_status_current']['value'] = REGIST_STATUS['registrant_owner_redirect'] c['regist_type']['value'] = regist_type context = RequestContext(request, c) return render_to_response("regist_owner_redirect.html", context)
def register_owner_redirect(request, regist_callback_me): registrant_callback = request_get(request.REQUEST, url_keys.regist_callback) regist_type = request_get(request.REQUEST, url_keys.regist_type) registrant_request_token = request_get(request.REQUEST, url_keys.registrant_request_token) registrant_request_scope = request_get(request.REQUEST, url_keys.registrant_request_scope) # TODO:may check it is in scope or not registrant_request_reminder = request_get(request.REQUEST, url_keys.registrant_request_reminder) registrant_request_user_public = request_get(request.REQUEST, url_keys.registrant_request_user_public) # TODO: if it is requesting to a specific user, it need to check whether this user is login or exist, however each individual case may have different implementaiton. It could just be ignored for generation. if (check_compulsory((registrant_callback, regist_type, registrant_request_token, registrant_request_scope, registrant_request_reminder))) == False: return error_response(5, ()) if (check_choice(REGIST_TYPE, regist_type)) == False: return error_response(2, (url_keys.regist_type, regist_type)) ## try: registration = Registration.objects.get(registrant_request_token=registrant_request_token) # check whether the token is out of request stage if registration.regist_status >= find_key_by_value_regist_status(REGIST_STATUS['register_grant']): return error_response(7, (url_keys.registrant_request_token, registrant_request_token)) register_redirect_token = registration.register_redirect_token # use the existing redirect token if it is still available, try to keep one request_token should only have one redirect_value except ObjectDoesNotExist: # if the redirect_token is not generate before register_redirect_token = dwlib.token_create(registrant_callback, regist_callback_me, TOKEN_TYPE['redirect']) regist_type_key = find_key_by_value_regist_type(regist_type) regist_status_key = find_key_by_value_regist_status(REGIST_STATUS['register_owner_redirect']) obj, created = Registration.objects.get_or_create( regist_type=regist_type_key, regist_status=regist_status_key, registrant_request_token=registrant_request_token, registrant_request_scope=registrant_request_scope, registrant_callback=registrant_callback, register_callback=regist_callback_me, registrant_request_reminder=registrant_request_reminder, registrant_request_user_public=registrant_request_user_public, register_redirect_token=register_redirect_token) ## params = { url_keys.regist_status: REGIST_STATUS['register_owner_grant'], url_keys.regist_type: regist_type, url_keys.regist_redirect_token:register_redirect_token, } url_params = dwlib.urlencode(params) url = '%s?%s'%(regist_callback_me, url_params) ## c = get_context_base_regist() c['regist_redirect_token']['value'] = register_redirect_token c['regist_redirect_url']['value'] = url c['regist_status']['value'] = REGIST_STATUS['register_owner_grant'] c['regist_status_current']['value'] = REGIST_STATUS['register_owner_redirect'] c['regist_type']['value'] = regist_type context = RequestContext(request, c) return render_to_response("regist_owner_redirect.html", context)
def registrant_owner_redirect_one_way(request, regist_callback_me): user = request.user regist_type = request_get(request.REQUEST, url_keys.regist_type) registrant_request_token = request_get(request.REQUEST, url_keys.registrant_request_token) register_access_token = request_get(request.REQUEST, url_keys.register_access_token) register_access_validate = request_get(request.REQUEST, url_keys.register_access_validate) if (check_compulsory((regist_type, registrant_request_token, register_access_token, register_access_validate))) == False: return error_response(5, ()) if (check_choice(REGIST_TYPE, regist_type)) == False: return error_response(2, (url_keys.regist_type, regist_type)) try: registration = Registration.objects.get(registrant_request_token=registrant_request_token) if registration.regist_status >= find_key_by_value_regist_status(REGIST_STATUS['registrant_confirm']): # if this token is too old return error_response(7, (url_keys.registrant_request_token, registrant_request_token)) except ObjectDoesNotExist: return error_response(3, (url_keys.registrant_request_token, registrant_request_token)) if registration.user != user: return error_response(6, ()) ## if registration.registrant_redirect_token == None or registration.registrant_redirect_token == '': registrant_redirect_token = dwlib.token_create(registration.registrant_callback, regist_callback_me, TOKEN_TYPE['redirect']) registration.registrant_redirect_token = registrant_redirect_token registration.save() if registration.registrant_grant_user_token == None or registration.registrant_grant_user_token == '': registrant_grant_user_token = dwlib.token_create_user(registration.register_callback, regist_callback_me, TOKEN_TYPE['grant'], user) registration.registrant_grant_user_token = registrant_grant_user_token registration.save() ## regist_type_key = find_key_by_value_regist_type(regist_type) regist_status_key = find_key_by_value_regist_status(REGIST_STATUS['registrant_owner_redirect']) registration.regist_status=regist_status_key registration.save() ## params = { url_keys.regist_status: REGIST_STATUS['registrant_confirm'], url_keys.regist_type: regist_type, url_keys.regist_redirect_token:registration.registrant_redirect_token, url_keys.regist_grant_user_token:registration.registrant_grant_user_token, } url_params = dwlib.urlencode(params) url = '%s?%s'%(regist_callback_me, url_params) ## return HttpResponseRedirect(url)