Share My Creation [Project Template] User Login Server

Version: 3.00
Based on (Project Template) Web API Server v3.30

Click to zoom


Description:
This is a fully functional user registration and login system with user login management.
It is a remake of MySQL API Server (Key + Token) and [B4X] User Login Apps.
The access token will expired in 10 minutes (you can set it like 30 minutes or longer).
It can be renewed using API key.
It is similar to JSON Web Token.
Testing can be done locally without setting up email.

Database:
SQLite or MySQL

Client app:
[B4X] User Login Client

Depends on:
Update user-login-client for v2.00
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

  • User Login Server (1.01).b4xtemplate
    426.3 KB · Views: 233
  • User Login Server (2.00).b4xtemplate
    449.4 KB · Views: 37
  • User Login Server (3.00).b4xtemplate
    433.4 KB · Views: 27
Last edited:

aeric

Expert
Licensed User
Longtime User
Some testing and fixes to support MySQL database. Template updated in post #1.
 

aeric

Expert
Licensed User
Longtime User
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

  • User Login Server (2.00beta1).b4xtemplate
    445.4 KB · Views: 60
Last edited:

aeric

Expert
Licensed User
Longtime User
Two bugs found and will be fixed in next version.

In User Login Server,
UsersApiHandler
Update to the following code:
B4X:
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

In User Login Client app,
B4XPageUserProfile
Update to the following code:
B4X:
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)
 
Top