Login
curl --request POST \
--url https://api.example.com/auth/login.php \
--header 'Accept: <accept>' \
--header 'Content-Type: <content-type>' \
--data '
{
"email": "<string>",
"password": "<string>"
}
'import requests
url = "https://api.example.com/auth/login.php"
payload = {
"email": "<string>",
"password": "<string>"
}
headers = {
"Content-Type": "<content-type>",
"Accept": "<accept>"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': '<content-type>', Accept: '<accept>'},
body: JSON.stringify({email: '<string>', password: '<string>'})
};
fetch('https://api.example.com/auth/login.php', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/auth/login.php",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'email' => '<string>',
'password' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Accept: <accept>",
"Content-Type: <content-type>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/auth/login.php"
payload := strings.NewReader("{\n \"email\": \"<string>\",\n \"password\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "<content-type>")
req.Header.Add("Accept", "<accept>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/auth/login.php")
.header("Content-Type", "<content-type>")
.header("Accept", "<accept>")
.body("{\n \"email\": \"<string>\",\n \"password\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/auth/login.php")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = '<content-type>'
request["Accept"] = '<accept>'
request.body = "{\n \"email\": \"<string>\",\n \"password\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"400": {},
"401": {},
"403": {},
"404": {},
"500": {},
"success": true,
"message": "<string>",
"user": {
"id": 123,
"uuid": "<string>",
"nombre": "<string>",
"apellido": "<string>",
"email": "<string>",
"telefono": "<string>",
"tipo_usuario": "<string>",
"calificacion": 123,
"creado_en": "<string>",
"location": {}
},
"token": "<string>",
"token_expires_at": "<string>"
}User Endpoints
Login
Authenticate a user and create a session
POST
/
auth
/
login.php
Login
curl --request POST \
--url https://api.example.com/auth/login.php \
--header 'Accept: <accept>' \
--header 'Content-Type: <content-type>' \
--data '
{
"email": "<string>",
"password": "<string>"
}
'import requests
url = "https://api.example.com/auth/login.php"
payload = {
"email": "<string>",
"password": "<string>"
}
headers = {
"Content-Type": "<content-type>",
"Accept": "<accept>"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': '<content-type>', Accept: '<accept>'},
body: JSON.stringify({email: '<string>', password: '<string>'})
};
fetch('https://api.example.com/auth/login.php', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/auth/login.php",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'email' => '<string>',
'password' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Accept: <accept>",
"Content-Type: <content-type>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/auth/login.php"
payload := strings.NewReader("{\n \"email\": \"<string>\",\n \"password\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "<content-type>")
req.Header.Add("Accept", "<accept>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/auth/login.php")
.header("Content-Type", "<content-type>")
.header("Accept", "<accept>")
.body("{\n \"email\": \"<string>\",\n \"password\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/auth/login.php")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = '<content-type>'
request["Accept"] = '<accept>'
request.body = "{\n \"email\": \"<string>\",\n \"password\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"400": {},
"401": {},
"403": {},
"404": {},
"500": {},
"success": true,
"message": "<string>",
"user": {
"id": 123,
"uuid": "<string>",
"nombre": "<string>",
"apellido": "<string>",
"email": "<string>",
"telefono": "<string>",
"tipo_usuario": "<string>",
"calificacion": 123,
"creado_en": "<string>",
"location": {}
},
"token": "<string>",
"token_expires_at": "<string>"
}Endpoint
POST /auth/login.php
Headers
string
required
Must be
application/jsonstring
required
Must be
application/jsonRequest Body
string
required
User’s email address
string
required
User’s password
Response
boolean
required
Indicates if login was successful
string
Success or error message
object
Authenticated user object with complete profile
Show user object
Show user object
integer
Unique user identifier
string
Universally unique identifier
string
User’s first name
string
User’s last name
string
User’s email address
string
User’s phone number
string
User type:
pasajero, conductor, admin, or empresanumber
Average user rating (0-5)
string
Account creation timestamp (ISO 8601)
object
User’s primary location
string
Authentication token (currently null, reserved for future use)
string
Token expiration timestamp (currently null)
Request Example
curl -X POST https://76.13.114.194/auth/login.php \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"email": "carlos.rodriguez@example.com",
"password": "SecurePass123!"
}'
import 'package:http/http.dart' as http;
import 'dart:convert';
final response = await http.post(
Uri.parse('https://76.13.114.194/auth/login.php'),
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: jsonEncode({
'email': 'carlos.rodriguez@example.com',
'password': 'SecurePass123!',
}),
);
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
if (data['success'] == true) {
// Store user data
final userId = data['user']['id'];
// Navigate to home screen
}
}
const response = await fetch('https://76.13.114.194/auth/login.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
email: 'carlos.rodriguez@example.com',
password: 'SecurePass123!',
}),
});
const data = await response.json();
if (data.success) {
// Store user session
localStorage.setItem('user', JSON.stringify(data.user));
}
<?php
$ch = curl_init('https://76.13.114.194/auth/login.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Accept: application/json',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'email' => 'carlos.rodriguez@example.com',
'password' => 'SecurePass123!',
]));
$response = curl_exec($ch);
$data = json_decode($response, true);
if ($data['success']) {
$_SESSION['user_id'] = $data['user']['id'];
}
?>
Response Example
{
"success": true,
"message": "Login exitoso",
"user": {
"id": 456,
"uuid": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
"nombre": "Carlos",
"apellido": "Rodríguez",
"email": "carlos.rodriguez@example.com",
"telefono": "+573001234567",
"tipo_usuario": "pasajero",
"calificacion": 4.8,
"creado_en": "2024-01-15T10:30:00.000Z",
"actualizado_en": "2024-03-15T14:30:00.000Z",
"location": {
"id": 89,
"usuario_id": 456,
"direccion": "Carrera 15 #85-30",
"latitud": 4.6814,
"longitud": -74.0479,
"ciudad": "Bogotá",
"departamento": "Cundinamarca",
"pais": "Colombia",
"es_principal": true
}
},
"token": null,
"token_expires_at": null
}
{
"success": false,
"message": "Email o contraseña incorrectos"
}
{
"success": false,
"message": "Usuario no encontrado"
}
{
"success": false,
"message": "Cuenta inactiva o suspendida"
}
Error Responses
Bad Request
Missing required fields or invalid request format
Unauthorized
Invalid email or password combination
Forbidden
User account is inactive or suspended
Not Found
User with provided email does not exist
Internal Server Error
Server error during authentication
Session Management
After successful login, store the user data securely:import 'package:shared_preferences/shared_preferences.dart';
// Store user session
final prefs = await SharedPreferences.getInstance();
await prefs.setInt('user_id', userData['id']);
await prefs.setString('user_email', userData['email']);
await prefs.setString('user_type', userData['tipo_usuario']);
// Retrieve user session
final userId = prefs.getInt('user_id');
final userEmail = prefs.getString('user_email');
// Store in localStorage
localStorage.setItem('userId', data.user.id);
localStorage.setItem('userEmail', data.user.email);
// Or use sessionStorage for session-only storage
sessionStorage.setItem('user', JSON.stringify(data.user));
// Retrieve
const userId = localStorage.getItem('userId');
const user = JSON.parse(sessionStorage.getItem('user'));
Never store passwords locally. Only store the user ID and non-sensitive information.
User Types
Thetipo_usuario field indicates the user’s role:
- pasajero - Regular passenger who can book rides
- conductor - Driver who can accept and complete trips
- admin - Administrator with access to admin endpoints
- empresa - Company/fleet manager
See Also
- Register - Create a new user account
- User Profile - Fetch user profile
- Check User Exists - Verify email before login
⌘I