call to controller function from email message not found - .htaccess

First let me say I'm new to CI and bootstrap and had very minimal exposure to php before this project. That said, I did browse the questions for a solution to my sitiation. This seems to be a popular one.
In my case, the controller is visible and running for the rest of the site, this is it's only error. All other pages are working. My forgot password email is working end-to-end just fine and it's using the same concept except it does not pass a parameter.
I'm implementing an email verification system during registration. I got most of my code from the CI demo and everything is working except the return to the site from the email message. When the user clicks the register button in the email, they are redirected to the proper location with the reg_key attached.
After clicking the email message, this is what the browser has as its url:
https://mr_marvel.com/quest/users/confirm_email/d83df0d58637d4fca2d52dcdbb3ccb4f
The user receives a 404 message even though the function is available in the controller.
Here is the route.php entry:
$route['users/confirm_email'] = 'users/confirm_email';
Here is the function in Users.php that the email is trying to call:
public function confirm_email($reg_key) {
// from email
if($this->uri->segment(3)) {
$reg_key = $this->uri->segment(3);
if($this->user_model->verify_email_key($reg_key)) {
$data['message'] =
'<h1 align="center">Your Email has been successfully verified, now you can login</h1>';
}
else {
$data['message'] = '<h1 align="center">Invalid Link</h1>';
}
}
else {
redirect('users/login');
}
}
here is my .htaccess (residing in the home folder where folder application resides:
And .htaccess contents:
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|images|js|css|uploads|favicon.png)
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^(.*)$ ./index.php/$1 [L]
I've scoured google searches but can't find anything that directly corresponds to my issue.
Hoping someone can spot my issue.
A tremendous thank you for checking it out!
Dennis

Well, looks like I found the answer. For all of those who sometimes encounter enigmatic errors, be sure you use the server your programming to, it's an easy mistake to make if your working both at the same time.
In my case, from my prod server localhost, I was sending an email out with a link to my production server which does not have any of the email registration code/forms yet. As soon as I fixed the change to http: from https: and localhost from my prod server, it worked perfectly.
Hope my mistake helps someone in the future.
Dennis

Related

Stripe webhook test error 302

I am trying to test a stripe webhook for subscription trial ending. When I go to send the test even to my webhook receiving route I get error 302. I am using a middleware called stripe-webhook-middleware. My route looks like this:
app.post('/stripe/events',
stripeWebhook.middleware,
stripeEvents
);
I know that route goes against what they docs say but I did get it directly from the package creator. So it should work, then I have the stripe-events.js from the package. I am just adding in a console.log to the route to find the correct data I need.
I tried different webhooks and all give the same error, it has to be in how I have it set up. I hope anyways.
Edit **
I have also done a new route that is just a basic post route with a console.log and still getting the 302 error. What could possible causes be? I can't post a github because of a credential I accidentally leaked.
I am/was using cloud9.io as my development environment and had my test site as private. That was causing stripe to need to login in order to do anything. I made it public and now it works. I had completely forgotten I had to login to see the site because I always was logged in to cloud 9 when I accessed the site. If you are getting a 302 error, make sure you don't need to log in to get to that route.
Just in case anyone sees this 302 error with Codeigniter 3, my webhook route was pointing to a Subscription controller that always exits the constructor if a user isn't logged in and authorised - so I moved the method to my Home controller (used for registration, login etc) thus:
$route['webhook']['post'] = 'home/webhook';
and the 302 error went away. I hope this helps a tired CI dev down the road.
Just in case someone receives this error with dJango, my webhook route was pointing to a language redirection. You can investigate it with curl -IvL http://localhost:8000/webhooks/stripe as #duck suggested above.
Here was my output:
HTTP/1.1 302 Found
...
* Issue another request to this URL: 'http://localhost:8000/en/webhooks/stripe/'
...
You can see the redirected URL in the output.
So, when I let Stripe CLI listen to that URL, it works:
stripe listen --forward-to localhost:8000/en/webhooks/stripe/

Codeigniter Controller class login form : 404 page not found

