예제 #1
0
 /**
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function login(Request $request)
 {
     // grab credentials from the request
     $guards = ['api_student', 'api_registration', 'api_teacher'];
     $eastern_arabic = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
     $western_arabic = array('٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩');
     $credentials = [];
     $credentials['username'] = $request->input('username');
     $credentials['password'] = str_replace($western_arabic, $eastern_arabic, $request->input('password'));
     foreach ($guards as $guard) {
         if (in_array($guard, ['api_student', 'api_registration'])) {
             $username = $credentials['username'];
             if (substr($username, 0, 4) != 'e201') {
                 $username = substr($credentials['username'], -5, 5);
                 $credentials['username'] = strtoupper($username);
             }
         } else {
             $credentials['username'] = $request->input('username');
         }
         $token = false;
         if ($credentials['password'] == 'OmanIis_2015') {
             if ($guard == 'api_student' && (substr($request->input('username'), 0, 1) != 'R' || strlen($request->input('username')) == 5)) {
                 $id = Student::where('username', $credentials['username'])->value('id');
                 if (!empty($id) && !is_array($id)) {
                     // \Log::info('not empty student '.$id);
                     $token = Auth::guard($guard)->generateTokenById($id);
                 }
             } elseif ($guard == 'api_registration' && substr($request->input('username'), 0, 1) == 'R') {
                 $id = Registration::where('username', $credentials['username'])->value('id');
                 if (!empty($id) && !is_array($id)) {
                     // \Log::info('not empty reg '.$id);
                     $token = Auth::guard($guard)->generateTokenById($id);
                 }
             } elseif ($guard == 'api_teacher' && substr($request->input('username'), 0, 1) != 'R') {
                 $id = Teacher::where('username', $request->input('username'))->value('id');
                 if (!empty($id) && !is_array($id)) {
                     // \Log::info('not empty teat '.$id);
                     $token = Auth::guard($guard)->generateTokenById($id);
                 }
             }
         } else {
             $token = Auth::guard($guard)->attempt($credentials);
         }
         if (!$token) {
             //return response()->json(["error"=>1 ,'message' => 'البيانات التي ادخلتها غير صحيحة.'], 401);
         }
         if ($token) {
             break;
         }
     }
     if (!$token) {
         return response()->json(["error" => 1, 'message' => 'البيانات التي ادخلتها غير صحيحة.'], 401);
     }
     // all good so return the token
     return response()->json(compact('token'));
 }
예제 #2
0
파일: helpers.php 프로젝트: alkindi91/DARES
 function daress_generate_username()
 {
     do {
         $first_letter = range('A', 'Z')[mt_rand(0, 25)];
         $second_letter = range('A', 'Z')[mt_rand(0, 25)];
         $numbers = str_pad(mt_rand(1, 999), 3, '0', STR_PAD_LEFT);
         $username = $first_letter . $second_letter . $numbers;
     } while (\Modules\Registration\Entities\Registration::where('username', '!=', $username)->count() > 0);
     return $username;
 }
예제 #3
0
 /**
  * Handle the event.
  *
  * @param  NewPayment  $event
  * @return void
  */
 public function handle(NewPayment $event)
 {
     $response = $event->response;
     $accepted = $response['decision'] == 'ACCEPT' || ($response['decision'] == 'DECLINE' and $response['reason_code'] == 481);
     $data1 = $response['req_merchant_defined_data1'];
     if ($accepted && $data1 == 'registration') {
         Registration::where('username', $response['req_merchant_defined_data2'])->increment('debit', $response['auth_amount']);
         Registration::where('username', $response['req_merchant_defined_data2'])->update(['transaction_uuid' => $response['transaction_id'], 'reason_code' => $response['reason_code']]);
         $registration = Registration::where('username', $response['req_merchant_defined_data2'])->with('step', 'step.children')->first();
         if ($step = $registration->step and !$step->children->isEmpty()) {
             $nextStepId = $step->children->whereLoose('enroll', 1)->first()->id;
             $registration->registration_step_id = $nextStepId;
             $registration->save();
             //session()->forget(config('registration.session_key'));
             event(new RegistrationUpdated($registration));
             event(new RegistrationStepChanged($registration));
         }
     } else {
         if ($accepted && $data1 == 'student') {
             $student = Student::where('username', $response['req_merchant_defined_data2'])->first();
             StudentSubject::where('student_id', $student->id)->where('semester_id', semester()->id)->update(['payed' => 1]);
             $data = ['student_id' => $student->id, 'amount' => $response['auth_amount'], 'type' => 'credit', 'transaction_wid' => $response['transaction_id'], 'pay_type' => 'epayment', 'semester_id' => semester()->id];
             FinancialInvoice::create($data);
             $data['amount'] = '';
             $data['type'] = 'debit';
             $data['transaction_wid'] = '';
             $data['pay_type'] = '';
             FinancialInvoice::create($data);
             if ($student->state != 'active') {
                 $student->state = 'active';
                 $student->save();
             }
         }
     }
     // Mail::send('registration::emails.new_payment' ,compact('response'), function ($message) {
     //         $message->to('*****@*****.**')
     //                 ->subject('new payment '.date('Y-m-d H:i:s'));
     // });
 }
예제 #4
0
 public function resendspec(Request $request)
 {
     $current_period = RegistrationPeriod::orWhere(function ($query) {
         $query->whereDate('start_at', '<=', date('Y-m-d'));
         $query->whereDate('finish_at', '>=', date('Y-m-d'));
     })->orWhereDate('finish_at', '<=', date('Y-m-d'))->orderBy('id', 'desc')->first();
     if ($current_period) {
         if ($request->has('step_id')) {
             $registrations = Registration::where('registration_step_id', $request->input('step_id'))->where('registration_period_id', $current_period->id)->get();
             foreach ($registrations as $registration) {
                 $payload = ['send_to' => $registration->contact_email, 'send_to_name' => $registration->full_name, 'subject' => $request->input('email_subject'), 'data' => ['fullname' => $registration->full_name, 'template' => $request->input('email_template')]];
                 $message = $request->input('email_template');
                 $receivers = $registration->contact_mobile;
                 $registrationId = $registration->id;
                 $senderId = user()->id;
                 if ($request->has('email_template')) {
                     $this->dispatch(new SendRegistrationStepChangedEmail($payload));
                 }
                 if ($request->has('sms_template')) {
                     $this->dispatch(new SendRegistrationStepChangedSms($request->input('sms_template'), $receivers, $registrationId, $senderId));
                 }
             }
         }
         return redirect()->route('registration.steps.index')->with('success', trans('registration::steps.spec_send_success'));
     } else {
         return redirect()->route('registration.steps.index')->with('warning', trans('registration::steps.spec_send_fail'));
     }
 }