Add one more column on jos_user table in Joomla 3.7 - joomla

I am developing custom authentication plugin for login in joomla from third party API.
When we login on any Joomla instance with user/password then the user/pass is passed to API get the correct response (like login_id, username, employee_ident, email, common name.) Then Joomla create the user on Joomla and save the response like (username,fullname ,email) on Joomla database. Now ccms auth plugin is working fine.
My requirement is to save one more column on jos_users while user authentication plugin from API. For this I have created the one column employee_ident in jos_user table but am not able to save employee_ident in joomla db on jos_user table.
Here is my code:
$result = $client->call($method, $params);
[0] => Array
(
[login_id] => Frasier.9878
[email_address] => frabc#gmail.com
[position_code_type_ident] => 157
[employee_ident] => 166651
[position_code_department_abbr_name] => executive_management
[position_code_title] => Chief Financial Officer
[hire_date] => 2003-01-20
[common_name] => Frasier Crane
)
if($result)
{
$email_address = isset($result[0][email_address]) ? $result[0][email_address] : $credentials['username']."#test.com";
$response->email = $email_address;
$response->fullname =$result[0][common_name];
$response->employee_ident =$result[0][employee_ident];
$response->username =$credentials['username'];
$response->status = JAuthentication::STATUS_SUCCESS;
$response->error_message = '';
}

You should create a Profile Plugin for this. By default Joomla! has a #__user_profiles table that can hold additional user information.
See this page from JDocs for more information: https://docs.joomla.org/Creating_a_profile_plugin/en
Another example is the core profile plugin:
https://github.com/joomla/joomla-cms/blob/staging/plugins/user/profile/profile.php

Related

laravel: redirect to same controller with query parameters when cookie exists

First, here's a little background on what I'm trying to accomplish:
I'm building a SaaS app, and on the marketing site, the user can select a plan which will direct them to the registration page. I'm using a very similar flow to Mailchimp.
Once they register, they have to verify their email. Once they verify their email, they "complete" their account with information like address, city, etc.
Then, they're taken to the paywall.
My problem
I need a way of remembering which plan they wanted from the marketing site when they land on the paywall. To do this I was going to set a cookie.
If a cookie exists of a certain value, I want to redirect to that same route, but add a query parameter such as ?plan=free
Here is my controller function tied to the route route('paywall')
/**
* Returns all the data needed for the paywall
*/
public function paywall() {
if ($plan_intent = Cookie::get('plan-intent')) {
return redirect()->route('paywall', ['plan' => $plan_intent]);
}
$account = auth()->user()->accounts->first();
$billingAccount = $account->billingAccount;
$contactDetails = $account->contactDetails();
return view('account.paywall', [
'plans' => Plan::all(),
'intent' => $account->createSetupIntent(),
'currentPlan' => $account->plan,
'contactDetails' => $contactDetails,
'billingAccount' => $billingAccount,
'states' => State::all()
]);
}
The code above is causing a redirection loop: (site name) redirected you too many times.
How can I conditionally add query parameters to the same route and redirect to the same route?
I had to do a check to see if the param was there. That's why the redirect loop was happening:
if ($plan_intent = Cookie::get('plan-intent') && !request()->input('plan')) {
return redirect()->route('paywall', ['plan' => $plan_intent]);
}

Laravel socialite

I have used laravel auth and socialite package in my web app. I have followed https://www.youtube.com/watch?v=uavoKwhGBKI&t=932s link and it working fine.To be brief, If I register using socialite it fetches the name of the user and email but needs to be filled other details as DOB and password but if I submit without filling that it shows 500 error while if I register without socialite then my validation works fine.The registration page is same.
Socialite only gives you access to a select set of data returned from a successful connection.
# Retrieving User Details
https://laravel.com/docs/6.x/socialite#retrieving-user-details
$user = Socialite::driver('github')->user();
// OAuth Two Providers
$token = $user->token;
$refreshToken = $user->refreshToken; // not always provided
$expiresIn = $user->expiresIn;
// OAuth One Providers
$token = $user->token;
$tokenSecret = $user->tokenSecret;
// All Providers
$user->getId();
$user->getNickname();
$user->getName();
$user->getEmail();
$user->getAvatar();
# Modifying LoginController
https://scqq.blogspot.com/2017/11/laravel-55-socialite-login-with-twitter.html
This guide you followed does not actually register a user by social platform. It only pre-populates the default Laravel registration form with the fields name and email as shown below. This is where you can add another property from above, such as the user's avatar, if desired. You would also need to add the corresponding field to the registration form.
return view('auth.register', [
'name' => $userSocial->getName(),
'email' => $userSocial->getEmail(),
// ... 'avatar' => $userSocial->getAvatar(),
]);
Google is NEVER going to give you someone's password!
The whole point of Socialite is to allow Google (or the selected provider) to authenticate the user — not your application.
If you wish to actually register a user with Socialite (without any additional forms or setting a password), you will need to modify or extend RegisterController.php to be able to support this.

