IMMREX7
<?php
namespace App\Http\Controllers\API;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Database\QueryException;
use \App\Http\SendNotificationApi;
use App\Http\SendSmsApi;
use Illuminate\Support\Str;
use Carbon\Carbon;
class ForgotPasswordController extends Controller {
public function manageFee($from,$to){
$feeheader = DB::table('feeheads')->where('idSchool',25)->where('idFinancialYear',$from)->get();
echo count($feeheader).'<br>';
$total = 0;
foreach( $feeheader as $feehead){
$fromDate = Carbon::parse($feehead->fromDate)->addYear()->format('Y-m-d');
$toDate = Carbon::parse($feehead->toDate)->addYear()->format('Y-m-d');
$feehead->fromDate = $fromDate;
$feehead->toDate = $toDate;
$feehead->idFinancialYear = $to;
$clone = (array) $feehead;
$idFeehead = $clone['idFeehead'];
unset($clone['idFeehead']);
if (DB::table('feeheads')->where('idSchool', '=', 25)->where('idFinancialYear', '=', $clone['idFinancialYear'])
->where('studentCategory', '=', $clone['studentCategory'])
->where('feeheadName', '=', $clone['feeheadName'])->where('amount', '=', $clone['amount'])->whereDate('fromDate', '=', $clone['fromDate'])->whereDate('toDate', '=', $clone['toDate'])->where('idClass', '=', $clone['idClass'])->where('idSection', '=', $clone['idSection'])->first() == null)
{
\App\FeeHead::insert($clone);
echo $idFeehead.'<br>';
$total++;
}
}
$newfeeheader = DB::table('feeheads')->where('idSchool',25)->where('idFinancialYear',$to)->count();
echo 'Extrar -- '.$total.' record <br>';
echo $newfeeheader;
}
public function sendOtp(Request $request) {
if(!isset($request->studentRole)){
$teacher = \App\Employee::where('mobile', '=', $request->mobile)->first();
if (isset($teacher)) {
$request->studentRole = "N";
}else $request->studentRole = "Y";
}
if($request->studentRole == "Y"){
$otp = mt_rand(100000, 999999);
//$parent = \App\AdmEntry::where('father_mobile', '=', $request->mobile)->orWhere('mother_mobile', '=', $request->mobile)->first();
$parent = \App\Parents::where('mobile', '=', $request->mobile)->first();
if($parent == null)
return response()->json(['success' => "Mobile number not found"], 200, ['app-status' => 'success']);
$school = \App\School::where('idSchool', '=', $parent->idSchool)->first();
$parent->otp = $otp;
$parent->otpSendAt = \Carbon\Carbon::now();
$parent->update();
$message = $otp.' OTP for reseting Password. Regards Jijau Enterprises.';
$phone_number = $request->mobile;
\App\Http\SendSmsApi::initiateForgotPassword($phone_number, $message, $school);
return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
}else{
$teacher = \App\Employee::where('mobile', '=', $request->mobile)->first();
if($teacher){
$otp = mt_rand(100000, 999999);
$school = \App\School::where('idSchool', '=', $teacher->idSchool)->first();
$teacher->otp = $otp;
$teacher->otpSendAt = \Carbon\Carbon::now();
$teacher->update();
$message = $otp.' OTP for reseting Password. Regards Jijau Enterprises.';
$phone_number = $request->mobile;
\App\Http\SendSmsApi::initiateForgotPassword($phone_number, $message, $school);
return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
}else{
return response()->json(['success' => "failed",'message'=>'This Mobile no is not registered with us.'], 422, ['app-status' => 'failed']);
}
}
}
public function verifyOtp(Request $request) {
if(!isset($request->studentRole)){
$teacher = \App\Employee::where('mobile', '=', $request->mobile)->first();
if (isset($teacher)) {
$request->studentRole = "N";
}else $request->studentRole = "Y";
}
if ($request->studentRole == "Y") {
$parent = \App\Parents::where('mobile', '=', $request->mobile)->where('otp', '=', $request->otp)->first();
$to = \Carbon\Carbon::now();
$otpvalid = $parent->otpsendAt;
$diff_in_minutes = $to->diffInMinutes($otpvalid);
if ($diff_in_minutes <= 5) {
$token= Str::random(32);
$parent->password_token=$token;
$parent->passwordSendAt = \Carbon\Carbon::now();
$parent->update();
return response()->json(['success' => "SUCCESS",'message'=>$token], 200, ['app-status' => 'success']);
} else {
return response()->json(['success' => "failed",'message'=>'Otp is invalid. Re-enter/Re-generate the OTP'], 422, ['app-status' => 'failed']);
}
} else {
$teacher = \App\Employee::where('mobile', '=', $request->mobile)->first();
if($teacher){
$to = \Carbon\Carbon::now();
$otpvalid = $teacher->otpsendAt;
$diff_in_minutes = $to->diffInMinutes($otpvalid);
if ($diff_in_minutes <= 5) {
$token= Str::random(32);
$teacher->password_token=$token;
$teacher->passwordSendAt = \Carbon\Carbon::now();
$teacher->update();
return response()->json(['success' => "SUCCESS",'message'=>$token], 200, ['app-status' => 'success']);
} else {
return response()->json(['success' => "failed",'message'=>'Otp is invalid. Re-enter/Re-generate the OTP'], 422, ['app-status' => 'failed']);
}
}else{
return response()->json(['success' => "failed",'message'=>'Otp is invalid. Re-enter/Re-generate the OTP'], 422, ['app-status' => 'failed']);
}
}
}
public function resetPassword(Request $request){
if(!isset($request->studentRole)){
$teacher = \App\Employee::where('mobile', '=', $request->mobile)->first();
if (isset($teacher)) {
$request->studentRole = "N";
}else $request->studentRole = "Y";
}
if ($request->studentRole == "Y") {
$to = \Carbon\Carbon::now();
$parent = \App\Parents::where('mobile', '=', $request->mobile)->first();
$otpvalid = $parent->passwordSendAt;
$diff_in_minutes = $to->diffInMinutes($otpvalid);
if ($diff_in_minutes <= 10 && $request->token==$parent->password_token) {
$parent->password = bcrypt($request->pwd);
if($parent->save())
return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
else
return response()->json(['success' => "Failed"], 200, ['app-status' => 'success']);
}else{
return response()->json(['success' => "failed",'message'=>'Token has expired please try again'], 200, ['app-status' => 'failed']);
}
}else{
$teacher = \App\Employee::where('mobile', '=', $request->mobile)->first();
if($teacher){
$to = \Carbon\Carbon::now();
$otpvalid = $teacher->passwordSendAt;
$diff_in_minutes = $to->diffInMinutes($otpvalid);
if ($diff_in_minutes <= 10 && $request->token==$teacher->password_token) {
$teacher->password = bcrypt($request->pwd);
if($teacher->save())
return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
else
return response()->json(['success' => "Failed"], 200, ['app-status' => 'success']);
}else{
return response()->json(['success' => "failed",'message'=>'Token has expired please try again'], 200, ['app-status' => 'failed']);
}
}else{
return response()->json(['success' => "failed",'message'=>'Token has expired please try again'], 200, ['app-status' => 'failed']);
}}
}
}
Copyright © 2021 -