Exemplo n.º 1
0
 public function updateAccount(Request $request, $id = FALSE, $action = FALSE)
 {
     $response['status'] = 'error';
     $response['message'] = trans('user_notifications.user_info_not_updated');
     if (!empty($request) && !empty($id) && !empty($action)) {
         if ($action == 'personal_info') {
             $user_data['first_name'] = !empty(Input::get('first_name')) ? Input::get('first_name') : '';
             $user_data['last_name'] = !empty(Input::get('last_name')) ? Input::get('last_name') : '';
             $user_data['phone'] = !empty(Input::get('phone')) ? Input::get('phone') : '';
             $user_data['address'] = !empty(Input::get('address')) ? Input::get('address') : '';
             $user_data['city'] = !empty(Input::get('city')) ? Input::get('city') : '';
             $user_data['state'] = !empty(Input::get('state')) ? Input::get('state') : '';
             $user_data['post_code'] = !empty(Input::get('postcode')) ? Input::get('postcode') : '';
             //				$user_data['country']    = ( ! empty(Input::get('country'))) ? Input::get('country') : '';
             if (Model_Users::updateUserInfo($id, $user_data) === TRUE) {
                 $response['status'] = 'success';
                 $response['message'] = trans('user_notifications.personal_info_updated');
             } else {
                 $response['message'] = trans('user_notifications.personal_info_not_updated');
             }
         } elseif ($action == 'change_password') {
             $user_data['password'] = !empty(Input::get('password')) ? Input::get('password') : '';
             $user_data['new_password'] = !empty(Input::get('new_password')) ? Input::get('new_password') : '';
             $user_data['re_new_password'] = !empty(Input::get('re_new_password')) ? Input::get('re_new_password') : '';
             if (!empty($user_data['password']) && !empty($user_data['new_password']) && !empty($user_data['re_new_password'])) {
                 $user = Model_Users::getSentinelUserByID($id);
                 $hasher = Sentinel::getHasher();
                 if (!Sentinel::validateCredentials($user, ['email' => $user->email, 'password' => $user_data['password']])) {
                     $response['message'] = trans('user_notifications.old_password_do_not_match');
                 } elseif ($hasher->check($user_data['password'], $user_data['new_password']) || $user_data['new_password'] != $user_data['re_new_password']) {
                     $response['message'] = trans('user_notifications.new_passwords_do_not_match');
                 } elseif (mb_strlen($user_data['new_password']) < 8) {
                     $response['status'] = 'warning';
                     $response['message'] = trans('user_notifications.password_length');
                 } else {
                     if (Sentinel::update($user, ['password' => $user_data['new_password']])) {
                         $response['status'] = 'success';
                         $response['message'] = trans('user_notifications.password_changed');
                     }
                 }
             }
         }
     }
     echo json_encode($response);
 }
 /**
  * 修改密码 - 执行修改
  */
 public function password_post()
 {
     //密码变更表单信息
     $form_data = $_POST;
     //        dump($form_data);
     //获取当前登陆用户信息
     $current_account = Sentinel::getUser();
     //        dump($current_account);
     $data = array();
     if (!$current_account) {
         return redirect()->route('account_login_get');
     }
     $data['email'] = $current_account['email'];
     $user_info = Sentinel::findByCredentials($data);
     if (!isset($form_data['password']) || $form_data['password'] == null) {
         //            dump('请输入原密码');
         return redirect()->route('account_password_get');
     }
     $data['password'] = $form_data['password'];
     $validateCredentials = Sentinel::validateCredentials($user_info, $data);
     if (!$validateCredentials) {
         //            dump('原密码有误,请重新输入');
         return redirect()->route('account_password_get');
     }
     if (!isset($form_data['new_password']) || $form_data['new_password'] == null || $form_data['new_password'] != $form_data['retype_password']) {
         //            dump('新密码有误,请重新输入');
         return redirect()->route('account_password_get');
     }
     $data['new_password'] = $form_data['new_password'];
     $flage = $this->password_logic($data);
     if ($flage) {
         //dump('密码修改成功');
         return redirect()->route('data_index');
     } else {
         //            dump('密码修改失败');
         return redirect()->route('account_password_get');
     }
 }