I am developing a mobile application using Ionic Framework for my E-commerce website developed using Woocommerce.
I need to use a single database for the users, so that the registered users can access their profiles and non-registered users can register to the website / app simultaneously with the same credentials.
I found this awesome plugin which claims to provide with REST User data to help login/register but I am unable to use this as I am already using Reactor Core and WP-API to access my products data and WordPress wouldn't allow me to use all these plugins simultaneously.
Well WordPress it self has a communication protocol which is XML-RPC you can read more on it here, However it does not have authentication method builtin.
But you can try it some thing like this:
function mynamespace_getUserID( $args ) {
global $wp_xmlrpc_server;
$wp_xmlrpc_server->escape( $args );
$blog_id = $args[0];
$username = $args[1];
$password = $args[2];
if ( ! $user = $wp_xmlrpc_server->login( $username, $password ) )
return $wp_xmlrpc_server->error;
return $user->ID;
}
function mynamespace_new_xmlrpc_methods( $methods ) {
$methods['mynamespace.getUserID'] = 'mynamespace_getUserID';
return $methods;
}
add_filter( 'xmlrpc_methods', 'mynamespace_new_xmlrpc_methods');
You can read more on Extending XML-RPC here. If you are using client side language for authentication, then you can check WordPress XmlRpc Javascript Api
Related
I'm new to using Svelte and would like to create a ordering website using Svelte. I know that I will need a database to keep track of the order, customer name, price etc. I have used MySQL before but I haven't learned how to connect a database to a website.
Is there a specific database that you can use if you are using Svelte?
Or is there a way to connect MySQL to Svelte?
I have searched about this on Youtube and Google but I'm not sure if it's different if you are using Svelte so I wanted to make sure.
Note: I have not started this project yet so I do not have any code to show I just want to know how you can connect a database if you're using Svelte.
Svelte is a front end javascript framework that run on the browser.
Traditionally, in order to use databases like mysql from a front end project such as svelte, (that contains only html,css and js), you would have to do it with a separate backend project. You can then communicate the svelte app and the backend project with the help of REST api. The same applies to other other front end libraries/frameworks like react, angular vue etc.
There are still so many ways to achieve the result. Since you are focusing on Svelte here are few things options
1 Sapper
Sapper is an application framework powered by svelte. You can also write backend code using express or polka so that you can connect to database of your choice (mysql / mongodb)
2 User Server less database
If you want you app simple and just focus on svelte app, you can use cloud based databases such as firebase. Svelte can directly talk to them via their javascript SDK.
3 monolithic architecture
To connect with mysql in the backend, you would need to use one serverside application programming language such as nodejs (express) php or python or whatever you are familiar with. Then use can embed svelte app or use api to pass data to the svelte app.
I can make an example with mongodb
You have to install the library
npm install mongodb
or add in package.json
Then you have to make a connection file that you have to call everytime you need to use the db
const mongo = require("mongodb");
let client = null;
let db = null;
export async function init() {
if(!client) {
client = await mongo.MongoClient.connect("mongodb://localhost");
db = client.db("name-of-your-db");
}
return { client, db }
}
for a complete example with insert you can see this video
https://www.youtube.com/watch?v=Mey2KZDog_A
You can use pouchdb, which gives you direct access to the indexedDB in the browser. No backend needed for this.
The client-pouchdb can then be replicated/synced with a remote couchdb. This can all be done inside you svelte-app from the client-side.
It is pretty easy to setup.
var db = new PouchDB('dbname');
db.put({
_id: 'dave#gmail.com',
name: 'David',
age: 69
});
db.changes().on('change', function() {
console.log('Ch-Ch-Changes');
});
db.replicate.to('http://example.com/mydb');
more on pouchdb.com
Also the client can save the data offline first and later connect to a remote database.
As i get question mostly about connection to backend, not a database. It is pity, but svelte app template has no way to connect backend "in box".
What about me, i'm using express middleware in front of rollup server. In this case you able to proxy some requests to backend server. Check code below
const proxy = require('express-http-proxy');
const app = require('express')();
app.use('/data/', proxy(
'http://backend/data',
{
proxyReqPathResolver: req => {
return '/data'+ req.url;
}
}
)
);
app.use('/', proxy('http://127.0.0.1:5000'));
app.listen(5001);
This script opend 5001 port where you have /data/ url proxied to backend server. And 5000 port still available from rollup server. So at http://localhost:5001/ you have svelte intance, connected to backend vi /data/ url, here you can send requests for fetching some data from database.
Am new to feathersjs am try to do local auth in feathers while creating the service under users.class.js file where there. i don't know what to implement there so kindly guide me with this
const { Service } = require('feathers-mongoose');
exports.Users = class Users extends Service {
create(Users, email, username, password, role ) {
Users.created_at = new Date();
return super.create(Users, email, username, password, role );
}
update(id, Users, users) {
Users.updated_at = new Date();
return super.update(id, Users, users);
}
};
I’d look at the docs to learn more about services.
In Feathers, when you generate a service through the CLI, it creates three files.
service-name.class.js/.ts contains your service definition. Feathers operates everything in a CRUD fashion. So, you’ll see all the CRUD methods here. You can either define the service yourself, or use CLI to define it for you using an adaptor like Mongoose or Sequelize.
service-name.hooks.js/.ts contains all the hooks associated with this service. Feathers likes to keep your logic simple and clean, opting to do things like validation through reusable hooks instead of modifying the service logic directly. You said you wanted to add authentication to your service. This is where you would do it. In the before:[] hook section, add the authenticate(“jet”) hook your the methods you want to require authentication for.
service-name.service.js/.ts just handles service registration with the framework. Starting out, I wouldn’t mess around with this file much. It just performs some setup so the framework knows your service exists and attaches it to a specific route like /users.
Hope this helps.
I am creating a BlackBerry app that provides the functionalities of an already existing web application but making it suitable for mobile phone users. I am creating the mobile app using PhoneGap and leveraging BlackBerry WebWorks SDK. I need to send data to and receive data (submit forms, update profiles) from the mobile app to the server where the web application runs from. I also want users of the app to chat with other users of the mobile app through the BlackBerry Internet Service (BIS). I want the mobile app to be able to query the database already created for the existing web application so existing users who have downloaded the app can view their details on their BlackBerry device instead of their computers. Can someone please recommend a solution?
With phonegap you can send XMLHttpRequests via AJAX. You can do this in pure JavaScript or even easier with jQuery.
You'll need to do the database work with a server-side language, like php.
here's a simple example, assuming you have included jQuery in your Phonegap app.
window.onload = function (){
document.addEventListener("deviceready", deviceReady, false);
}
function deviceReady{
var userName = 'Hans';
var userShoeSize = 'Medium';
$.post("http://example.com/responseHandler.php", {
userName: userName, userShoeSize:userShoeSize},
function(data) {
alert(data.greeting+data.shoeSize);
}, "json");
}
and on the server in responseHandler.php:
<?php
header("Access-Control-Allow-Origin: *");
$response = array();
$response['greeting'] = 'Hi, '.$_POST['userName'];
$response['shoeSize'] = 'Your shoes are size '.$_POST['userShoeSize'];
echo json_encode($response);
?>
By echoing out a JSON encoded string on the server, javascript can easily parse the response. You don't have to use JSON, you can work with anything echoed out on the server.
Just remember to whitelist your page and allow querystrings from other origins on your server.
I want to connect Magento Database with my other website for login purposes. So that users do not need to register again.
For other websites I don't have Magento layer. Just raw PHP mysql websites.
I'm wondering what would be best way create a central database and how can I retrieve user information(username and password only.) from Magento Database.
I am thinking to execute raw php mysql queries but for that I need to open ports on my servers to connect to other servers because all websites are on different servers.
What would be the best approach.
In order to achieve SSO (Single sign on) the best thing to do would be to migrate all your users to Magento.
The Magento files should be accessible on the external website too (either if they are on the same server or via a mount.) You can then use something like the code below:
<?php
require_once '/path/to/magento/root/app/Mage.php';
umask(0);
Mage::app();
$session = Mage::getSingleton('customer/session');
// Login
try {
$session->login($email, $password);
$session->setCustomerAsLoggedIn($session->getCustomer());
//Load the customer modules
$customer = Mage::getModel('customer/customer')->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
//Get customer attribbutes
$customer->loadByEmail($email);
} catch (Exception $e) {
Mage::log($e->getMessage());
}
Where $email and $password would contain the values that are sent from a form
I've a MySql database hosted in my web site, with a table named UsrLic
Where any one wants to buy my software must register and enter his/her Generated Machine Key (+ username, email ...etc).
So my question is:
I want to automate this process from my software, how this Process will be?
Should I connect and update my database directly from my software ( and this means I must save all my database connection parameters in it * my database username , password , server * and then use ADO or MyDac to connect to this database ? and if yes how secure is this process ?
or any other suggestions .
I recommend creating an API on your web site in PHP and calling the API from Delphi.
That way, the database is only available to your web server and not to the client application, ever. In fact, you should run your database on localhost or with a private IP so that only machines on the same physical network can reach it.
I have implemented this and am implementing it again as we speak.
PHP
Create a new file named register_config.php. In this file, setup your MySQL connection information.
Create a file named register.php. In this file, put your registration functions. From this file, include 'register_config.php'. You will pass parameters to the functions you create here, and they will do the reading and writing to your database.
Create a file named register_api.php. From this file, include 'register.php'. Here, you will process POST or GET variables that are sent from your client application, call functions in register.php, and return results back to the client, all via HTTP.
You will have to research connecting to and querying a MySQL database. The W3Schools tutorials will have you doing this very quickly.
For example:
Your Delphi program calls https://mysite/register_api.php with Post() and sends the following values:
name=Marcus
email=marcus#gmail.com
Here's how the beginning of register_api.php might look:
// Our actual database and registration functions are in this library
include 'register.php';
// These are the name value pairs sent via POST from the client
$name = $_POST['name'];
$email = $_POST['email'];
// Sanitize and validate the input here...
// Register them in the DB by calling my function in register.php
if registerBuyer($name, $email) {
// Let them know we succeeded
echo "OK";
} else {
// Let them know we failed
echo "ERROR";
}
Delphi
Use Indy's TIdHTTP component and its Post() or Get() method to post data to register_api.php on the website.
You will get the response back in text from your API.
Keep it simple.
Security
All validation should be done on the server (API). The server must be the gatekeeper.
Sanitize all input to the API from the user (the client) before you call any functions, especially queries.
If you are using shared web hosting, make sure that register.php and register_config.php are not world readable.
If you are passing sensitive information, and it sounds like you are, you should call the registration API function from Delphi over HTTPS. HTTPS provides end to end protection so that nobody can sniff the data being sent off the wire.
Simply hookup a TIdSSLIOHandlerSocketOpenSSL component to your TIdHTTP component, and you're good to go, minus any certificate verification.
Use the SSL component's OnVerifyPeer event to write your own certificate verification method. This is important. If you don't verify the server side certificate, other sites can impersonate you with DNS poisoning and collect the data from your users instead of you. Though this is important, don't let this hold you up since it requires a bit more understanding. Add this in a future version.
Why don't you use e.g. share*it? They also handle the buying process (i don't see how you would do this for yourself..) and let you create a reg key through a delphi app.