Enable your RDS or Admin password - coldfusion

I'm not sure why I'm getting this. If I browse to
http://www.phillipsenn.com/Matrix/JSON/Upload/Upload.cfc?method=Save&Item=1
Then the component works correctly.
But if I do this, then it asks for the RDS password.
!function($, window, undefined) {
var local = {};
local.data = {};
local.type= 'post',
local.dataType= 'json',
local.data.method = 'Save';
local.data = {
Item : 'Item One'
}
var myPromise = $.ajax('Upload.cfc',local);
myPromise.done(function(result) {
console.log('success!');
});
myPromise.fail(function(A,B,C) {
$('body').append(A.responseText);
console.log(B);
console.log(C);
});
}(jQuery, window);
Finally, here's my component:
<cfcomponent>
<cffunction name="Save" access="remote" output="yes">
<cfargument name="Item">
<cfset var local = {}>
<cfquery datasource="#Application.Datasource#" username="#Application.Username#" password="#Application.Password#">
INSERT INTO lru.Clip(ClipDesc) VALUES('test')
</cfquery>
#arguments.Item#
</cffunction>
</cfcomponent>

Phil,
I'm guessing that somehow your ajax code is calling the CFC without the "method" url param. When it does this CF thinks you are going to try the "CFC Explorer" - a neat little tool that creates a Javadoc like description of your CFC. You can see it (even on local) if you simply browse to your CFC without any url params as in:
http://www.phillipsenn.com/Matrix/JSON/Upload/Upload.cfc
So something has to change with your Ajax call... I think that the issue is your last set statement...
local.data = {
Item : 'Item One'
}
is replacing the "data" sets above it..... with a single struct called "Item". you are losing the key called "method" when you do it this way. Try:
local.data.Item = 'Item One';

Related

Avoid double call GET Ajax load

Well, I'm trying to create a graphical interface for a database using django.
I have to say that I'm trying to learn so I don't have too much experience with Frameworks, just with pure code.
The doubt I have is:
-When trying to create a filter system with checkboxes I have used Ajax to be able to update the view without having to refresh. Like this:
$(document).on('click','#console_check_filter',function(){
var ps_id;
ps_id = $(this).attr("data-posts-id");
$.ajax({
url: "{% url 'list-view' %}",
method: 'POST',
data: {
'getfilter': ps_id,
'csrfmiddlewaretoken': '{{ csrf_token }}',
},
success: function (res, status,data) {
$("#list").load("/game/list-view");
},
error: function (res,ras,rus) {
}
});
});
But I had the error that for every call I made with POST the AJAX function ().load() made another call which eliminated the variable that gave me the POST. This made it impossible for me to use the information received from the POST to create the filter.
Result: I click on the checkbox and in the console I get a call with the filtered list and then another one without filter, and as it is not only the last one that is rendered, which has no data.
To solve this I have used a globar variable to save the value in the POST and the ().load() return to make the GET call using the value saved in the GLOBAL.
filet=""
def game_list(request):
global filet
context = {}
game_filter = request.GET.get('console_check_filter')
games = Game.objects.all()
game_post = games
data = {'success': False}
page = request.GET.get('page',1)
game_console_filter=""
context['games'] = games
#if request.method=='POST':
game_console_filter = request.POST.get('getfilter')
if not game_console_filter:
game_console_filter = request.GET.get('getfilter')
if request.method=="POST":
filet = get_game_console_filter(request,game_console_filter)
context['games'] = games
context['game_post'] = filet
return render(request,'Jocs/list-view.html',context )
This doesn't seem elegant to me, I'm out of the woods, yes, but I don't think it's the best solution.
Any idea to avoid this happening to me?
A greeting and thank you very much for everything
Apparently I am more stupid than I thought. In the end the solution was to send the variable by URL. Example:
AJAX:
$(document).on('click','#console_check_filter',function(){
var ps_id;
ps_id = $(this).attr("data-posts-id");
$.ajax({
url: "{% url 'list-view' %}",
method: 'POST',
data: {
getfilter': ps_id,
csrfmiddlewaretoken': '{{ csrf_token }}',
},
success: function (res, status,data) {
$("#list").load("/game/list-view/?filters="+ps_id); > <-----HERE
},
error: function (res,ras,rus) {
}
});
});
views.py:
#if request.method=='POST':
game_console_filter = request.POST.get('getfilter')
if not game_console_filter:
game_console_filter = request.GET.get('filters') <---HERE
I think that if this is the right way to proceed, at least it's more elegant.
I hope someone else will find this answer useful.
Sorry for the inconvenience and for asking trivial questions. Greetings to all.

How can I render AccountKit UI

