FOSUserBundle: two login templates for the the login action - symfony

I have installed FOSUserBundle. Now I would like to have two different templates for the same login action: one for the login in the layout and the other one for a standalone login page.
What is the way to do this?

You can leave the login form from FOSUserBundle as is (or overwrite it by moving it to app/Resources). This form will be used for the standalone login page. For other sections of the website you can create a new login form in twig yourself, the important thing is that your form will need to have all the fields named like the one from FOSUserBundle and to have the action path set to the login check page (because your using FOSUserBundle the path is "fos_user_security_check").
The names for the fields you will find here:
https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/views/Security/login.html.twig
You can see that you need also a generated csrfToken. You can generate it in your controller, also inspired by the guys from FOSUserBundle: https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Controller/SecurityController.php#L43

Related

Plugin with custom registration and login

I've created a login and registration pages in a plugin. I've created them as custom templates within my plugin.
I would like a page I created within my plugin as a third custom template to have login and register buttons on there. I can't work out how to do this. Please could I have some advise or someone point me in the right direction

Sulu cms: Create bundle for custom controller

I am using sulu minimal edition.
So i want to create bundle for my custom controllers.
I have contact form in my website.
On form submit i want redirect to symfony route.
Save data in custom table and display in admin area user role wise. Whats best way?
I follow http://blog.sulu.io/how-to-develop-a-bundle-in-the-sulu-admin-1
but php on ./bin/websiteconsole debug:router my new routes created in controller not showing.
Sounds like you use annotations. Dit you try defining your route with XML?
As far as I know annotation - and XML defined routes can't be mixed within the same bundle (some please correct me if I'm wrong). Since Sulu uses XML I'd stick to that for the sake of consistency.

Drupal 7 - Handling multiple type of users

I need to create a website for a client using Drupal 7, the only problem is that I don't know how to handle multiples login forms and permissions.
The goal is that A type of user must be allowed to browse and do some stuff on the website but they can't post offers, however B type of users can only post their offers and manage their contents, the system is just as Upwork.
How can I achieve this ? I'm not good at PHP but I know how to use Drupal, so are there modules that can help me to do what I want?
This is exactly how Drupal works by default using role based permissions. You won't need to install a module or have different login forms.
Start by creating different roles. RoleA can view certain content types and maybe post comments. RoleB can do everything RoleA can do plus post offers and manage their own content. You can control create/edit/delete permissions by content type. It can all be done using the point and click admin interface.
On admin page /admin/user (root relative path to admin page) you can see your site users. There's also link "+ Add user" for creating new user. So if you edit/create an user, on user edit page there is a section "Roles" where you can set what roles that user can use. One role may be "Browse some stuff" and other "Edit some stuff".. You can add/edit roles at admin page /admin/people/permissions/roles. So create the roles you need there.
And to precisely set what role can do what there is admin page: /admin/people/permissions. So when you create all the roles you need, go to that page to set permissions and after that you can assign roles to your users.

SonataAdmin, add a page in the dashboard

I'm working on Symfony2 and SonataAdminBundle.
I need to add a module in my admin for send email to all users.
So, i need a new page with a link in the menu.. How can i do that simply ?
Fow now i have my blocks in my dashboard, so one one page..

How do I remove the user registration/login form?

My website doesn't need the user login functionality. Only some users need to post new nodes.
How do I remove the user registration and the login forms in Drupal?
While it's technically possible to remove the login functionality, you shouldn't, because then your administrator could never log onto the site.
In order to remove the register functionality, you simply need to browse to admin/user/settings (for Drupal 6) or admin/config/people/accounts (for Drupal 7) and select the the "Only site administrators can create new user accounts" option.
While jhedstrom answer does work, I particuarly find that it doesn't fully address the issue.
Here's a simple way to remove the login form from the site on Drupal 7.
First, let's create a new simple page called Admin. Simply go to Content - Add Content - Basic Page. Enter whatever details you'd like such as title, body, etc. just make sure that under URL path settings you specify a common alias for adminstration, I used admin.
Second step, let's make sure that the login form only shows on the admin page we just created. Navigate to Structure - Blocks - User login (note tat the block name may vary from installation to installation), and hit Configure. Under Visibility settings select the option Only the listed pages so that the block only shows for the pages you specify on the input, and enter the alias you set on the step above (admin).
Finally, let's ensure that only administrators can create accounts, by following jhedstrom's suggestion. Go to Configuration - People - Account settings, then under Registration and cancellation, ensure that the box for Administrators Only is selected for the Who can register accounts? option.
I think this is a much nicer and detailed approach to ensure that the login form isn't displayed, considering you don't need people creating accounts on your site.
You can override it using hook_menu(), move login page in any other suitable for administrative needs place
You can disable the forms all together. In a custom module:
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
switch($form_id) {
case 'user_login':
case 'user_register_form':
$form['#access'] = FALSE;
break;
}
}
Depending on your needs, you can either create a custom page and set the login block there, so you and other administrators can login, or install HybridAuth module to allow visitors to login and register new accounts only through social media 3rd parties.
You can use the Disable Login Page module to disable the login page completely for the general public. Only the webmaster or site admins who have access to a secret key/value pair will be able to access the login page. Everybody else will get access denied at user/login page. This will work in Drupal 8 and Drupal 9.

Resources