FinceptTerminal is a modern finance application offering advanced market analytics, investment research, and economic data tools, designed for interactive exploration and data-driven decision-making in a user-friendly environment.
C++ ai-agentsalgorithmic-tradingbloomberg-terminalcppfinancefinancial-marketsfintechgood-first-issueinvestmentinvestment-researchmachine-learningopensourcepythonqtquantitative-financestock-markettrading
profile update
tilakpatel227964d547e28f
diff --git a/fincept-terminal-desktop/src/components/auth/LoginScreen.tsx b/fincept-terminal-desktop/src/components/auth/LoginScreen.tsxindex 9f1996471..bcc55eafa 100644--- a/fincept-terminal-desktop/src/components/auth/LoginScreen.tsx+++ b/fincept-terminal-desktop/src/components/auth/LoginScreen.tsx@@ -1,11 +1,11 @@// File: src/components/auth/LoginScreen.tsx-// User login screen with email/password authentication and guest access+// User login screen with email/password authentication, MFA support, and guest accessimport React, { useState } from 'react';import { Button } from "@/components/ui/button";import { Input } from "@/components/ui/input";import { Label } from "@/components/ui/label";-import { Mail, Lock, Eye, EyeOff } from "lucide-react";+import { Mail, Lock, Eye, EyeOff, Shield } from "lucide-react";import { Screen } from '../../App';import { useAuth } from '@/contexts/AuthContext';import { useTranslation } from 'react-i18next';@@ -15,7 +15,7 @@ interface LoginScreenProps {}const LoginScreen: React.FC<LoginScreenProps> = ({ onNavigate }) => {- const { login, setupGuestAccess } = useAuth();+ const { login, setupGuestAccess, verifyMfaAndLogin } = useAuth();const { t } = useTranslation('auth');const [email, setEmail] = useState("");const [password, setPassword] = useState("");@@ -23,6 +23,8 @@ const LoginScreen: React.FC<LoginScreenProps> = ({ onNavigate }) => {const [isLoading, setIsLoading] = useState(false);const [isGuestLoading, setIsGuestLoading] = useState(false);const [error, setError] = useState("");+ const [mfaRequired, setMfaRequired] = useState(false);+ const [mfaCode, setMfaCode] = useState("");const handleLogin = async (e: React.FormEvent) => {e.preventDefault();@@ -40,8 +42,11 @@ const LoginScreen: React.FC<LoginScreenProps> = ({ onNavigate }) => {if (result.success) {// App.tsx useEffect will handle navigation based on account_type+ } else if (result.mfa_required) {+ // MFA is required, show MFA input+ setMfaRequired(true);+ setError("");} else {-// Provide user-friendly error messagesconst errorMessage = result.error || 'Login failed. Please check your credentials.';@@ -72,6 +77,32 @@ const LoginScreen: React.FC<LoginScreenProps> = ({ onNavigate }) => {}};+ const handleMfaVerify = async (e: React.FormEvent) => {+ e.preventDefault();++ if (!mfaCode) {+ setError('Please enter the MFA code sent to your email.');+ return;+ }++ setIsLoading(true);+ setError("");++ try {+ const result = await verifyMfaAndLogin(email, mfaCode);++ if (result.success) {+ // App.tsx useEffect will handle navigation based on account_type+ } else {+ setError(result.error || 'Invalid MFA code. Please check your email and try again.');+ }+ } catch (err) {+ setError('MFA verification failed. Please try again.');+ } finally {+ setIsLoading(false);+ }+ };+const handleGuestAccess = async () => {setIsGuestLoading(true);setError("");@@ -91,6 +122,81 @@ const LoginScreen: React.FC<LoginScreenProps> = ({ onNavigate }) => {}};+ // MFA Verification Screen+ if (mfaRequired) {+ return (+ <div className="bg-zinc-900/90 backdrop-blur-sm border border-zinc-700 rounded-lg p-6 w-full max-w-sm mx-4 shadow-2xl">+ <div className="mb-6">+ <div className="flex items-center gap-2 mb-3">+ <Shield className="h-6 w-6 text-blue-400" />+ <h2 className="text-white text-2xl font-light">Two-Factor Authentication</h2>+ </div>+ <p className="text-zinc-400 text-xs leading-5">+ A verification code has been sent to your email. Please enter it below to complete login.+ </p>+ </div>++ <form onSubmit={handleMfaVerify} className="space-y-4">+ <div className="space-y-1">+ <Label htmlFor="mfaCode" className="text-white text-xs">+ Verification Code+ </Label>+ <Input+ id="mfaCode"+ type="text"+ placeholder="Enter 6-digit code"+ value={mfaCode}+ onChange={(e) => {+ setMfaCode(e.target.value);+ if (error) setError("");+ }}+ className="bg-zinc-800 border-zinc-600 text-white placeholder-zinc-500 py-2 h-9 text-sm focus:border-zinc-500 focus:ring-1 focus:ring-zinc-500 text-center tracking-widest text-lg"+ disabled={isLoading}+ maxLength={6}+ autoComplete="one-time-code"+ required+ />+ </div>++ {error && (+ <div className="text-red-400 text-xs bg-red-900/20 border border-red-900/50 rounded p-2">+ {error}+ </div>+ )}++ <div className="flex flex-col gap-2 pt-1">+ <Button+ type="submit"+ className="w-full bg-blue-600 hover:bg-blue-700 text-white py-2 text-sm font-normal transition-colors disabled:opacity-50"+ disabled={isLoading}+ >+ {isLoading ? (+ <div className="flex items-center justify-center">+ <div className="w-3 h-3 border border-white/30 border-t-white rounded-full animate-spin mr-1.5"></div>+ Verifying...+ </div>+ ) : 'Verify & Login'}+ </Button>++ <button+ type="button"+ onClick={() => {+ setMfaRequired(false);+ setMfaCode("");+ setError("");+ }}+ className="text-zinc-400 hover:text-zinc-300 text-xs transition-colors"+ disabled={isLoading}+ >+ ← Back to login+ </button>+ </div>+ </form>+ </div>+ );+ }++ // Regular Login Screenreturn (<div className="bg-zinc-900/90 backdrop-blur-sm border border-zinc-700 rounded-lg p-6 w-full max-w-sm mx-4 shadow-2xl"><div className="mb-6">@@ -228,4 +334,4 @@ const LoginScreen: React.FC<LoginScreenProps> = ({ onNavigate }) => {);};-export default LoginScreen\ No newline at end of file+export default LoginScreen;diff --git a/fincept-terminal-desktop/src/components/tabs/ProfileTab.tsx b/fincept-terminal-desktop/src/components/tabs/ProfileTab.tsxindex 804bb1b30..518a318c1 100644--- a/fincept-terminal-desktop/src/components/tabs/ProfileTab.tsx+++ b/fincept-terminal-desktop/src/components/tabs/ProfileTab.tsx@@ -337,6 +337,47 @@ const SecuritySection: React.FC<{setShowApiKey: (show: boolean) => void;}> = ({ session, onRegenerateKey, loading, showApiKey, setShowApiKey }) => {const apiKey = session?.api_key || '';+ const [mfaLoading, setMfaLoading] = React.useState(false);+ const [showPasswordPrompt, setShowPasswordPrompt] = React.useState(false);+ const [password, setPassword] = React.useState('');++ const handleEnableMFA = async () => {+ if (!session?.api_key) return;+ if (confirm('Enable Multi-Factor Authentication? You will receive OTP codes via email for login.')) {+ setMfaLoading(true);+ const result = await UserApiService.enableMFA(session.api_key);+ setMfaLoading(false);+ if (result.success) {+ alert('MFA enabled successfully! You will receive OTP codes via email during login.');+ window.location.reload(); // Refresh to update MFA status+ } else {+ alert(`Failed to enable MFA: ${result.error}`);+ }+ }+ };++ const handleDisableMFA = async () => {+ if (!session?.api_key) return;+ setShowPasswordPrompt(true);+ };++ const confirmDisableMFA = async () => {+ if (!password) {+ alert('Please enter your password to disable MFA.');+ return;+ }+ setMfaLoading(true);+ const result = await UserApiService.disableMFA(session.api_key, password);+ setMfaLoading(false);+ setShowPasswordPrompt(false);+ setPassword('');+ if (result.success) {+ alert('MFA disabled successfully!');+ window.location.reload(); // Refresh to update MFA status+ } else {+ alert(`Failed to disable MFA: ${result.error}`);+ }+ };return (<div style={{ display: 'flex', flexDirection: 'column', gap: '16px' }}>@@ -399,12 +440,147 @@ const SecuritySection: React.FC<{label="EMAIL VERIFICATION"enabled={session?.user_info?.is_verified}/>- <SecurityRow- label="TWO-FACTOR AUTHENTICATION"- enabled={session?.user_info?.mfa_enabled}- />+ <div style={{+ display: 'flex',+ justifyContent: 'space-between',+ alignItems: 'center',+ padding: '10px 0',+ borderBottom: `1px solid ${COLORS.BORDER}`+ }}>+ <span style={{ color: COLORS.WHITE, fontSize: '11px' }}>MULTI-FACTOR AUTHENTICATION (EMAIL-BASED)</span>+ <div style={{ display: 'flex', alignItems: 'center', gap: '12px' }}>+ <div style={{ display: 'flex', alignItems: 'center', gap: '6px' }}>+ <span style={{+ color: session?.user_info?.mfa_enabled ? COLORS.GREEN : COLORS.RED,+ fontSize: '11px',+ fontWeight: 'bold'+ }}>+ {session?.user_info?.mfa_enabled ? 'ENABLED' : 'DISABLED'}+ </span>+ {session?.user_info?.mfa_enabled ? (+ <CheckCircle size={14} color={COLORS.GREEN} />+ ) : (+ <AlertCircle size={14} color={COLORS.RED} />+ )}+ </div>+ <button+ onClick={session?.user_info?.mfa_enabled ? handleDisableMFA : handleEnableMFA}+ disabled={mfaLoading}+ style={{+ padding: '6px 12px',+ backgroundColor: session?.user_info?.mfa_enabled ? COLORS.RED : COLORS.GREEN,+ border: 'none',+ color: COLORS.WHITE,+ cursor: mfaLoading ? 'not-allowed' : 'pointer',+ fontSize: '10px',+ fontFamily: 'monospace',+ fontWeight: 'bold',+ opacity: mfaLoading ? 0.5 : 1+ }}+ >+ {mfaLoading ? 'PROCESSING...' : (session?.user_info?.mfa_enabled ? 'DISABLE' : 'ENABLE')}+ </button>+ </div>+ </div></div></DataPanel>++ {/* Password Prompt Modal for Disabling MFA */}+ {showPasswordPrompt && (+ <div style={{+ position: 'fixed',+ top: 0,+ left: 0,+ right: 0,+ bottom: 0,+ backgroundColor: 'rgba(0,0,0,0.8)',+ display: 'flex',+ alignItems: 'center',+ justifyContent: 'center',+ zIndex: 1000+ }}>+ <div style={{+ backgroundColor: COLORS.PANEL_BG,+ border: `2px solid ${COLORS.ORANGE}`,+ padding: '24px',+ maxWidth: '400px',+ width: '90%'+ }}>+ <div style={{+ color: COLORS.ORANGE,+ fontSize: '14px',+ fontWeight: 'bold',+ marginBottom: '16px',+ display: 'flex',+ alignItems: 'center',+ gap: '8px'+ }}>+ <Shield size={18} />+ DISABLE MULTI-FACTOR AUTHENTICATION+ </div>+ <div style={{+ color: COLORS.MUTED,+ fontSize: '11px',+ marginBottom: '16px'+ }}>+ Please enter your password to confirm disabling MFA:+ </div>+ <input+ type="password"+ value={password}+ onChange={(e) => setPassword(e.target.value)}+ onKeyPress={(e) => e.key === 'Enter' && confirmDisableMFA()}+ placeholder="Enter your password"+ style={{+ width: '100%',+ padding: '10px',+ backgroundColor: COLORS.HEADER_BG,+ border: `1px solid ${COLORS.BORDER}`,+ color: COLORS.WHITE,+ fontSize: '11px',+ fontFamily: 'monospace',+ marginBottom: '16px'+ }}+ />+ <div style={{ display: 'flex', gap: '8px', justifyContent: 'flex-end' }}>+ <button+ onClick={() => {+ setShowPasswordPrompt(false);+ setPassword('');+ }}+ style={{+ padding: '8px 16px',+ backgroundColor: COLORS.HEADER_BG,+ border: `1px solid ${COLORS.BORDER}`,+ color: COLORS.WHITE,+ cursor: 'pointer',+ fontSize: '11px',+ fontFamily: 'monospace'+ }}+ >+ CANCEL+ </button>+ <button+ onClick={confirmDisableMFA}+ disabled={mfaLoading}+ style={{+ padding: '8px 16px',+ backgroundColor: COLORS.RED,+ border: 'none',+ color: COLORS.WHITE,+ cursor: mfaLoading ? 'not-allowed' : 'pointer',+ fontSize: '11px',+ fontFamily: 'monospace',+ fontWeight: 'bold',+ opacity: mfaLoading ? 0.5 : 1+ }}+ >+ {mfaLoading ? 'PROCESSING...' : 'CONFIRM DISABLE'}+ </button>+ </div>+ </div>+ </div>+ )}</div>);};diff --git a/fincept-terminal-desktop/src/contexts/AuthContext.tsx b/fincept-terminal-desktop/src/contexts/AuthContext.tsxindex 861e03820..ca4b48601 100644--- a/fincept-terminal-desktop/src/contexts/AuthContext.tsx+++ b/fincept-terminal-desktop/src/contexts/AuthContext.tsx@@ -4,6 +4,7 @@import React, { createContext, useContext, useState, useEffect, ReactNode } from 'react';import { AuthApiService } from '@/services/authApi';import { PaymentApiService } from '@/services/paymentApi';+import { UserApiService } from '@/services/userApi';// Response types to match your APIexport interface LoginResponse {@@ -131,7 +132,7 @@ interface AuthContextType {isFirstTimeUser: boolean;availablePlans: SubscriptionPlan[];isLoadingPlans: boolean;- login: (email: string, password: string) => Promise<{ success: boolean; error?: string }>;+ login: (email: string, password: string) => Promise<{ success: boolean; error?: string; mfa_required?: boolean }>;signup: (username: string,email: string,@@ -141,6 +142,7 @@ interface AuthContextType {country_code?: string) => Promise<{ success: boolean; error?: string }>;verifyOtp: (email: string, otp: string) => Promise<{ success: boolean; error?: string }>;+ verifyMfaAndLogin: (email: string, otp: string) => Promise<{ success: boolean; error?: string }>;setupGuestAccess: () => Promise<{ success: boolean; error?: string }>;logout: () => Promise<void>;checkApiConnectivity: () => Promise<boolean>;@@ -484,7 +486,7 @@ const fetchUserProfile = async (apiKey: string): Promise<UserProfileResponse['da};// Login function- const login = async (email: string, password: string): Promise<{ success: boolean; error?: string }> => {+ const login = async (email: string, password: string): Promise<{ success: boolean; error?: string; mfa_required?: boolean }> => {try {const result = await AuthApiService.login({ email, password }) as ApiResponse;@@ -498,6 +500,15 @@ const fetchUserProfile = async (apiKey: string): Promise<UserProfileResponse['da// But makeApiRequest wraps it again, so we need to check result.data.dataconst apiData = (result.data as any)?.data || result.data;+ // Check if MFA is required+ if (result.success && apiData && apiData.mfa_required) {+ return {+ success: false,+ mfa_required: true,+ error: 'MFA verification required'+ };+ }+if (result.success && apiData && apiData.api_key) {const apiKey = apiData.api_key;@@ -635,6 +646,61 @@ const fetchUserProfile = async (apiKey: string): Promise<UserProfileResponse['da}};+ // Verify MFA and complete login+ const verifyMfaAndLogin = async (email: string, otp: string): Promise<{ success: boolean; error?: string }> => {+ try {+ const result = await UserApiService.verifyMFA(email, otp) as ApiResponse;++ // Backend returns: { success: true, data: { api_key: "..." } }+ const apiData = (result.data as any)?.data || result.data;++ if (result.success && apiData && apiData.api_key) {+ const apiKey = apiData.api_key;++ const [userProfile, userSubscription] = await Promise.all([+ fetchUserProfile(apiKey),+ fetchUserSubscription(apiKey)+ ]);++ const newSession: SessionData = {+ authenticated: true,+ user_type: 'registered',+ api_key: apiKey,+ device_id: generateDeviceId(),+ user_info: userProfile ? {+ username: userProfile.username,+ email: userProfile.email,+ account_type: userProfile.account_type,+ credit_balance: userProfile.credit_balance,+ is_verified: userProfile.is_verified,+ mfa_enabled: userProfile.mfa_enabled+ } : {+ email: email,+ account_type: 'free',+ credit_balance: 0+ },+ subscription: userSubscription || undefined+ };++ setSession(newSession);+ saveSession(newSession);+ setIsFirstTimeUser(checkIsFirstTimeUser());++ return { success: true };+ } else {+ return {+ success: false,+ error: result.error || result.message || 'MFA verification failed'+ };+ }+ } catch (error) {+ return {+ success: false,+ error: error instanceof Error ? error.message : 'MFA verification failed'+ };+ }+ };+// Forgot password functionconst forgotPassword = async (email: string): Promise<{ success: boolean; error?: string }> => {try {@@ -754,6 +820,7 @@ const fetchUserProfile = async (apiKey: string): Promise<UserProfileResponse['dalogin,signup,verifyOtp,+ verifyMfaAndLogin,setupGuestAccess,logout,checkApiConnectivity,diff --git a/fincept-terminal-desktop/src/services/userApi.tsx b/fincept-terminal-desktop/src/services/userApi.tsxindex 0aca58209..69f1d6ce2 100644--- a/fincept-terminal-desktop/src/services/userApi.tsx+++ b/fincept-terminal-desktop/src/services/userApi.tsx@@ -186,6 +186,42 @@ export class UserApiService {return makeApiRequest('/support/stats', 'GET', apiKey);}+ // ========================+ // MFA (Multi-Factor Authentication)+ // ========================++ static async enableMFA(apiKey: string): Promise<ApiResponse> {+ return makeApiRequest('/user/mfa/enable', 'POST', apiKey);+ }++ static async disableMFA(apiKey: string, password: string): Promise<ApiResponse> {+ return makeApiRequest('/user/mfa/disable', 'POST', apiKey, { password });+ }++ static async verifyMFA(email: string, otp: string): Promise<ApiResponse> {+ // No API key required - called after initial login+ try {+ const response = await fetch(getApiEndpoint('/user/verify-mfa'), {+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({ email, otp }),+ });+ const data = await response.json();+ return {+ success: response.ok,+ data,+ error: response.ok ? undefined : data.detail || 'MFA verification failed',+ status_code: response.status,+ };+ } catch (error) {+ return {+ success: false,+ error: error instanceof Error ? error.message : 'Network error',+ status_code: 500,+ };+ }+ }+// ========================// NEWSLETTER// ========================