Beispiel #1
0
 /**
  * Handle a registration request for the application.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function postRegister(Request $request)
 {
     $validator = $this->registrar->validator($request->all());
     if ($validator->fails()) {
         $this->throwValidationException($request, $validator);
     }
     $this->auth->login($this->registrar->create($request->all()));
     $member = new Member();
     $member->first_name = $request->first_name;
     $member->last_name = $request->last_name;
     $member->save();
     $mail = new Mail();
     $mail->mail = $request->email;
     $mail->code = rand(1000000, 9999999);
     $mail->save();
     return redirect($this->redirectPath());
 }
Beispiel #2
0
 public function handleCreateMailType()
 {
     // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     // Reduce Credit before approve email
     // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     $receiver_address = Address::where('id', Request::get('receiver_address_id'))->first();
     if (!$receiver_address || $receiver_address->user_id != Auth::user()->id) {
         return redirect('home')->with("error", "มีบางอย่างผิดพลาด");
     }
     $mail_type = DB::table('mailtypes')->where('id', Request::get('mail_type_id'))->first();
     if ($mail_type->price > Auth::user()->credits) {
         return redirect('home')->with('error', 'เครดิตของคุณไม่เพียงพอ');
     }
     $mail = new Mail();
     $mail->user_id = Auth::user()->id;
     $mail->mail_type_id = Request::get('mail_type_id');
     $mail->content = Request::get('content');
     $mail->receiver_name = $receiver_address->name;
     $mail->receiver_address_line_1 = $receiver_address->address_line_1;
     $mail->receiver_address_line_2 = $receiver_address->address_line_2;
     $mail->receiver_address_line_3 = $receiver_address->address_line_3;
     $mail->receiver_postcode = $receiver_address->postcode;
     $mail->status = 0;
     if (Request::get('sender_address_id') != 0) {
         $sender_address = Address::where('id', Request::get('sender_address_id'))->first();
         if (!$sender_address || $sender_address->user_id != Auth::user()->id || $sender_address->is_sender == false) {
             return redirect('home')->with("error", "มีบางอย่างผิดพลาด Test");
         }
         $mail->sender_name = $sender_address->name;
         $mail->sender_address_line_1 = $sender_address->address_line_1;
         $mail->sender_address_line_2 = $sender_address->address_line_2;
         $mail->sender_address_line_3 = $sender_address->address_line_3;
         $mail->sender_postcode = $sender_address->postcode;
     }
     $mail->save();
     $User = User::find(Auth::user()->id);
     $User->credits -= $mail_type->price;
     $User->save();
     return redirect('home')->with("msg", "บันทึกจดหมายของท่านแล้ว");
 }