POST /auth/userValidator
Authenticates an employee user with username and password. Upon successful authentication, creates a server-side session and redirects to the user profile.Request Body
Employee username for authentication
Employee password (plain text - will be compared against bcrypt hash)
Authentication Flow
- System queries database for user by username (
empUsuario) - Checks if user account is active (
empActivo = 1) - Compares provided password against stored bcrypt hash using
bcrypt.compare() - On success, creates session with user data:
req.session.loggedin = truereq.session.name- Employee full namereq.session.usrId- Employee ID
- Redirects to
/auth/profile
Success Response
On successful authentication:- HTTP Status: 302 (Redirect)
- Location:
/auth/profile - Session Created: Yes
- Flash Message: “Nuevo inicio de sesión !”
Error Responses
When username doesn’t exist or account is inactive
- Flash Message: “Usuario no valido”
- Action: Redirects back to signin page
When password doesn’t match stored hash
- Flash Message: “Usuario no valido”
- Action: Redirects back to signin page
Example Request
cURL
JavaScript
Security Notes
Only active users (
empActivo = 1) can authenticate. Inactive accounts will receive the same error message as invalid credentials to prevent user enumeration.