Skip to main content

Overview

The Settings API provides endpoints for managing user account settings including profile information, password changes, currency/language preferences, and AI feature toggles.
All settings endpoints require session-based authentication and operate on the authenticated user’s account.

Authentication

All endpoints require session-based authentication via the @api_login_required decorator.

Update Profile

Update the user’s display name. Endpoint: POST /api/settings/profile

Request Body

fullName
string
required
The user’s full name. Cannot be empty.

Example Request

curl -X POST https://api.finai.com/api/settings/profile \
  -H "Content-Type: application/json" \
  -H "Cookie: session=your_session_cookie" \
  -d '{
    "fullName": "Nguyen Van A"
  }'

Response

{
  "status": "success",
  "message": "Cập nhật họ tên thành công!"
}

Error Responses

{
  "status": "error",
  "message": "Họ tên không được để trống"
}
{
  "status": "error",
  "message": "Lỗi server: [error details]"
}

Update Password

Change the user’s password with current password verification. Endpoint: POST /api/settings/password

Request Body

currentPassword
string
required
The user’s current password for verification
newPassword
string
required
The new password
confirmNewPassword
string
required
Confirmation of the new password (must match newPassword)

Example Request

curl -X POST https://api.finai.com/api/settings/password \
  -H "Content-Type: application/json" \
  -H "Cookie: session=your_session_cookie" \
  -d '{
    "currentPassword": "old_password",
    "newPassword": "new_secure_password",
    "confirmNewPassword": "new_secure_password"
  }'

Response

{
  "status": "success",
  "message": "Đổi mật khẩu thành công!"
}

Error Responses

{
  "status": "error",
  "message": "Vui lòng điền đầy đủ thông tin"
}
{
  "status": "error",
  "message": "Mật khẩu mới không khớp nhau"
}
{
  "status": "error",
  "message": "Mật khẩu hiện tại không đúng"
}

Update Preferences

Update currency and language preferences. Endpoint: POST /api/settings/preferences

Request Body

currency
string
default:"VND"
Currency code (e.g., “VND”, “USD”, “EUR”)
language
string
default:"vi"
Language code (e.g., “vi”, “en”)

Example Request

curl -X POST https://api.finai.com/api/settings/preferences \
  -H "Content-Type: application/json" \
  -H "Cookie: session=your_session_cookie" \
  -d '{
    "currency": "USD",
    "language": "en"
  }'

Response

{
  "status": "success",
  "message": "Đã lưu tùy chỉnh!"
}

Update AI Settings

Enable or disable AI-powered features including transaction categorization and dashboard insights. Endpoint: POST /api/settings/ai

Request Body

aiSuggestion
boolean
required
True to enable AI features, false to disable

Example Request

curl -X POST https://api.finai.com/api/settings/ai \
  -H "Content-Type: application/json" \
  -H "Cookie: session=your_session_cookie" \
  -d '{
    "aiSuggestion": true
  }'

Response

{
  "status": "success",
  "message": "Đã BẬT AI"
}
or when disabled:
{
  "status": "success",
  "message": "Đã TẮT AI"
}

Impact of AI Settings

When AI suggestions are disabled (ai_suggestions=0):
  • The /api/dashboard-insights endpoint returns a disabled status
  • AI-powered transaction categorization may be restricted
  • Chatbot functionality may be limited
The AI settings are stored as an integer in the database: 1 for enabled, 0 for disabled. The API converts the boolean true/false values to 1/0 automatically.

Implementation Reference

The Settings API is implemented in app/routes/settings.py:
settings.py
@settings_bp.route('/api/settings/profile', methods=['POST'])
@api_login_required
def update_profile():
    data = request.json
    new_name = data.get('fullName', '').strip()
    
    if not new_name:
        return jsonify({'status': 'error', 'message': 'Họ tên không được để trống'}), 400
        
    try:
        user = User.query.get(session['user_id'])
        user.name = new_name
        db.session.commit()
        return jsonify({'status': 'success', 'message': 'Cập nhật họ tên thành công!'})
    except Exception as e:
        db.session.rollback()
        return jsonify({'status': 'error', 'message': 'Lỗi server: ' + str(e)}), 500

Database Schema

User settings are stored in the thietlapnguoidung table:
models.py
class UserSetting(db.Model):
    __tablename__ = 'thietlapnguoidung'
    
    user_id = db.Column('MaNguoiDung', db.String(8), db.ForeignKey('nguoidung.MaNguoiDung', ondelete='CASCADE'), primary_key=True)
    currency = db.Column('DonViTienTe', db.String(10), default='VND')
    language = db.Column('NgonNgu', db.String(10), default='vi')
    notifications = db.Column('ThongBao', db.Integer, default=1)
    ai_suggestions = db.Column('AI_GoiY', db.Integer, default=1)
    theme = db.Column('GiaoDien', db.String(20), default='light')

Build docs developers (and LLMs) love