Beispiel #1
0
 /**
  * function to post 
  * reset new password and 
  * remove code in table user
  */
 function post_reset_password()
 {
     $input = request()->input();
     if (!$input) {
         return app()->abort(404);
     }
     ///////////////////
     // validate data //
     //////////////////
     $rules['password_baru'] = ['required', 'min:8', 'confirmed'];
     $validator = Validator::make(request()->input(), $rules);
     if ($validator->fails()) {
         return redirect()->back()->withErrors($validator);
     } else {
         /////////////////
         // check code //
         ////////////////
         $query_data['reset_password'] = request()->input('code');
         $query_data['take'] = 1;
         $check_code = json_decode($this->api->get($this->api_url . '/users?' . http_build_query($query_data))->getBody());
         /////////////////
         // assign data //
         ////////////////
         $id = $check_code->data->data[0]->_id;
         $data['password'] = request()->input('password_baru');
         $data['reset_password'] = '';
         $api_response = json_decode($this->api->post($this->api_url . '/users/update/' . $id, ['form_params' => $data])->getBody());
         //////////////
         // redirect //
         //////////////
         if (str_is('success', $api_response->status)) {
             $data = $api_response->data->data;
             //send mail
             $view = 'default.components.email.done_reset_password';
             $to = $data->email;
             $email = ['title' => 'Capcus', 'subject' => 'Reset New Password', 'data' => $data];
             MailEngine::send($view, $to, $email);
             return redirect()->route('reset.password', ['set' => 'done']);
         } else {
             $alert = $api_response->data;
             foreach ($alert as $x) {
                 $alert_str[] = implode(', ', $x);
             }
             Session::flash('_alert_danger', implode("\n", $alert_str));
             return redirect()->back()->withInput();
         }
     }
 }
Beispiel #2
0
 function subscribe()
 {
     ///////////////
     // GET EMAIL //
     ///////////////
     $email = request()->input('email');
     ///////////////
     // SUBSCRIBE //
     ///////////////
     $query['email'] = $email;
     $api_response = $this->api->get($this->api_url . '/subscription/add?' . http_build_query(array_merge($query, ['access_token' => Session::get('access_token')])))->getBody();
     $tmp = json_decode($api_response);
     if (str_is('success', $tmp->status)) {
         session()->put('subscribe', $email);
         $url = route('api.unsubscribe', ['email' => $tmp->data->data->email, 'token' => $tmp->data->data->unsubscription_token]);
         //send email
         $view = 'default.components.email.subscribe';
         $to = $email;
         $email = ['title' => 'Subscribe to Capcus', 'subject' => 'Capcus Subscription', 'data' => ['url' => $url]];
         MailEngine::send($view, $to, $email);
         return Redirect::route('subscribe');
     }
 }