/**
  * Update password
  * 
  * 1. Check new password
  * 2. Check old password
  * 3. Save password
  * @param id
  * @return redirect url
  */
 public function update()
 {
     //1. Check new password
     if (Input::has('password')) {
         $rules = ['password' => 'min:8|confirmed'];
         $validator = Validator::make(Input::only('password', 'password_confirmation'), $rules);
         if (!$validator->passes()) {
             $this->errors = $validator->errors();
             return $this->generateRedirectRoute('password.change.edit', ['id' => Input::get('password')]);
         }
     }
     //2. Check old password
     $APIMe = new APIMe();
     $me = $APIMe->getShow(true);
     if ($me['status'] != 'success') {
         \App::abort(404);
     }
     $apiUrl = '/oauth/access_token';
     $apiData = ['email' => $me['data']['email'], 'password' => Input::get('old_password'), 'grant_type' => 'password', 'client_id' => env('API_client_id'), 'client_secret' => env('API_client_secret')];
     $api = new API();
     $result = json_decode($api->post($apiUrl, $apiData), true);
     //3. Save password
     if ($result['status'] == "success") {
         Session::set('APIToken', $result['data']['token']['token']);
         Session::set('userID', $result['data']['me']['id']);
         $APIAdmin = new APIAdmin();
         $data = $APIAdmin->getShow($result['data']['me']['id']);
         $admin = $data['data'];
         if (strtotime($data['data']['date_of_birth'])) {
             $admin['date_of_birth'] = date('Y-m-d H:i:s', strtotime($data['data']['date_of_birth']));
         } else {
             $admin['date_of_birth'] = '';
         }
         $admin['password'] = Input::get('password');
         $result = $APIAdmin->postData($admin);
         //3b. Check Response
         if ($result['status'] != 'success') {
             $this->errors = $result['message'];
         }
         //3c. Return view
         if (!empty($id)) {
             $this->page_attributes->success = "Data Admin Telah Diedit";
         } else {
             $this->page_attributes->success = "Data Admin Telah Ditambahkan";
         }
         return $this->generateRedirectRoute('admin.dashboard');
     } else {
         return Redirect::route('auth.login');
     }
 }
Exemplo n.º 2
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     //1. Check input
     if (!Input::has('password')) {
         return Redirect::route('auth.login');
     }
     //2. Check password
     $APIMe = new APIMe();
     $me = $APIMe->getShow(true);
     if ($me['status'] != 'success') {
         \App::abort(404);
     }
     $apiUrl = '/oauth/access_token';
     $apiData = ['email' => $me['data']['email'], 'password' => Input::get('password'), 'grant_type' => 'password', 'client_id' => env('API_client_id'), 'client_secret' => env('API_client_secret')];
     $api = new API();
     $result = json_decode($api->post($apiUrl, $apiData), true);
     //3. Check status
     if ($result['status'] != "success") {
         return Redirect::back()->withErrors('Password tidak valid')->with('msg-type', 'danger');
     }
     Session::set('APIToken', $result['data']['token']['token']);
     Session::set('userID', $result['data']['me']['id']);
     return $next($request);
 }