list blogs list of blogger in Google PHP SDK

I am using Google API SDK in CakePHP application.
I have to list the blogs owned by the user after authenticating the application.
The user will select from the list of blogs and I will record the blog ID to make further requests.
According to the documentation, we need to make GET request to
GET https://www.googleapis.com/blogger/v3/users/self/blogs?key=YOUR-API-KEY
But I have my API Key and user's access token.
How can I list the blogs using the access token?
I tried using the SDK Services
$client = new \Google_Client();
$client->setApplicationName(GOOGLE_APP_NAME);
$client->setClientId(GOOGLE_CLIENT_ID);
$client->setClientSecret(GOOGLE_CLIENT_SECRET);
$client->setAccessToken($access_token);
$client->setAccessType("offline"); // offline access
$client->setIncludeGrantedScopes(true); // incremental auth
$client->addScope('https://www.googleapis.com/auth/userinfo.email');
$client->addScope('https://www.googleapis.com/auth/blogger');
$callback_url = Router::url(['prefix' => 'dashboard', 'controller' => 'SharingLogin', 'action' => 'bloggerCallback'], true);
$client->setRedirectUri($callback_url);
$service = new \Google_Service_Blogger($client);
$listblog = $service->blogs;
debug($listblog);
But this lists nothing and empty array object.

Customize the current magento onestep checkout page

Need help in customizing the existing onestep checkout page so that billing/customer info form will be included within the payment select section.
For Example,
If Customer has chosen Card as payment option then along with Card Details form fields it should also display billing information fields(First name, last name, email, country, zip, password, confirm password.) as well.
If customer has selected paypal as payment option then fields(Email, Password, Confirm password).
Basically, we are trying to reduce the number of steps and speed up the checkout.
Use the following
public function index( $category_id = null )
{
if (!$this->KnowledgeSolution->KnowledgeCategory->exists( $category_id ))
{
throw new NotFoundException(__('Invalid Knowledge Category'));
}
$KnowledgeCategory = $this->KnowledgeSolution->KnowledgeCategory->read(null,$category_id);
$this->set('KnowledgeCategory',$KnowledgeCategory);
$this->Paginator->settings['contain'] = array('Users','KnowledgeReply'=>array('Users') );
$this->set('KnowledgeSolutions', $this->Paginator->paginate());
$this->Paginator->settings = array('conditions' => array('Product .title LIKE' => 'a%'),'limit' => 10 );
$this->set(compact('data'));
}

Magento - Customer Not Logged in After Redirect From External Page

I'm having a lot of trouble getting a customer to stay logged in after I have created a new account. I'm creating them an account and adding products to a cart from an external site, and then sending them to Magento store. What I want to have happen is:
A customer goes to a signup page and enters relevant information.
They go to a new page where they can choose to add free samples to their cart.
After picking samples. their account is created and they are redirected to the Magento store with the samples in their cart.
The problem I'm having is between steps 2 and 3. I create an account using the Magento's SOAP API with the following:
$customerInfo = array('firstname' => $custFirstname, 'lastname' => $custLastname, 'email' => $email, 'password_hash' => md5( $new_password ), 'store_id' => 34, 'website_id' => 25,'group_id' => 9);
// Call API method customer.create
$newCustomerId = $client->call( $session, 'customer.create', array( $customerInfo ) );
I then return their customer ID, which I pass to another function which actually logs them in and adds products to their cart:
public static function _addSamplesToCart($customer_id, $sample_one, $sample_two, $sample_three){
Mage::getSingleton("core/session", array("name" => "frontend"));
$customerSession = Mage::getSingleton('customer/session', array("name" => "frontend"));
$customerSession->init("customer_bn_us");
$customerSession->loginById($customer_id);
$cart = Mage::getSingleton('checkout/cart');
$cart->addProductsByIds($idArray);
$cart->save();
$cart->getCheckoutSession()->setCartWasUpdated(true);
}
These functions are actually called from AJAX post requests, so when I get a successful return value from _addSamplesToCart, I do a simple javascript redirect (window.location ="http://www.myhostname.net/welcome") and it correctly takes me there, but I'm not logged in.
I've been looking around all afternoon and trying a few different things and nothing has worked. I've also tried doing a hidden form submit to /customer/account/loginPost and it still doesn't work. I have verified that it's correctly creating an account in Magento. My only hunch is that I'm doing this with a mix of AJAX and PHP so somehow the cookies or sessions are getting mixed up?
If you are trying to login from an hostname different from the one used by the Magento store, it cannot work. You can verify this by checking if a frontend cookie is created after the AJAX call.
I suggest you to create a new controller in Magento that receives the id of the customer just created and executes the code you wrote in your function:
www.myhostname.net/autologin/myaction/13 (where 13 is the id of the customer just created).
Obviously you should add something else to avoid security issues.

Resources