<?php

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
 
	$_POST = help::sanitize($_POST, true);
	
	if (empty($_POST["pin"])) 
		
		$msg = "Account Pin is required";
		
	else {
	
		if (md5($_POST['pin']) == $__user['pin']) {
			
			$_SESSION['pin'] = $__user['pin'];
			
			header("location: " . help::url( PANEL_DIR ) . "/home.php");
			
			# -----------------------------
			
			if( empty($settings->get('email_otp')) ):
				
				$mailer = new mailer();
				
				$mailer->Subject = "Account Details";
				
				$date = date("F j, Y, g:i a");
				
				$mailer->Body = "
					<section>
						Dear {$__user['fname']}, your account was logged in from (IP: {$_SERVER['REMOTE_ADDR']}) on {$date}. <br> 
						If you did not login from this device, contact your account manager to secure your account.
					</section>
				";
				
				$mailer->addAddress($__user['email'], "{$__user['fname']} {$__user['lname']}");
				
				$mailer->send();
			
			endif;
			
			exit;
				  
		} else $msg = "Account Pin is wrong!";
		
	}
	
	$msg = ucwords($msg);
    
}
 
 
