Share My Creation [Project Template] User Login Server

Version: 3.11

User Login Server


GitHub: https://github.com/pyhoon/user-login-server-b4j

Clients: [Project Template] [B4X] User Login Client

Description:
  1. This is a user registration and login server.
  2. Includes API for change and reset user password.
  3. Based on Web API Server v3.50 project template.
  4. It is a remake of MySQL API Server (Key + Token) and [B4X] User Login Apps.
  5. By default the access token will expired in 10 minutes. It is renewed using API key. It is similar to JSON Web Token.
  6. Testing can be done locally without setting up email.
Database:
  • SQLite
  • MySQL
Depends on:
You can use LibDownloader to download the correct version of additional libraries.
 

Attachments

Last edited:
Some testing and fixes to support MySQL database. Template updated in post #1.
 
Version: 2.00beta1

Based on Web API Server v3.10
Depends on MiniORMUtils v1.14 and WebApiUtils v3.02

Update user-login-client
B4X:
'Public strURL As String = "http://192.168.50.42:17178/web/api/v1/"
Public strURL As String = "http://192.168.50.42:8080/api/v1/"
 

Attachments

Last edited:
Two bugs found and will be fixed in next version.

In User Login Server,
UsersApiHandler
Update to the following code:
[CODE lang="b4x" highlight="3"]Private Sub ValidateToken (Token As UserData) As Boolean
Try
If Token = Null Or Token.IsInitialized = False Then
HRM.ResponseCode = 401
HRM.ResponseError = "Undefine User Token"
ReturnApiResponse
Return False
End If[/CODE]

In User Login Client app,
B4XPageUserProfile
Update to the following code:
[CODE lang="b4x" highlight="12"]Sub UpdateProfile
Try
Log("[B4XPageUserProfile] UpdateProfile")
Dim data As Map
data.Initialize
data.Put("key", Main.User.ApiKey)
data.Put("token", Main.User.Token)
data.Put("user_name", txtUserName.Text.Trim)
data.Put("user_location", txtUserLocation.Text.Trim)
Dim job As HttpJob
job.Initialize("", Me)
job.PutString(Main.strURL & "users/update-profile", data.As(JSON).ToString)
job.GetRequest.SetHeader("Authorization", "Bearer " & Main.User.Token)
Wait For (job) JobDone(job As HttpJob)[/CODE]
 
Version: 3.10beta1

Changes:
  • Based on Web API Server template v3.50
  • Depends on MiniORMUtils v2.63
  • User Login Client v2.00beta1
 
Version: 3.11

Changes:
  • Fix bug in help.js for reading token
  • Added Macro to create project template (from source)
 
Back
Top