I have a problem using Drupal 7 admin login in my custom theme. After creating a custom theme when I try to submit the login form, I receive the following error:
"Access denied You are not authorized to access this page."
When I revert back to a default theme (eg. Bartik), everything works fine again.
After reading a lot of solutions, I can't seem to find the right one for me. Any ideas?
EDIT:
The problem seems to be the "drupal_render(drupal_get_form('search_block_form'))" in my page.tpl.php. For my theme i need a form markup without any container, so i used this function to render the form. The solution for me was to change it like:
$form_array= drupal_get_form("user_login");
$form = drupal_render($form_array);
echo $form;
First take a look at this:
your-drupal-parh/user -if this link takes to the login form, then you just need to customize the login form.
If it doesn't help, try create a login.
Update templete.php
function themename_theme() {
$items = array();
$items['user_login'] = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'themename') . '/templates',
'template' => 'user-login',
'preprocess functions' => array(
'themename_preprocess_user_login'
),
);
return $items;
}
function themename_preprocess_user_login(&$vars) {
$vars['intro_text'] = t('Custom login form');
}
themename is the name of your theme.
path points to the path where the user-login.tpl.php file exists in your theme directory[here drupal_get_path('theme', 'themename') . '/templates' means that the user-login.tpl.php file is in the theme's template directory].
Code for user-login.tpl.php:
<p><?php print render($intro_text); ?></p>
<div class="redha-user-login-form-wrapper">
<?php print drupal_render_children($form) ?>
</div>
Clear cache and see what happens.
Related
Ok, so I have a web app that uploads a file to the webserver. My input fields in my upload form include: type of upload (dropdown list), title, description, and the file to be uploaded, which is a PDF.
Once the PDF file is uploaded, the download link will appear in another page for the public to see. In addition, the title typed in the input field is the download link.
Now, I want to change my code. Instead of downloading it directly when the link is clicked I want it to open in a new tab, so the users can first look at the PDF file then download it from there.
Here are my codes.
Controller:
public function sendFile(){
$id = $this->request->params['pass'][0];
$staffup = $this->StaffUpload->find('first', array('conditions' => array('iduploads'=>$id)));
$this->response->file($staffup['StaffUpload']['dest'], array('download' => true, 'name' => $staffup['StaffUpload']['title']));
return $this->response;
}
The code above is the download function.
public function resources() {
$this->layout = 'website';
$this->set('staff_uploads', $this->StaffUpload->find('all', array('conditions' => array('type' => 'Resource'))));
}
The code above is the view wherein I show all uploaded files which type is Resources.
View:
<?php
foreach ($staff_uploads as $staff_uploads) {
?>
ul>
<li>
<?php
echo $this->Html->link($staff_uploads['StaffUpload']['title'], array('controller' => 'websites', 'action' => 'sendFile', $staff_uploads['StaffUpload']['iduploads']));
?>
</li>
</ul>
<?php
}
?>
The code above shows the view.
So yeah, back to the question. I want to change the download link to a link in which when clicked, will show the PDF file in a new tab. How do I do that? And by the way, the codes posted above are all working properly. I just want to change my code so that it will be viewed in a new tab when clicked.
Thank you!
According to the docs:
echo $this->Html->link(
'Enter',
'/pages/home',
array('target' => '_blank')
);
I am currently building a wordpress theme. For the menu, I just want to display all the pages that are created in the order that they are created in (i.e. I don't want users to have to go into the 'menu' section of the site and create their own).
I tried using wp_page_menu and this worked HOWEVER I need to add a walker class to expand the functionality, which you can't do with this function. So I need a way to display all my pages with using wp_nav_menu as my code - is there a way to do this?
Here is my code currently:
<nav id="nav">
<?php wp_nav_menu( array( 'walker' => new Clapton_Nav_Walker ) ); ?>
</nav>
Try this
functions.php this below code register a menu for use
<?php register_nav_menu( 'main_menu', 'Primary Menu' ); ?>
// remove <?php ?> tags if it already there
index.php or wherever you want, below code output the menu
<?php wp_nav_menu( array( 'theme_location' => 'main_menu','walker' => new Clapton_Nav_Walker ) ); ?>
Build menu in WordPress Dashboar -> Appearance -> Menus -> Manage Locations
made a simple thankyou page (e.g. /product/3/thankyou) based on a menu callback in a custom module. the content shows up fine in the normal page layout but i want the regions and blocks to show up and they don't. suggestions?
// menu callback
function custom_menu() {
$items = array();
$items['product/%/thankyou'] = array(
'page callback' => 'custom_product_thankyou',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK
);
return $items;
}
// theme function
function custom_theme() {
return array(
'product_review_thankyou' => array(
'variables' => array('node' => NULL),
'template' => 'product_review_thankyou',
),
);
}
// page callback
function custom_product_thankyou() {
$node = node_load(arg(1));
$output = theme('product_review_thankyou', array('node' => $node));
return $output;
}
I just tried your code in a drupal installation and i have no issues with missing blocks. Is it possible that you configured your blocks to be displayed only on certain pages?
The one block that i still couldn't get to show up (no matter what the block visibility settings were) was a 'menu block'. Problem was there wasn't a link for the thank you page in this block. So, I ended up having to add links on the configuration page with paths like product/[node_id]/thankyou, and then I disabled the links so they wouldn't be visible. Refreshed the page, and the block appeared.
To me this is a little annoying, as I kind of wanted this to be dynamic and not have to write in the product node ids. But either way, problem solved.
How would I create a login link on a CakePHP page that contains a query string with the current page so for example: domain.com/login/?back=/posts/This_is_a_post
and then how would I use this in the login method to send the user BACK to this url?
I have tried this: <?php echo $this->Html->link('Log in', array('controller'=>'users','action'=>'login','admin'=>false, '?'=> array('back'=>$this->here)), array('escape'=>false)); ?>
but it does this on the url /login?back=%2Fportfolio%2Fgt%2FCreatHive
how do I get it to NOT change the / in the URL
Cheers
The best way to do this is to store the last page visited in a session at some point, probably when the page is loaded in the login action or something. Why you ask? As an attacked could make a link to your site eg: yoursite.com/login?back=mysite.com/login, so that when the user logs in, you send them to my site which is an exact duplicate of your login form and get them to login again. Voila, an attacker could now easily phish your users info.
With sessions there'd be no url encoding problems either. Just something like this in your login action:
$this->Session->set('back_to', $this->referer());
// Then if they have logged in:
$backTo = $this->Session->read('back_to');
if($backTo) {
$this->redirect($back_to);
} else {
$this->redirect($this->Auth->redirect());
}
Update - Try using named parameters instead:
For your link:
echo $this->Html->link('My Link', array('controller' => 'users', 'action' => 'login', 'url' => $url));
In your users login:
function login(){
if($this->Session->read('Auth.User')){
$url = $this->params['named']['url']
// encode/decode url
$this->redirect("$url");
}
}
You can always use urlencode() and urldecode() for the $url variable.
You also need to make sure your form also sends the URL back to the login function:
echo $this->Form->create('User', array('controller' => 'users', 'action' => 'login', 'url' => $url));
I have an issue with cake's auth that I simply can't seem to get past (i've been debugging and trying different tutorials for the last two days). As far as I can see it should be very simple, the problem is whenever i try to login, it just refreshes the login page. I cannot for the life of me figure out why! My only conclusion is that there must be something (basic) which tutorials take for granted that I have missed.
Here are a couple of snippets:
users_controller.php
class UsersController extends AppController {
var $name = 'Users';
function beforeFiler() {
parent::beforeFilter();
}
function login() {
}
function logout() {
$this->Session->setFlash('You have successfully logged out.');
$this->redirect($this->Auth->logout());
}
}
app_controller.php
class AppController extends Controller {
var $helpers = array('Html','Form','Javascript');
var $components = array('Auth');
function beforeFilter() {
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
$this->Auth->loginRedirect = array('controller' => 'contents', 'action' => 'index');
$this->Auth->logoutRedirect = array('controller' => 'contents', 'action' => 'view');
$this->Auth->loginError = 'Something went wrong';
$this->Auth->allow('register', 'view');
$this->Auth->authorize = 'controller';
$this->set('loggedIn', $this->Auth->user('id'));
}
function isAuthorized() {
return true;
}
}
login.ctp
<div class="midCol short">
<h3>Login</h3>
<div class="loginBox">
<?php e($form->create('User', array('controller'=>'users','action'=>'login')));?>
<?php
echo $this->Form->input('username');
echo $this->Form->input('password');
e($this->Form->end(array('label'=>'Login', 'class'=>'loginButton button png')));?>
</div>
</div>
Any help would be greatly appreciated, this has me tearing my hair out!
Just for documentation as I had difficulties finding an answer for CakePHP 2.x on the web. This stuff needs to be "correct" in order to use Form authentication:
The config needs to be right, e.g. in your UsersController (the fields config is really only required when names differ in the DB):
public $components = array(
'Auth' => array(
'authenticate' => array(
'Form' => array(
'fields' => array(
'username' => 'username',
'password' => 'password'
),
)
)
)
);
You have to use the Form Helper: Form->create adds a hidden input field ("post"), and the names of the input fields generated by Form->input() follow a convention that the Auth component expects.
User->login must not pass custom data to Auth->login(). The Auth component will take the auth data from the form (= request).
Thanks for the advice, but I ended up scrapping it and building again from scratch. Not exactly sure why it was originally breaking, probably not calling inbuilt functions with American English!
The Auth component will redirect to the page before you logged in. If that page was the login page that's where it'll redirect to.
When you're testing, it's likely that you're refreshing the login page, so on successful login that's where you're redirected to. You can check this by trying to perform an Auth protected action after logging in.
This gives me a lot of headaches as well - I think the current functionality of the component is a little clumsy in that respect.
I had the exact same problem and found that I had to restart mySQL service. Once it was restarted I stopped getting the login page being redirected. Hope that helps.
Gonna throw something in here. I was having an almost unresolveable problem with cakephp authentication. Ended up doing some debugging around it and found that during my database prep I had created a field for the password which was perfectly able to store normal size passwords... but.... when you start applying password hashing you need a lot more. My code was fine, but I had to add a bunch more space into the VARCHAR field for the password before I could log in. If you're having a problem with authentication - make sure your password field is adequately sized and not getting truncated like mine was. Took me a whole day to find that. DOH!
Correct me if i am wrong but must there not be code for redirection or something inside the function of login
function login() {
}
should it not be something like
public function login()
{
if ($this->request->is('post')) {
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error(__('Invalid username or password, try again'));
}
}