Im trying to combine several tutorials about Codeigniter and bootstrap and understand per codes so i can integrate it in my project. What i am trying to do right now is create a login form using the two framework.
And i setup my View according to the turotial included in Codeigniter 'user_guide/tutorial/static_pages.html' which my landing page is named as 'home.php' is inside the folder 'pages' and header.php, and footer.php is inside the 'templates' folder. I created also a controller: Page.php.
I also use .htaccess to hide 'index.php'. Now i follow this tutorial how to create a login page:
http://learnjquerybootstrap.blogspot.com/2015/01/login-session-using-codeigniter-and-bootstrap.html?m=1
-the only difference is this since i use htaccess:
<?php echo form_open(clogin/index); ?>
But when I try to submit the page i receive a: 404 page not found.
My navbar links are working fine. I understand that the codeigniter works like this:
http://localhost/myfolder/index.php/class/function/
so when i submit my form the url that show up is:
http://localhost/myfolder/clogin/index
and gives me: 404 page not found.
Question:
What is wrong with it?
is there something wrong with the tutorial that i am using? i check other tutorials and the controller structure is just the same, like on this link:
http://www.kodingmadesimple.com/2014/08/how-to-create-login-form-codeigniter-mysql-twitter-bootstrap.html
do i need to include clogin.php in route.php?
or is it about the htaccess? my
uri_protocol
is configured as
'REQUEST_URI'
in config.php. i tried other options but still the same.
Don't need include to route.
I recommented ready auth library.
If you use DevTools in your browser maybe "Network" tab of devtools can help you to why you get 404 error.
i already firgured it out.The mistake was in the route.php, since i tried to combine two examples.. i realized that the wildcard route that i included from the Codeigniter user guide will not work with the Clogin.php.
Since it was set as
$route['(:any)']='pages/view/$1';
So the url works as
http://localhost/myfolder/pages/view/clogin
instead of
http://localhost/myfolder/clogin.
I removed it and now it is working.

How to redirect user to 404 page not found error when non admin try to access wp-admin or wp-login.php

For security reasons I am trying to restrict my wordpress site admin and login panel access to non-admin users by rewriting the link, such that if user types in http://www.mysite.com/wp-login.php or http://www.mysite.com/wp-admin he is redirected to Error 404 page but if he types http://www.mysite.com/blah-login or http://www.mysite.com/blah-admin is redirected to my WP admin or login panel. I have following options to do that.
Rewrite .htaccess file which I am not good at and don't wanna mess up my site's .htaccess file.
Use $wp_rewrite class which I did by writing a small plugin, its code is given below.
register_activation_hook( __FILE__, 'activate' );
function activate() {
rewrite();
flush_rewrite_rules();
}
register_deactivation_hook( __FILE__, 'deactivate' );
function deactivate() {
flush_rewrite_rules();
}
add_action( 'init', 'rewrite' );
function rewrite() {
add_rewrite_rule( 'blah-admin/?$', 'wp-admin', 'top' );
add_rewrite_rule( 'blah-login/?$', 'wp-login.php', 'top' );
add_rewrite_rule( 'blah-register/?$', 'wp-register.php', 'top' );
}
It works perfectly only problem is it does not restrict access to wp-admin, wp-login.php or wp-registe.php (Which is must).
I can write following rule to a new .htaccess file.
AuthUserFile /dev/null
AuthGroupFile /dev/null
AuthName "Wordpress Admin Access Control"
AuthType Basic
<LIMIT GET>
order deny,allow
deny from all
allow from xxx.xxx.xxx.xxx
</LIMIT>
and place it under wp-admin folder, it has 2 drawbacks one is it will only restrict access to my wp-admin folder not wp-register.php or wp-login.php and second is I am a DHCP client so allow from xxx.xxx.xxx.xxx will not work for me.
I could use a combination 2nd and third rule but it will definitely not work because I cannot provide an alternative permalink to a overall blocked folder.
As for a last resort I could use wp-modal plugin's permalink rewriting capability, it works like a charm but this plugin is not compatible with my theme.
So is there really a solution to my problem?
I use this snippet to redirect people away from the backend if they're not already logged in. You could modify it to point to your 404:
// BLOCK BACKEND ACCESS FOR NON-ADMINS
add_action( 'init', 'blockusers_init' );
function blockusers_init() {
// If accessing the admin panel and not an admin
if ( is_admin() && !current_user_can('level_10') ) {
// Redirect to the homepage
wp_redirect( home_url() );
exit;
}
}
Just change the URL from the home_url() function to your 404 page under wp_redirect.
I assume that you're trying to protect yourself from brute-force attacks? Why not just limit the frequency of allowed login attempts? There is a pretty solid plugin called "Limit Login Attempts" which will track per IP and the use of cookies.
Check it out here: http://wordpress.org/plugins/limit-login-attempts/
Trying to mask the login page is an interesting idea, though. You could just create your own login page somewhere and have it interact with a custom login script that you write. This would allow you 301 redirect the login pages to a 404 page without messing with any core functionality.
You could have a form at something like https://yourwpsite.com/supersecretlogin and then have it POST to a custom handler that uses the wp_signon method. Here's an example of how to log someone in without using wp-admin:
$creds = array();
$creds['user_login'] = $_POST['user'];
$creds['user_password'] = $_POST['password'];
$creds['remember'] = true;
$user = wp_signon( $creds, false );
if ( is_wp_error($user) )
exit($user->get_error_message());
header('Location: https://yourwpsite.com/wp-admin');
http://codex.wordpress.org/Function_Reference/wp_signon
Hope that helps!

