Coldfusion onRequestStart show some error - coldfusion

I try to write a onRequestStart function in application.cfc and code is
function onRequestStart(requestname){
if(!structKeyExists(session, "UserId") or !structKeyExists(session, "LoggedIn") ){
if(!(find("login",requestname) > 0 or find("signup",requestname) > 0)){
location("/mobile/index.cfm",false);
}
}else{
location("/mobile/dashbord.cfm",false);
}
}
the above code if condition is working ,after login the else condition will show This page isn’t working127.0.0.1 redirected you too many times. this error. why show this error , i am new in coldfusion please help me to solve this issue.

You are trying to locate the dashbord from dashbord page, Incase you are hitting the page like this and it will show the issue of redirected you too many times , so you need to put some condition in else statement like below,
!find("dashbord",requestname) > 0

Related

Javascript/php - After page Refresh, return to page anchor

I have a single page with numerous html anchor points.
I need to refresh the page every 10 seconds to get new incoming data from my database, the page refresh does this.
What I need is if, I am viewing another anchor point which is another page, I wish to be returned to that anchor point after the refresh happens.
Here is what I have, which runs fine but doesn't return me to the anchor I was viewing:
function refresh() {
if(new Date().getTime() - time >= 10000)
window.location.reload(true);
}
This above, refresh's the page then returns me to the default anchor point #menu
I have also tried this to be returned to the current view anchor point, but this doesn't work, it won't even run:
function refresh() {
if(new Date().getTime() - time >= 10000)
window.location.href = 'driver.php#<?php echo $_SESSION['loc'];?>';
window.location.reload(true);
}
Also tried it without the php coding it still won't run:
function refresh() {
if(new Date().getTime() - time >= 10000)
window.location.href = 'driver.php#show_requests';
window.location.reload(true);
}
Any help is much appreciated.
As I couldn't work out a result to use the one page, I solved the issue by using multiple pages and just set a refresh on each individual page. A bit messy, but it works.

I m inserting my data uthrough page item using request process it gives an error fetch more then one row please give me a solution

var a = $v('P1995_LUMBER');
if ((a = '1')) {
apex.submit({
request: "CREATE",
set: {
LUMBER: "P1995_LUMBER",
LST_NME: "P1995_LST_NME",
FST_NME: "P1995_FST_NME",
},
});
} else if (a != '1') {
apex.submit({
request: "Update",
set: {
LUMBER: "P1995_LUMBER",
LST_NME: "P1995_LST_NME",
FST_NME: "P1995_FST_NME",
},
});
} else {
alert("bang bang");
}
Couple of things:
JavaScript's equality check is either == or === (more details here). (a = '1') assign '1' to the variable.
It seems like you're not using the apex.submit process correctly. Typically, you would set the item's value
e.g.:
apex.page.submit({
request: "SAVE",
set: {
"P1_DEPTNO": 10,
"P1_EMPNO": 5433
}
} );
Although, by looking at your JavaScript code, I would say you don't even need to use JavaScript.
Whenever you submit a page, all items on it are automatically sent to the server-side. You can then reference them using bind variables. You could then simply have two process, one for the Create and one for the Update, each having the corresponding insert/update statement using the different items on your page.
Usually what you will see is a page with two buttons for Create/Edit. They will have a server-side condition so that only the correct one is displayed.
Try creating a Form type page (form with report) using the wizard, and you'll see how everything is done.
Without seeing the page and the code you're using it's hard to tell what your issue really is, more details would be required.
That code does not have any sql in it so it is impossible to diagnose why you are encountering a TOO_MANY_ROWS exception. Run the page in debug mode and check the debug data - it should show you what statement is throwing the exception. If you need more help, post a proper reproducible case, not a single snipped of code without any context.

If statement inside cypress.io test

I'm new to testing and to cypress.io in particular, and I'm trying to test the registering flow in my app.
I want to check two scenarios -
If the user is trying to register with an existing username, an error message should be popping up
Else if proper inputs are inserted, the username is successfully registered
How can I do so in one test? Is there an option to use if statement with cypress?
Thanks a lot in advance.
You can do something like:
If(Cypress.$(‘error msg locator’).length > 0) {
//error msg displayed.Do something
}
else {
//success login.Do something
}

Access the page if user is not loggedin?

I have login in my new application that checks on each request if user is logged in. If user is not logged in automatically will be redirected to the login page. I have situation where user clicks on Forgot Password. In that case I generated temporary link that will direct user to reset.cfm page. However problem is that user is not logged in and if I try to click on the link that should direct me to reset.cfm my code will direct me instead to login.cfm. Here is logic that I use in Application.cfc:
public boolean function onRequestStart(required string thePage) output="false" {
local.page = listLast(arguments.thePage,"/");
//onApplicationStart();
if(!listFindNoCase("Login.cfm,Authentication.cfc",page)){
if(structKeyExists(SESSION, "loggedin") AND SESSION.loggedin EQ false){
location(url="https://example.com", addToken="false");
}
}
return true;
}
As you can see in the example above, on each request I check the flag loggedin. I'm wondering how I can let the user access Reset.cfm?token=94129873129 link to the page? I would like to keep my logic to work the same for the users that are not logged in. At the same time I need to give them an access to Reset.cfm. If anyone have suggestions how this can be achieved or better way to handle this please let me know. One solution that I was thinking about was this solution, in Main.cfm:
<cfif structKeyExists(url,"token")>
<cfinclude template="Reset.cfm">
<cfelse>
<cfinclude template="Login.cfm">
</cfif>
If url parameter token exists then direct user to Reset.cfm if not to Login.cfm.
Hello you can write a conditions like below, Please add whiteList concept. In that while list you can added the file list ( What are file you can access without login. Here I gave example reset.cfm and register.cfm the both file we can access without login. ) Then put condition on these like below.
public any function onRequestStart(required string thePage) output="false" {
local.page = listLast(CGI.SCRIPT_NAME,"/");
local.whiteList = ['reset.cfm','register.cfm']; // Here you can add what are pages you want to access without login.
if( local.page NEQ 'login.cfm' AND !StructKeyExists( session, "loggedin" ) && !arrayFindNoCase(local.whiteList,local.page ) ) {
location( url="login.cfm", addtoken='false' );
}
}
I hope it will helpful to you. Please let me know your thoughts on these.

accessing session data

I am setting a custom session in the catalog/controller/checkout/cart.php controller. All it does, it checks if a value is set or not.
if (isset($this->request->post['no_tax']) && $this->request->post['no_tax'] == '1')
{
$this->session->data['no_tax'] = true;
}
elseif (isset($this->request->post['no_tax']) && $this->request->post['no_tax'] === '0')
{
unset($this->session->data['no_tax']);
}
I can then access this in the catalog/model/shipping/totalbased.php model file,
isset($this->session->data['no_tax'])
The problem is, I need to send additioanl information in the order to the admin, which is done in the catalog/model/checkout/order.php
I've done a check in there:
if(isset($this->session->data['no_tax']) )
{
//do something
}
$mail->send();
The do something, simply adds a PDF. The problem is, the PDF isn't attached.
In the error.txt, I get: 2012-05-14 14:42:11 - PHP Notice: Undefined index: no_tax in /var/www/vhosts/site.com/httpdocs/catalog/order.php
Can I access the session this way?
Thanks
The code looks fine from what I can see, and yes you can access the data like you've shown. The error you've had looks like you have tried to access the session data directly at some point without checking it's set, causing the notice