One really common pattern found in mobile applications is a dual email + Facebook log in system. Facebook is a very popular sign in method, but noteverybodyhas an account and not everybody wants to use their Facebook account to sign in to new services. This makes giving the option to users to use either email or their Facebook account to sign up very attractive.
There seems to be very little (that I could find at least) information out there on how to set up a log in / authentication system in Sencha Touch. So I’m writing a series of blog posts that will cover how to set up a log in system from scratch with the option to sign up with either email or a Facebook account. The application will have a PHP & MySQL backend and will also use PhoneGap Build.
Topics covered over the coming weeks will include:
- Setting up the database and API (this post)
- Creating the application and screens
- Email sign up system
- Authentication and generating sessions for users
- Auto login / remember me for return visits
- Integrating a Facebook signup system
In this first part, I will walk you through setting up your database and setting up some PHP files on your server that are ready to receive calls from your application.
Setting up the database
We’re going to have to create a MySQL database first of course so go ahead and do that, calling it whatever you wish. Once you’ve created the database, add the following table to it:
CREATE TABLE `users` (`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,`fbid` VARCHAR(255),`email` VARCHAR(100) NOT NULL,`password` VARCHAR(255) NOT NULL,`session` VARCHAR(255),PRIMARY KEY (`id`));
This will allow us to store the details the users uses to sign up, as well as any other details we would like to track. You could go ahead and add some other fields like ‘first_name’, ‘phone’ and so on if you wish. If you’re building out a real application, you’re likely going to require other tables as well, but this is all we need to actually get the log in system working.
Setting up the API
Throughout the log in and sign up processes, our application will be making calls to an API hosted on the Internet. This API will be created with PHP files which will interact with our database, and then return data in a JSON format to our application.
Although we are not implementing it just yet, our application will make calls to our server using an Ajax proxy. The problem with this is that we can run into some Cross Origin Resource Sharing errors which might look something like the following:
XMLHttpRequest cannot load [URL]. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost’ is therefore not allowed access.
XMLHttpRequest cannot load [URL]. Origin [URL] is not allowed by Access-Control-Allow-Origin.
Request header field Content-Type is not allowed by Access-Control-Allow-Headers
Essentially, we’re running into security problems because we’re making requests to a domain different to the one the application is hosted on. I wrote a blog posts on this recently so if you’d like more information you cancheck it out here.
What we want to do now though is make sure we don’t run into any of these errors by making sure we set our headers (and everything else) correctly from the beginning. Now I need you to create a file called ‘users.php’ and add the following code to it:
<?php $link = mysql_connect("localhost", "db_user", "your_password");mysql_select_db("your_db", $link);$action = $_GET["action"];$result = "{'success':false}";header('Access-Control-Allow-Origin: *');header('Access-Control-Allow-Methods: GET, POST, OPTIONS');header('Access-Control-Allow-Headers: Content-Type,x-prototype-version,x-requested-with');echo($result);?>
What we are doing here is first connecting to the database – you will have to replace these details with your own. Next we are grabbing the ‘action’ which will be passed into the API through the URL. For example: http://www.example.com/api/users.php?action=something. Eventually we will cycle through this ‘action’ variable to perform the appropriate action. When we want to log a user in we could make an Ajax request to ‘users.php?action=login’ or if we wanted to log a user out ‘users.php?action=logout’ and so on.
Before outputting the result, we are also setting our headers here. These headers are necessary to overwrite the default Cross Origin Resource Sharing options and to prevent the errors above. If you read the CORS article I linked above you will notice that you can also set these headers at the server level instead of directly in your PHP files.
At the end of this file we are outputting ‘$result’. If you were to visit this page in your browser you would simply see ‘{‘success’:false}’. This is a JSON formatted string that is telling us that whatever operation was just performed on the server was not successful. In later parts of this tutorial series we will of course be outputting different data through this JSON string that will indicate whether a user successfully logged in, what their session key is and so on. This same format can be used to send in large, complex data including any and all details we had stored about a user in the database.
This concludes the first part of this tutorial series. At this point we have our database set up and our API ready to be added to and interacted with. Stay tuned for the following posts in this series; I’ll update with a link to Part 2 here when it is ready! Feel free to sign up to the fortnightly newsletter in the bar on the right for updates on any new blog posts.

MySQL sesuai untuk pemula untuk mempelajari kemahiran pangkalan data. 1. Pasang alat pelayan dan klien MySQL. 2. Memahami pertanyaan SQL asas, seperti SELECT. 3. Operasi data induk: Buat jadual, masukkan, kemas kini, dan padam data. 4. Belajar Kemahiran Lanjutan: Fungsi Subquery dan Window. 5. Debugging dan Pengoptimuman: Semak sintaks, gunakan indeks, elakkan pilih*, dan gunakan had.

MySQL dengan cekap menguruskan data berstruktur melalui struktur jadual dan pertanyaan SQL, dan melaksanakan hubungan antara meja melalui kunci asing. 1. Tentukan format data dan taip apabila membuat jadual. 2. Gunakan kunci asing untuk mewujudkan hubungan antara jadual. 3. Meningkatkan prestasi melalui pengindeksan dan pengoptimuman pertanyaan. 4. Secara kerap sandaran dan memantau pangkalan data untuk memastikan pengoptimuman keselamatan data dan prestasi.

MySQL adalah sistem pengurusan pangkalan data sumber terbuka yang digunakan secara meluas dalam pembangunan web. Ciri -ciri utamanya termasuk: 1. Menyokong pelbagai enjin penyimpanan, seperti InnoDB dan Myisam, sesuai untuk senario yang berbeza; 2. Menyediakan fungsi replikasi master-hamba untuk memudahkan pengimbangan beban dan sandaran data; 3. Meningkatkan kecekapan pertanyaan melalui pengoptimuman pertanyaan dan penggunaan indeks.

SQL digunakan untuk berinteraksi dengan pangkalan data MySQL untuk merealisasikan penambahan data, penghapusan, pengubahsuaian, pemeriksaan dan reka bentuk pangkalan data. 1) SQL Melaksanakan operasi data melalui Pilih, Masukkan, Kemas kini, Padam Penyataan; 2) Gunakan pernyataan membuat, mengubah, drop untuk reka bentuk dan pengurusan pangkalan data; 3) Pertanyaan kompleks dan analisis data dilaksanakan melalui SQL untuk meningkatkan kecekapan membuat keputusan perniagaan.

Operasi asas MySQL termasuk membuat pangkalan data, jadual, dan menggunakan SQL untuk melakukan operasi CRUD pada data. 1. Buat pangkalan data: createdatabasemy_first_db; 2. Buat Jadual: CreateTableBooks (Idintauto_IncrementPrimaryKey, Titlevarchar (100) NotNull, Authorvarchar (100) NotNull, Published_yearint); 3. Masukkan Data: InsertIntoBooks (Tajuk, Pengarang, Published_year) VA

Peranan utama MySQL dalam aplikasi web adalah untuk menyimpan dan mengurus data. 1.MYSQL dengan cekap memproses maklumat pengguna, katalog produk, rekod urus niaga dan data lain. 2. Melalui pertanyaan SQL, pemaju boleh mengekstrak maklumat dari pangkalan data untuk menghasilkan kandungan dinamik. 3.MYSQL berfungsi berdasarkan model klien-pelayan untuk memastikan kelajuan pertanyaan yang boleh diterima.

Langkah -langkah untuk membina pangkalan data MySQL termasuk: 1. Buat pangkalan data dan jadual, 2. Masukkan data, dan 3. Pertama, gunakan pernyataan CreatedataBase dan createtable untuk membuat pangkalan data dan jadual, kemudian gunakan pernyataan InsertInto untuk memasukkan data, dan akhirnya gunakan pernyataan PILIH untuk menanyakan data.

MySQL sesuai untuk pemula kerana mudah digunakan dan berkuasa. 1.MYSQL adalah pangkalan data relasi, dan menggunakan SQL untuk operasi CRUD. 2. Ia mudah dipasang dan memerlukan kata laluan pengguna root untuk dikonfigurasi. 3. Gunakan Masukkan, Kemas kini, Padam, dan Pilih untuk Melaksanakan Operasi Data. 4. Orderby, di mana dan menyertai boleh digunakan untuk pertanyaan yang kompleks. 5. Debugging memerlukan memeriksa sintaks dan gunakan Jelaskan untuk menganalisis pertanyaan. 6. Cadangan pengoptimuman termasuk menggunakan indeks, memilih jenis data yang betul dan tabiat pengaturcaraan yang baik.


Alat AI Hot

Undresser.AI Undress
Apl berkuasa AI untuk mencipta foto bogel yang realistik

AI Clothes Remover
Alat AI dalam talian untuk mengeluarkan pakaian daripada foto.

Undress AI Tool
Gambar buka pakaian secara percuma

Clothoff.io
Penyingkiran pakaian AI

AI Hentai Generator
Menjana ai hentai secara percuma.

Artikel Panas

Alat panas

SecLists
SecLists ialah rakan penguji keselamatan muktamad. Ia ialah koleksi pelbagai jenis senarai yang kerap digunakan semasa penilaian keselamatan, semuanya di satu tempat. SecLists membantu menjadikan ujian keselamatan lebih cekap dan produktif dengan menyediakan semua senarai yang mungkin diperlukan oleh penguji keselamatan dengan mudah. Jenis senarai termasuk nama pengguna, kata laluan, URL, muatan kabur, corak data sensitif, cangkerang web dan banyak lagi. Penguji hanya boleh menarik repositori ini ke mesin ujian baharu dan dia akan mempunyai akses kepada setiap jenis senarai yang dia perlukan.

SublimeText3 versi Cina
Versi Cina, sangat mudah digunakan

Hantar Studio 13.0.1
Persekitaran pembangunan bersepadu PHP yang berkuasa

Muat turun versi mac editor Atom
Editor sumber terbuka yang paling popular

MinGW - GNU Minimalis untuk Windows
Projek ini dalam proses untuk dipindahkan ke osdn.net/projects/mingw, anda boleh terus mengikuti kami di sana. MinGW: Port Windows asli bagi GNU Compiler Collection (GCC), perpustakaan import yang boleh diedarkan secara bebas dan fail pengepala untuk membina aplikasi Windows asli termasuk sambungan kepada masa jalan MSVC untuk menyokong fungsi C99. Semua perisian MinGW boleh dijalankan pada platform Windows 64-bit.