I have a Laravel 8 project. Users are applying to be a creator from another web project, and we approve these applications from the project I am currently having problems with. In other words, the project we are talking about is an admin panel. Let me tell you what I want to do now. We approve the applications coming here with the create button in the admin panel and create the creator. However, this creator does not currently occur on Firebase. I also want this creator to be rendered in Firebase as well. I did some research and found something like Firebase Admin SDK for PHP. As far as I understand, I can perform this operation with the help of this SDK.
Then I went and wrote my codes to the create function inside the CreatorController, where the content of this Create Button is written. Here is my code that I wrote.
CreatorController.php-create function
public function create(Request $request){
$application = null;
$subscriber = null;
if($request->application_id!=null){
$application = CreatorApplicationForm::findorfail($request->application_id);
$subscriber = User::where([['email','=',$application->email],['role_id','=',4]])->get()->first();
}
return view('admin.creators.create',['application' => $application,'subscriber' => $subscriber]);
if(isset($_POST['create-btn'])){
$displayName = $_POST['name'];
$email = $_POST['email'];
$userProperties = [
'displayName' => $displayName,
'email' => $email,
];
$createdUser = $auth->createUser($userProperties);
}
}
I wrote the last if block in the function, the previous ones were already written.
Later, when I showed this to a friend, he said it wouldn't work for me. He said you wrote it in classical PHP form and told me to adapt it to Laravel. Also, I guess I need to sync the newly created user to the subscribers in the first if block.
Frankly, I'm a little confused. How can I solve this problem?
Related
I'm a noob junior so I apologise in advance if this is a very basic question and if it has been asked a gazillion times before.
I am basically trying to run another function when a user registers. After some googling I came upon: hook_entity_insert($entity, $type) from (https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_entity_insert/7.x) now, even though there are code examples it does not tell me where to put the code, how to get the data that is submitted etc...
Which file do I put the sample code to test. The sample code provided is:
function hook_entity_insert($entity, $type) {
// Insert the new entity into a fictional table of all entities.
$info = entity_get_info($type);
list($id) = entity_extract_ids($type, $entity);
db_insert('example_entity')
->fields(array(
'type' => $type,
'id' => $id,
'created' => REQUEST_TIME,
'updated' => REQUEST_TIME,
))
->execute();
}
First you should understand the hook system in Drupal. For Drupal 7 this page is a good start. It gives you a quick overview and understanding of the concept.
Understanding the hook system for Drupal modules
There is a specific hook that 'fires' after an user is inserted, named hook_user_insert
You don't need to use hook_entity_insert. In your custom module use below hook
when user registers.
function yourModuleName_form_user_register_alter(&$form, &$form_state) {
// Add your own function to the array of validation callbacks
$form['#validate'][] = 'yourModuleName_user_register_validate';
}
Refer
Hook into Drupal registration and validate user info against business logic
If you want to run a function after the user has registered, use hook_user_insert (or, if this needs to be run every time a user is changed, hook_user_presave).
In general: Hooks in drupal are functions that comply with a specific naming scheme. In the places where a hook is executed (i.e., on user registration), Drupal searches for all modules that contain a function where the function name consists of the module's (machine) name, followed by the hook name. For hook user insert, you would need to implement a module (or place your code in a module you already implemented), see documentation here. Supposing your module is called "custom_module", you then implement a function like so:
function custom_module_user_insert(&$edit, $account, $category) {
//Do what you wanted to do here
}
Hope this helps
I’m new to Laravel and OctoberCMS, there is a lot of documentation on both but because I don’t have much of an understanding of either I would really appreciate some help. It's also quite confusing trying to understand both at the same time, especially as there is way more documentation about laravel than October.
Currently, I wish to extend a plugin (Link to their extending plugin documentation). I need to use the session (username or email) from the rainlab user plugin (Link to their Git) and insert it into another plugin.
I'm upgrading the other plugin that currently relies on users entering their name via a form and replacing this with their username or email address once logged in.
My Layout contains the user plugin session:
{% component 'session' %}
The user plugin session works fine on the rest of my pages but I have gotten a 'value not found' error with my previous attempts using it with the plugin.
I know I need to either link the plugins or create a new one, and retrieve the username (or email) from the users database and insert it into another table, just can’t quite work out how to do this. To make matters worse I don’t have experience with MVC either!
Added this function (from an example I found) to the second plugin's Plugin.php page:
Plugin.php
public function boot()
{
Event::listen('rainlab.user.register', function($user) {
// Code to register $user->email to mailing list
});
}
But I got 'Undefined' error.
I've also tried adding a Routes.php file as I thought there may be an issue with middleware.
Routes.php
Route::get('/test', function () {
dd(
Auth::getUser(),
BackendAuth::getUser()
);
})->middleware('web');
Received this error:
"Call to undefined method RainLab\User\Facades\Auth::getUser()"
I’ve been banging my head against the wall for a week now and any tips or explanations would be greatly received. If you require any other bits of code please let me know. I haven't added any more bits of code as I know those pieces didn't work (being going around in circles and it would be a bit erratic and not much use) and I don't want to spam code on this page. I've shown the bits above to try and explain some previous thought processes. Also, it's the start of my project and not much code has changed from the generic code available to you from the OctoberCMS and User Plugin Gits.
I believe an explanation and some help here would benefit a lot of people, I can see I’m not the only one to have issues, partly down to the changes in the latest version of laravel.
Any thoughts and explanations would be much appreciated.
UPDATE:
To make it clearer where I need my session to appear I've included the code below. $name needs to be replaced by a new variable like email or username (from session).
components\Chat.php
$name = 'anonymous';
if ($n = Input::get('name')) {
$name = strip_tags($n);
}
$message = new Message(['text'=>$text, 'user_id'=>$user_id, 'name'=>$name]);
$message->save();
return $this->getMessagesOutput($message->id, [$message]);
}
It will be really Easy if you are adding session in layout {% component 'session' %}
now on entire page you can use {{ user.email }} directly in twig to get user email
if you need to use using PHP you can use Auth facade
this code must me in component which are included in page which is using that layout or in its life-cycle methods
// Returns the signed in user
$user = Auth::getUser();
echo $user->email;
you can not directly use route because route is separate from page execution so Auth will not work there.
"I need to use the session (username or email) from the rainlab user plugin (Link to their Git) and insert it into another plugin."
just create new component which have this code and include it in page.
can you share details what you need to do and how you are doing to get details and on which time you need to use that details so i can answer it precisely.
UPDATE
// by default name
$name = 'anonymous';
$user_id = 0; // if user is not logged in
// if user is logged in then use session
if($sessionUser = \Auth::getUser()) {
// if user didn't set name then you can assign some default value here or email
$name = $sessionUser->name != '' ? $sessionUser->name : $sessionUser->email;
$user_id = $sessionUser->id;
}
// not needed but if user want to edit its name then we use that one
if ($n = Input::get('name')) {
$name = strip_tags($n);
}
$message = new Message(['text'=>$text, 'user_id'=>$user_id, 'name'=>$name]);
$message->save();
return $this->getMessagesOutput($message->id, [$message]);
I'm making a fairly large symfony3 application. It's my first one and I must say I'm pretty amazed by the robustness of the framework. It's an application that lets users create "events". And every event is happening in a certain "location". I have two bundles "EventBundle" and "VenueBundle". A venue can host many events so there's a one to many relation between the two. At this point I have an event creation page with a dropdown input that is automaticly filled with the venues already in the database. The EntityType field made it easy for me to implement that relation. This is an awesome symfony feature.
Because it's possible that not every venue is already in the database at the moment of creating a new event, I want to use a small "quick create venue" modal window (based on zurb-foundation) in the event creation wizard. It's to prevent users from exiting the wizard to add a new venue.
I was struggeling for the past two or three days or so to have two forms from different entities on one twig page. I have already found the answer in this question: Symfony - Two forms from two entities on the same page. But the answer raised a second question for me. I think it's easier to explain if I first show the code I'm having right now:
public function createAction(Request $request)
{
$event = new Event();
$eventForm = $this->createForm(EventType::class, $event);
$venue = new Venue();
$venueQuickForm = $this->createForm(VenueQuickType::class, $venue, array(
'action' => $this->generateUrl('massiv_venue_quickcreate')
));
$eventForm->handleRequest($request);
if($eventForm->isSubmitted() && $eventForm->isValid()) {
$event = $eventForm->getData();
$event->setPostedBy(1);
$event->setUpdatedBy(1);
$em = $this->getDoctrine()->getManager();
$em->persist($event);
$em->flush();
return $this->redirectToRoute('massiv_event_homepage');
}
$venueQuickForm->handleRequest($request);
if($venueQuickForm->isSubmitted() && $venueQuickForm->isValid()) {
$venue = $venueQuickForm->getData();
$venue->setPostedBy(1);
$venue->setUpdatedBy(1);
$em = $this->getDoctrine()->getManager();
$em->persist($venue);
$em->flush();
}
In the createForm method of the second form (venueQuickForm) I added the option "action" with a url pointing to the venue controller's quickcreate action. That was my idea, I had this already in my code before I found the answer, but kept that line to see how it would behave. It turns out it is ignored because in that quickCreateAction method I simply put a "ok" response and that page is not shown when a press the submit button. The rest of the code works fine, the venue is saved in the database.
So I am about to delete that line, but is the code above indeed the way to go? Intuitively I want to keep both codes seperate so putting the "save venue" part in the Venue controller seems locic to me or is that not the way Symfony is designed to work?
I really need help in making modifications to a script I purchased which was designed using codeigniter (a system I am totally new to). The project is designed to have only two user roles with fixed permission (admin, others(is_logged_in)). After couple of hours of learning how MVC works I have been able to change so little yet insignificant stuff in project.
My big problem is this:
I want to use the script to complete a web POS app which I have been working on basically in native php, the project uses ion-auth for the login systems and authentications, please I want to use another 3rd party acl systems like flexiauth, oauth, Aauth, etc but I don't have enough knowledge to know what files I will be replacing and which controller (s) I will need to made modification in.....I am totally stuck....please help me
What I need is simple enough:
I want to have multiple groups and users with access to different resources in the web app e.g a cashier (should have access to pos, customer, report daily_sales, close register, print invoice) AND (an account should have access to dashboard, reports, order etc), manager should be able to create new user, view sales, void sales etc, AND admin should of course have overall access.
What I have now is admin(full access to all the resources) other logged_in users: restricted in some areas.
Groups I have is 2:
Admin
Staff.
I don't know how to continue.
i think i find the custom library used to define the access
Please check the follow code and advice on where i can start:
class MY_Controller extends CI_Controller {
function __construct() {
parent::__construct();
define("DEMO", 0);
$this->Settings = $this->site->getSettings();
$this->lang->load('app', $this->Settings->language);
$this->Settings->pin_code = $this->Settings->pin_code ? md5($this->Settings->pin_code) : NULL;
$this->theme = $this->Settings->theme.'/views/';
$this->data['assets'] = base_url() . 'themes/default/assets/';
$this->data['Settings'] = $this->Settings;
$this->loggedIn = $this->tec->logged_in();
$this->data['loggedIn'] = $this->loggedIn;
$this->data['categories'] = $this->site->getAllCategories();
$this->Admin = $this->tec->in_group('admin') ? TRUE : NULL;
$this->data['Admin'] = $this->Admin;
$this->m = strtolower($this->router->fetch_class());
$this->v = strtolower($this->router->fetch_method());
$this->data['m']= $this->m;
$this->data['v'] = $this->v;
}
function page_construct($page, $data = array(), $meta = array()) {
if(empty($meta)) { $meta['page_title'] = $data['page_title']; }
$meta['message'] = isset($data['message']) ? $data['message'] : $this->session->flashdata('message');
$meta['error'] = isset($data['error']) ? $data['error'] : $this->session->flashdata('error');
$meta['warning'] = isset($data['warning']) ? $data['warning'] : $this->session->flashdata('warning');
$meta['ip_address'] = $this->input->ip_address();
$meta['Admin'] = $data['Admin'];
$meta['loggedIn'] = $data['loggedIn'];
$meta['Settings'] = $data['Settings'];
$meta['assets'] = $data['assets'];
$meta['suspended_sales'] = $this->site->getUserSuspenedSales();
$meta['qty_alert_num'] = $this->site->getQtyAlerts();
$this->load->view($this->theme . 'header', $meta);
$this->load->view($this->theme . $page, $data);
$this->load->view($this->theme . 'footer');
}
}
Codeigniter doesn't come with native login system, so the script you purchased is already using a third party package/plugin.
Look for login script code in the following locations : Models, Libraries.
The controller is where you control everything, so you can have a look at that later, first you need to determine which files are being used as the core of login functionalities. Once you have determined, you can look at the code and understand how they are handling user groups/ previlages etc.
About the groups and previlages, either they have their on table in database where the values are stored for admin, public etc or the values are stored in a config file, you can find all the config files in the application\config directory. Use PHPMYAdmin to check database and check non codeigniter config files too.
Check the Auth in every controller. Remove them and put your exiting auth system.
I am building a paid subscription site using Drupal. After searching through the Drupal modules I have not been able to find anything that will allow me to create a new Drupal account once the user has visited my landing page, decided they want to subscribe, and provided their valid credit card information. I would like to redirect them to the subscription site with a newly created account once their credit card info has been validated.
Is anyone familiar with a module or a methodology for remotely creating a user account with Drupal? OpenID is a possibility but I would like to give the user a little more freedom in selecting their username.
Why not extend Drupal's registration form with some extra fields and validation functions?
You could have a hook, function, or build an xml-rpc interface to a function that created a new user account after the user has entered their details.
For example, on the form that they fill out, you could have in the _submit of the form:
formname_sumbit($form, &$form_state) {
// Do form stuff here
// Now do user_save stuff
$password = user_password();
$mail = $form_state['values']['email_address'];
// Use blank account object as we are creating a new account
$account = array();
$properties = array('name' => 'someusername', 'pass' => $password, 'mail' => $mail, $roles => array('authenticated user', 'some other role'));
$this_user = user_save($account, $properties);
}
That should take care of creating the user. I'm not sure about how to login them automatically, but a global $user; $user = $this_user; might work. The user should be notified of their new account via email by the user_save function, but you might want to let them know with a drupal_set_message as well.
http://api.drupal.org/api/function/user_save/6