Here is my form which is on my login.php page:
<form id="LoginForm">
<input value="+1" id="country_code" />
<input placeholder="phone number" id="phone_number"/>
<button onclick="smsLogin();">Login via SMS</button>
</form>
<script src="https://sdk.accountkit.com/en_US/sdk.js"></script>
<script>
// initialize Account Kit with CSRF protection
AccountKit_OnInteractive = function(){
AccountKit.init(
{
appId:"{{FACEBOOK_APP_ID}}",
state:"{{csrf}}",
version:"{{ACCOUNT_KIT_API_VERSION}}",
fbAppEventsEnabled:true,
redirect:"{{REDIRECT_URL}}"
}
);
};
// login callback
function loginCallback(response) {
if (response.status === "PARTIALLY_AUTHENTICATED") {
var code = response.code;
var csrf = response.state;
// Send code to server to exchange for access token
}
else if (response.status === "NOT_AUTHENTICATED") {
// handle authentication failure
}
else if (response.status === "BAD_PARAMS") {
// handle bad parameters
}
}
// phone form submission handler
function smsLogin() {
var countryCode = document.getElementById("country_code").value;
var phoneNumber = document.getElementById("phone_number").value;
AccountKit.login(
'PHONE',
{countryCode: countryCode, phoneNumber: phoneNumber}, // will use default values if not specified
loginCallback
);
}
// email form submission handler
function emailLogin() {
var emailAddress = document.getElementById("email").value;
AccountKit.login(
'EMAIL',
{emailAddress: emailAddress},
loginCallback
);
}
</script>
And here is the expected interface to send the code :
The problem I have is before AccountKIt UI get rendered the user has to click Login via SMS button... which I am not finding interesting, I want if the user goes on login.php page the AccountKit UI should be rendered automatically without showing my form.
I tried to do to remove the form and modified the function smsLogin() to be immediately called as follow :
function {
var countryCode = document.getElementById("country_code").value;
var phoneNumber = document.getElementById("phone_number").value;
AccountKit.login(
'PHONE',
{countryCode: countryCode, phoneNumber: phoneNumber}, // will use default values if not specified
loginCallback
);
}();
But I received the error saying :
TypeError: AccountKit.login is not a function
I need some tips to see how I can acheive what I want to do.
I am redirecting the user directly on the page of accountkit when he visit my login page.The link of accountkit is : https://www.accountkit.com/v1.0/basic/dialog/sms_login/ and has parameter I am passing the phonenumber, country_code,redirect url(which is my page on which the user will be sent). So everything is working as I wanted.

can't access to the POST variable that sent from register form in django

I have a register form in html that has a button that type of submit and the name of registerSubmit like this:
<input class="RegisterButton right green" name="registerSubmit" type="submit" value="Continue">
I want to check the form with Ajax and then if every thing is valid then redirect the user to her/his profile.But when I want to redirect the user to his/her profile I can't send the submit input that its name is registerSubmit. here is a section of JQuery code that related to this event:
$("#mainRegisterForm").submit(function(event){
var thisRegisterForm = $(this);
$(".ajaxLogoRegister").show();
event.preventDefault();
var firstName = $("input[name='firstname']").val();
var lastName = $("input[name='lastname']").val();
var emailAddress = $("input[name='email']").val();
var password = $("input[name='password']").val();
var rePass = $("input[name='rePass']").val();
var sex = "NULL";
if ($("input[name='gender']").is(":checked")){
sex = $("input[name='gender']:checked").val();
}
var data ={
firstname:firstName,
lastname:lastName,
emailaddress:emailAddress,
password:password,
repass:rePass,
sex:sex
};
$.ajax({
url: 'ajax/registercheck',
data: data,
dataType: 'json',
success:function(result){
if(result.fn==0){
//do some stuff
}
//another if conditions that checks the validity of every field of refister form
...
...
$(".ajaxLogoRegister").hide();
if(result.isOK=='1'){ //isOK = 1 when every filed is valid and user must redirect to his/her profile
thisRegisterForm.unbind('submit').submit();
}
}
});
});
My main problem is that when I click the registerSubmit button in views.py the request.POST.get('registerSubmit') returns None object instead of Continue value.
when I don't use Ajax and send the form normally registerSubmit value is Continue and every thing is OK.where I am wrong?
By default, $.ajax(); will issue a GET request, not a POST. You need to specify that in your ajax options. Second, I don't see where you're accessing the value of the element named "registerSubmit". I see an "rePass", but you're not including the value you're expecting to find in the request.
You need to either specifically set the "type" ajax option type to "POST" or retrieve the method property from the form element:
$ajax({
url: 'ajax/registercheck',
data: data,
dataType: 'json',
type: 'POST',
....
});

Click facebook like button and be taken to another url

