Example #1
0
 /**
  * @param string $url
  * @param string $message
  * @param string $type
  * @return \Illuminate\Http\RedirectResponse|\PeskyCMF\Http\CmfJsonResponse
  */
 function cmfRedirectResponseWithMessage($url, $message, $type = 'info')
 {
     if (request()->ajax()) {
         return cmfServiceJsonResponse()->setMessage($message)->setRedirect($url);
     } else {
         return Redirect::to($url)->with(\PeskyCMF\Config\CmfConfig::getInstance()->session_message_key(), ['message' => $message, 'type' => $type]);
     }
 }
Example #2
0
 public function replacePassword(Request $request, $accessKey)
 {
     $this->validate($request->data(), ['id' => 'required|integer|min:1', 'password' => 'required|min:6', 'password_confirm' => 'required|min:6|same:password']);
     $user = $this->getUserFromPasswordRecoveryAccessKey($accessKey);
     if (!empty($user) && $user->_getPkValue() !== $request->data('id')) {
         /** @var CmfDbObject $user */
         $user->begin()->_setFieldValue('password', $request->data('password'));
         if ($user->commit()) {
             return cmfServiceJsonResponse()->setMessage(CmfConfig::transCustom('.replace_password.password_replaced'))->setRedirect(route(CmfConfig::getInstance()->login_route()));
         } else {
             return cmfServiceJsonResponse(HttpCode::SERVER_ERROR)->setMessage(CmfConfig::transCustom('.replace_password.failed_to_save'));
         }
     } else {
         return cmfServiceJsonResponse(HttpCode::FORBIDDEN)->setMessage(CmfConfig::transCustom('.replace_password.invalid_access_key'))->setRedirect(route(CmfConfig::getInstance()->login_route()));
     }
 }
 public function deleteBulk(Request $request)
 {
     if (!$this->getScaffoldConfig()->isDeleteAllowed()) {
         return cmfServiceJsonResponse(HttpCode::FORBIDDEN)->setMessage(CmfConfig::transBase('.action.delete.forbidden'))->goBack(route('cmf_items_table', [$this->getTableNameForRoutes()]));
     }
     $model = $this->getModel();
     $conditions = $this->getConditionsForBulkActions($request, $model);
     if (!is_array($conditions)) {
         return $conditions;
         //< response
     }
     $deletedCount = $model->delete($conditions);
     $message = $deletedCount ? CmfConfig::transBase('.action.delete_bulk.success', ['count' => $deletedCount]) : CmfConfig::transBase('.action.delete_bulk.nothing_deleted');
     return cmfServiceJsonResponse()->setMessage($message)->goBack(route('cmf_items_table', [$this->getTableNameForRoutes()]));
 }