login
Authenticate users to access the JSON Database Server by verifying email and password credentials, then receive a JWT token for secure API operations.
Instructions
Kullanıcı giriş yapar ve JWT token alır
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| Yes | Kullanıcı e-posta adresi | ||
| password | Yes | Kullanıcı şifresi |
Implementation Reference
- src/index.js:415-474 (handler)The main execution logic for the 'login' tool. Validates user credentials against the database, generates a JWT token upon successful authentication, handles errors for invalid users or passwords, and logs audit events.case 'login': { const { email, password } = args; // Kullanıcıyı bul const user = db.users.find(u => u.email === email); if (!user) { // Başarısız login denemesini logla await auditLogger.loginFailed(email, { reason: 'user_not_found' }); return { content: [{ type: 'text', text: JSON.stringify({ success: false, message: 'Kullanıcı bulunamadı' }) }] }; } // Şifreyi kontrol et const isPasswordValid = await comparePassword(password, user.password); if (!isPasswordValid) { // Başarısız login denemesini logla await auditLogger.loginFailed(email, { reason: 'invalid_password', userId: user.id }); return { content: [{ type: 'text', text: JSON.stringify({ success: false, message: 'Geçersiz şifre' }) }] }; } // JWT token oluştur const token = generateToken(user.id, user.email, user.role); // Başarılı login'i logla await auditLogger.loginSuccess(user.id, user.role, { email, loginTime: new Date().toISOString(), tokenGenerated: true }); return { content: [{ type: 'text', text: JSON.stringify({ success: true, message: 'Giriş başarılı', token, user: { id: user.id, name: user.name, email: user.email, role: user.role, department: user.department, position: user.position } }) }] }; }
- src/index.js:84-95 (schema)The input schema definition for the 'login' tool, specifying required email and password fields. This is part of the tool list returned by ListToolsRequest.{ name: 'login', description: 'Kullanıcı giriş yapar ve JWT token alır', inputSchema: { type: 'object', properties: { email: { type: 'string', description: 'Kullanıcı e-posta adresi' }, password: { type: 'string', description: 'Kullanıcı şifresi' } }, required: ['email', 'password'] } },
- src/audit.js:192-196 (helper)Helper functions for logging successful and failed login attempts to the audit log system, used within the login handler.loginSuccess: (userId, userRole, details = {}) => logAudit(userId, userRole, 'LOGIN_SUCCESS', AUDIT_CATEGORIES.AUTH, AUDIT_LEVELS.INFO, details), loginFailed: (email, details = {}) => logAudit(null, null, 'LOGIN_FAILED', AUDIT_CATEGORIES.AUTH, AUDIT_LEVELS.WARN, { email, ...details }),