Is something like this possible?
I have a client launching an online magazine for his business. He wants to add a facebook like button (for the magazine fanpage) on his current corporate site and ask users to 'like it' in order to be taken to the magazine website. Can it be done? Are there drawbacks to this approach? For example, the same user will have to 'like it' every time they want to access the magazine site?
Thank you for any suggestion, I'm pretty new to facebook.
You can redirect a user on clicking a like button using the Javascript SDK and FB.Event.Subscribe
FB.Event.subscribe('edge.create', function(response) {
window.parent.location = 'http://www.google.com';
});
edge.create is called when ever a user likes something on the page
response is the url that has just been liked.
If there are multiple like buttons on the page you could use an if statement with the response to make sure the page only redirects for a particular like button
Here's the full javascript code and a like button
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR_APP_ID', // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
oauth : true, // enable OAuth 2.0
xfbml : true // parse XFBML
});
FB.Event.subscribe('edge.create', function(response) {
window.parent.location = 'http://www.google.com';
});
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/<?php if(isset($fb_user['locale'])){echo $fb_user['locale'];}else{echo'en_US';}?>/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
<fb:like href="http://www.google.com" send="false" width="450" show_faces="true"></fb:like>

How to solve Only Web services with a [ScriptService] attribute on the class definition can be called from script

I attempt to use webservice return POCO class generated from entity data model as JSON when using Jquery AJAX call method in webservice. but I have problem with error "Only Web services with a [ScriptService] attribute on the class definition can be called from script", and getting stuck in it,
Here is my code :
namespace CarCareCenter.Web.Admin.Services
{
/// <summary>
/// Summary description for About
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class About : System.Web.Services.WebService
{
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
[WebMethod]
public static Entities.Category getAbout()
{
Entities.Category about = new Entities.Category();
using (var context = new CarCareCenterDataEntities())
{
about = (from c in context.Categories where c.Type == "About" select c).SingleOrDefault();
}
return about;
}
}
}
aspx page :
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: 'POST',
dataType: 'json',
contentType: 'application/json; charset=utf-8',
url: '/Services/About.asmx/getAbout',
data: '{}',
success: function (response) {
var aboutContent = response.d;
alert(aboutContent);
$('#title-en').val(aboutContent.Name);
$('#title-vn').val(aboutContent.NameVn);
$('#content-en').val(aboutContent.Description);
$('#content-vn').val(aboutContent.DescriptionVn);
$('#id').val(aboutContent.CategoryId);
},
failure: function (message) {
alert(message);
},
error: function (result) {
alert(result);
}
});
$('#SaveChange').bind('click', function () { updateAbout(); return false; });
$('#Reset').bind('click', function () { getAbout(); return false; })
});
function updateAbout() {
var abt = {
"CategoryId": $('#id').val(),
"Name": $('#title-en').val(),
"NameVn": $('#title-vn').val(),
"Description": $('#content-en').val(),
"DescriptionVn": $('#content-vn').val()
};
$.ajax({
type: "POST",
url: "AboutManagement.aspx/updateAbout",
data: JSON.stringify(abt),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var aboutContent = response.d;
$('#title-en').val(aboutContent.Name);
$('#title-vn').val(aboutContent.NameVn);
$('#content-en').val(aboutContent.Description);
$('#content-vn').val(aboutContent.DescriptionVn);
},
failure: function (message) {
alert(message);
},
error: function (result) {
alert(result);
}
});
}
</script>
Do any approaches to solve it ? Please help me . Thanks
just add Attribute Class [ScriptService]
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
old question. i had same problem, just removed contenttype from ajax call and it worked.
I just had exactly this same error message: "Only Web services with a [ScriptService] attribute on the class definition can be called from script.", but it had a totally different cause and solution.
It was working on my development machine, but not in production.
In my web.config I had:
<system.web>
<httpHandlers>
<remove verb="*" path="*.asmx"></remove>
<add verb="*" path="*.asmx" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35"></add>
</httpHandlers>
</system.web>
Replaced the Add tag with a newer assembly version:
<add verb="*" path="*.asmx" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
And it worked! Aparently the older assembly (1.0.61025.0) did not reccognise the attribute that was compiled against the newer (3.5.0.0) one.
Hope I can save someone the hours I needed to get to the bottom of this one!
I was also facing the same issue.
I just commented below code and it started working:
[System.Web.Script.Services.ScriptService]
available in .asmx file .
Just adding this in case someone else made the same stupid mistake I did.
Solution: Right click on the .asmx file in Visual Studio's Solution Explorer and select "View Markup". Verify that the value for the Class attribute is correct and not pointing to the wrong class. For some reason, the mismatch of the CodeBehind file and the Class name will throw this error instead of something more relevant.
Back story: Working on legacy code and wanted to use an .asmx web service to remain consistent with the rest of the code base. In VS2017, I couldn't find where to add that file so I just copied another .asmx file and renamed it. I should have known better. The issue is slightly masked because you are taken directly to the code behind file when you double click on the .asmx in the solution explorer, so it's easy to overlook that renaming the file does not update the Class attribute.