Routes in Codeigniter

I want to have a clean URL in CodeIgniter based application for User's Profile Information.
Please Take a look at URL formats below.
Actual URL : http://www.mydomain.com/index.php/users/profile/user1
I'm expecting users to have Personal URL's like
http://www.mydomain.com/user1
http://www.mydomain.com/user2
http://www.mydomain.com/user3
URL http://www.mydomain.com/user1 should process http://www.mydomain.com/index.php/users/profile/user1 in background execution.
I will be removing index.php from URL using Route library.
Thanks in advance for any sort of help.
Have a look at https://www.codeigniter.com/user_guide/general/routing.html.
$route['user(:num)'] = "users/profile/user/$1";
If you mean you want /anyusername to route to the users controller, you would have to put:
$route['(:any)'] = "users/profile/$1";
At the bottom of routes.php and every non user-URL above it. Otherwise every URL would be routed there, obviously. You will need to implement some mechanism in the users-controller to throw 404-errors, since you are routing all requests not catched in the routing rules above.
IN config/routes.php
add this line
$route['user(:num)'] = "users/profile/$1";

Redirect login component in .htaccess Joomla -> Community Builder

I'm building a website with Joomla and Community builder.
What I need help with is redirecting to specific page when user is not logged in!
After pressing module link outside Joomla:
index.php?option=com_jevents&task=icalrepeat.detail&evid=16&Itemid=490&year=2011&month=11&day=17&title=personalefest-jysk&uid=3f380241e99b5db330b8e05f8920340a&login=1
Joomla redirecs to this: index.php/component/users/?view=login
Where I really want to go to this: /index.php/component/comprofiler/login (which is CB component's login view)
They go through some interesting things here
Issuing a redirect from a Joomla module
and here
RewriteRule to redirect with url that got parameters
But I'm not able to fully understand how I make the right changes.
The first link you provided has the answer:
You create a public article which you can call "dispatcher.php" and it will have the following code:
<?php
$user =& JFactory::getUser();
include_once JPATH_COMPONENT . DIRECTORY_SEPARATOR . "controller.php"; // assuming com_content
if (!$user->id) { //user is not logged in
$contentController = new ContentController();
$link = JRoute::_("/index.php/component/comprofiler/login");
$contentController->setRedirect($link);
return;
} else { //the user is logged in
$contentController = new ContentController();
$link = JRoute::_("/index.php?option=com_jevents&task=icalrepeat.detail&evid=16&Itemid=490&year=2011&month=11&day=17&title=personalefest-jysk&uid=3f380241e99b5db330b8e05f8920340a&login=1");
$contentController->setRedirect($link);
return;
}
?>
Instead of providing a link to your article - you provide a link to dispatcher.php which will "decide" where to redirect the user (to your page - if the user is logged in - else to the other login page)
You might have to debug it - since I don't have time to test it myself.
Good luck!

Resources