I am building a Silverstripe site that allow users to sign up to something. I have a few pages that in the CMS I set the page visibility to "Logged-in users" this is great but the default action is to redirect to /Security/Login. Is there a simple way of change the redirect for normal pages to goto etc /Account/Login and leave the default /Security/Login for CMS users?
Thanks
With the help of another plugin, I used this bit of code
public function onBeforeSecurityLogin()
{
$backUrl = $this->owner->getRequest()->getVar('BackURL');
if (!strstr($backUrl, '/admin/')) {
if (Controller::curr()->class != 'Account') {
$link = 'account/login' . '?BackURL=' . urlencode($backUrl);
return $this->owner->redirect($link);
}
}
}
And I also extended the Security Class to create my own handler and form for logins
You can set ?BackURL=/Account/Login in your links, or in the Session.
Alternatively set the config variable, E.g:
Security:
login_url: Account/Login
Related
I've installed Wordpress inside my Laravel app to manage blog content and other stuff.
Now I need user Laravel authentication for accessing wordpress. Is it possible to do that ? If yes, how?
As per my understanding you need Laravel authentication for accessing wordpress blog. Unauthenticated users should not be able to access it.
If this is the case. Solution is listed below.
Your Blog url: site_url/blog { it can be wordpress folder name inside laravel }
Edit ( routes/web.php )
Route::get('/blog', 'AdminPagesController#blog');
AdminPagesController
namespace App\Http\Controllers;
use Request;
use Carbon\Carbon;
class AdminPagesController extends Controller {
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct() {
//It will check if logged in, if not redirect to login page
$this->middleware('auth');
}
public function blog(){
// Simple return, wordpress will handle rest if authenticated person access the url
return;
}
}
The only way I can think of to make this work is reading the index.php from WordPress inside your Laravel controller with
ob_start();
require '/path/to/wp/index.php';
$html = ob_get_clean();
return response($html);
However if you want to use Laravel with a CMS, there are better (native) options like October CMS.
How to redirect user to a particular page after the user is successfully registered into the site?
Here drupal_goto() does not work. We need to work with the form redirection. How can this be achieved?
// include the Url namespace in your custom module
use Drupal\Core\Url;
// Add CUSTOM SUBMIT HANDLER FOR REGISTRATION
$form['actions']['submit']['#submit'][] = '__tmp_registration_submit';
function __tmp_registration_submit(&$form, FormStateInterface $form_state) {
// set relative internal path
$redirect_path = "\user\uid\payment-history";
$url = url::fromUserInput($redirect_path);
// set redirect
$form_state->setRedirectUrl($url);
}
Maybe a bit heavy, but you could also use the Rules module.
I have a site www.example.com and a wordpress blog at www.example.com/blog.
I want my user to login at www.example.com and $_SESSION['USERNAME'] is passed to www.example.com/blog.
I just want to know, how can i automatically login the end user to wordpress blog, once they login to my main site.
For now i am passing $_SESSION['USERNAME'] and using a plugin external database login, which I have linked to my main site database.
Any function that is used to login to wordpress using session username will be helpful.
Wordpress don't use $_SESSIONyou need to code a plugin or to add some code to your functions.php to do this - cf http://www.frank-verhoeven.com/using-session-in-wordpress/
You should add something like this :
function init_sessions() {
if (!session_id()) {
session_start();
}
}
add_action('init', 'init_sessions');
NB: there is also a plugin to manage Sessions with Wordpress, maybe you can use/hack this http://wordpress.org/plugins/wp-session-manager/
I have been reading on this. Here is what I have found as I am in the same issue. In your wp-config.php file at the top add:
add_action('init', 'myStartSession', 1);
function myStartSession() {
if(!session_id()) {
session_start();
}
}
HOWEVER, " The data stored in the session doesn’t go away when the user logs out or logs into a different account. For that you need to destroy the session. ..." (exerpt from this nice write up). It explains you also need to:
function myEndSession() {
session_destroy ();
}
if you can get wp user_id you could do something like this:
function init_sessions() {
if (user_logged_on_site) {
#session_start();
$user_id = $_SESSION['wp_user_id']; //this has to be set when the user logs on your website
wp_set_auth_cookie( $user_id); //log in the user on wordpress
}
}
add_action('init', 'init_sessions');
Documentation on wp_set_auth_cookie http://codex.wordpress.org/Function_Reference/wp_set_auth_cookie
I can't seem to get the page route module to move to the next page, after it creates the profile page.
1. I created a route called Registration
2. Inside the route I have two pages,
a) Content Profile Editing Form
b) Node Add form
The page route should take the user to the profile create page, and then route to the create a group node page.
Problem is after the user is directed to the content profile editing form and clicks next, it redirects back to the profile form instead of going to the next page.
Any ideas, this does not seem normal at all.
Charles
thanks for the help. I found the solution. I thought it might be a module or a coding change I have made so I decided to create a new drupal install and only install the modules needed.
I still had the same problem, very strange indeed. I eventually found the this article, with someone whom has had the same issues.
http://drupal.org/node/699458
The following needs to be added to the pageroute.module
<?php
/**
* Submit function for all pageroute forms, except submit-like tab buttons
* Redirect to the set target.
*/
function pageroute_page_form_submit($form, &$form_state) {
$page = &$form_state['page'];
$route = &$form_state['storage']['route'];
/* hack saturnino part */
if(!empty( $page->options['neighbours']['forward']) )
{
drupal_redirect_form($form, $route->path.'/'.$page->options['neighbours']['forward']);
return;
}
/* hack saturnino part */
// no page access -> try redirect
if (!$route->checkPageAccess($page->name, $form_state['target'])) {
unset($form_state['storage']);
$form_state['rebuild'] = FALSE;
if ($route->options['redirect_path']) {
drupal_redirect_form($form, pageroute_get_redirect_path($page));
return;
}
drupal_not_found();
pageroute_exit_now();
return;
}
$form_state['rebuild'] = TRUE;
}
?>
thanks for your help
We have certain users in our member list that have a role "vendor" attached to them. All such members are to be redirected to a certain page upon login. How can this be accomplished?
There is more than one way to skin this cat...
This is my preferred Drupal 7 method:
function hook_user_login(&$edit, $account) {
$edit['redirect'] = 'node/123';
}
For Drupal 7
Action --> admin/config/system/actions - Redirect to URL
then enable your trigger module
Trigger --> /admin/structure/trigger/node
if your are trying to login redirect just follow this(select user tab in the page)
go to --> admin/structure/trigger/user
then
Trigger: After a user has logged in
choose an action -->Redirect to URL and assign.
Then clear the cache.
It will work for you!
You can define actions and triggers in Drupal:
Action(admin/settings/actions)
- Redirect to a specific page
Trigger (admin/build/trigger/user)
- After user has logged in
Try this.
EDIT (see comments):
Create a small module to check on a user's login process what role he has and then redirect if neccesary.
drupal_goto => redirect-function in drupal
hook_user =>triggers on user operations
And for the user's roles:
GLOBAL $user;
$roles = $user->roles;
$vendor = in_array('vendor', $roles);
$vendor then holds a true/false value will decide to redirect or not.
If you don't know how to do this, just post here and I'll write the module for you. But this would be a good practice for writing future drupa modules for you perhaps. :)
There are 2 ways in DRUPAL 7
1) Using action and trigger
see this http://drupal.org/node/298506
2)if using custom module
function YOURMODULE_user_login(&$edit, $account) {
if (!isset($_POST['form_id']) || $_POST['form_id'] != 'user_pass_reset' || variable_get('login_destination_immediate_redirect', FALSE)) {
if(in_array('THE-ROLE-WANTED-TO-REDIRECT',$account->roles)):
drupal_goto('PATH');
else: drupal_goto('user/'.$account->uid);
endif;
}
}
You can use Rules
Events: User has logged in.
Condition: User has role
Actions: Page redirect
There are modules that do this (besides Trigger+Actions), such as LoginDestination: http://drupal.org/project/login_destination. This Drupal forum post has a bit more info about it as well.
following condition for hook_user
if($op =='login') drupal_goto("your path");
This can be achieved by using a combination of content access and login toboggan modules. You'll be able to restrict pages and prompt user to login to access them.
First set the conditions in form preprocess (for example I want to redirect only users that logged in using the form at node page)
function YOURMODULE_form_user_login_alter(&$form, &$form_state, $form_id)
{
$pathArguments = explode('/', current_path());
if (count($pathArguments) == 2 && $pathArguments[0] === 'node' && is_numeric($pathArguments[1])) {
$form_state['nodepath'] = current_path();
}
}
than define redirect:
function YOURMODULE_user_login(&$edit, $account)
{
if (isset($edit['nodepath']) && !empty($edit['nodepath'])) {
drupal_goto($edit['nodepath']);
}
}