Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64
Your IP : 18.225.156.91
<?php
require_once( dirname( dirname(__FILE__) )."/sendGridMail.php");
function uniclareChangeEmailSendOTP($aobj_context)
{
$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
$passwd = $aobj_context->mobj_data['passwd'];
$email = $aobj_context->mobj_data['email'];
$regno = $aobj_context->mobj_data['regno'];
$univcode = $aobj_context->mobj_data['univcode'];
if($passwd == "" || $email == "" || $regno == "" || $univcode == ""){
$arr['msg'] = 'Invalid params.';
echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure");
return;
}
$query = "select fmobileno, femail from masuser
where fpasswd='{$passwd}' and fregno='{$regno}' and funivcode='{$univcode}'";
// var_dump($query);
$count = $aobj_context->mobj_db->GetRow($query);
if(count($count) <= 0){
$arr['msg'] = 'Something Went Wrong, Check the password';
echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure");
return;
}
if($count['femail'] == $email) {
$arr['msg'] = 'New Email ID. cannot be same as old Email ID';
echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure");
return;
}
$query = "select femail from masuser
where femail = '{$email}'";
// var_dump($query);
$row = $aobj_context->mobj_db->GetRow($query);
if(count($row) > 0) {
$arr['msg'] = 'New Email ID is already registered. ';
echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure");
return;
}
$mobileno = $count['fmobileno'];
$query = "select femailotp from masuser where fmobileno = '{$mobileno}'
and ROUND(time_to_sec((TIMEDIFF(NOW(), FEMAILOTPTIME))) / 60) <= 5";
$result = $aobj_context->mobj_db->GetRow($query);
if(count($result) > 0)
{
$emailotp = $result['femailotp'];
}
else
{
$emailotp = rand(100000, 900000); //strtoupper(substr(sha1(rand()), 0, 4));
}
$message="<html>";
$message.="<body>";
$message.="<style>";
$message.=".mail_tbl td{text-align:left; padding:2px; font-size:12px; font-family: Verdana, Arial, Helvetica, sans-serif;}";
$message.="</style>";
$message.="<p style='font-size:12px; font-family: Verdana, Arial, Helvetica, sans-serif'>Dear Student,</p></br>";
$message.="<p style='font-size:12px; font-family: Verdana, Arial, Helvetica, sans-serif'>Your Email OTP for Email Id Change is ".$emailotp."</p></br>";
$message.="</br>";
$message.="</body>";
$message.="</html>";
$subject="Uniclare Authentication";
$resp = sendGridMail($email,$subject,$message);
$query = "update masuser set FRESETEMAILOTP = '{$emailotp}',
femailotp='{$emailotp}',
FRESETEMAILOTPTIME = now(),
FRESETEMAILOTPCNT = FRESETEMAILOTPCNT+1
where fmobileno = '{$mobileno}'";
$result = $aobj_context->mobj_db->Execute($query);
if($result) {
$res['msg'] = 'OTP sent to new Email ID';
echo $aobj_context->mobj_output->ToJSONEnvelope($res,0,"success");
}
else {
$arr['msg'] = 'Something Went Wrong.';
echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure");
}
}
function uniclareChangeEmailID($aobj_context)
{
$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
$univcode = $aobj_context->mobj_data['univcode'];
$data = $aobj_context->req_body;
$smsotp = $data['emailotp'];
$email = $data['email'];
$regno = $data['regno'];
if($smsotp == "" || $email == "" || $regno == "" || $univcode == ""){
$arr['msg'] = 'Invalid params.';
echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure");
return;
}
// $arr = array();
$query = "select * from masuser
where FRESETEMAILOTP='{$smsotp}' and fregno = '{$regno}' and funivcode='{$univcode}'";
$result = $aobj_context->mobj_db->GetAll($query);
if(count($result) > 0){
$query = "update masuser set femail='{$email}', fupdtime=now()
where fregno = '{$regno}' and funivcode='{$univcode}'";
$result = $aobj_context->mobj_db->Execute($query);
if($result){
$arr['msg']='Updated successfully';
echo $aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success");
}else{
$arr['msg']='Updation Failed.';
echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure");
}
} else {
$arr['msg']="Invalid OTP";
echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure");
}
}
?>
|