<commit_before><?php

class BasedmUserActions extends myFrontModuleActions
{

  /**
   * Handle dmUser/signin form validation and authenticates the user
   */
  public function executeSigninWidget(dmWebRequest $request)
  {
    $form = $this->forms['DmSigninFront'];

    $user = $this->getUser();
    
    if ($user->isAuthenticated() && $this->getPage() != dmDb::table('DmPage')->getTree()->fetchRoot())
    {
      return $this->redirect('@homepage');
    }

    if ($request->isMethod('post') && $request->hasParameter($form->getName()))
    {
      if ($form->bindAndValid($request))
      {
        $user->signin($form->getValue('user'), $form->getValue('remember'));

        $this->redirectSignedInUser($request);
      }
    }
    else
    {
      if ($request->isXmlHttpRequest())
      {
        $this->getResponse()->setStatusCode(401);
        $this->getResponse()->setHeaderOnly(true);
        return sfView::NONE;
      }

      // if we have been forwarded, then the referer is the current URL
      // if not, this is the referer of the current request
      $user->setReferer($this->getContext()->getActionStack()->getSize() > 1 ? $request->getUri() : $request->getReferer());
    }
  }

  /**
   * Override this method to redirect the user to some page
   * just after he(she) successfully signed in.
   */
  protected function redirectSignedInUser(dmWebRequest $request)
  {
    $redirectUrl = $this->getUser()->getReferer($request->getReferer());

    $this->redirect('' != $redirectUrl ? $redirectUrl : '@homepage');
  }

  /**
   * Handle dmUser/form form validation and creates the user account, then authenticates the user
   */
  public function executeFormWidget(dmWebRequest $request)
  {
    $form = $this->forms['DmUser'];

    if ($request->isMethod('post') && $request->hasParameter($form->getName()))
    {
      $data = $request->getParameter($form->getName());
      
      if($form->isCaptchaEnabled())
      {
        $data = array_merge($data, array('captcha' => array(
          'recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'),
          'recaptcha_response_field'  => $request->getParameter('recaptcha_response_field'),
        )));
      }

      $form->bind($data, $request->getFiles($form->getName()));
      
      if ($form->isValid())
      {
        $user = $form->save();

        $this->getUser()->signin($user);

        $this->redirectRegisteredUser($request);
      }
    }
  }

  /**
   * Override this method to redirect the user to some page
   * just after he(she) successfully registered.
   */<commit_msg>[DmUser] fixed compatibility with Diem 5.1<commit_after><?php

class BasedmUserActions extends myFrontModuleActions
{

  /**
   * Handle dmUser/signin form validation and authenticates the user
   */
  public function executeSigninWidget(dmWebRequest $request)
  {
    $form = new DmSigninFrontForm();

    $user = $this->getUser();
    
    if ($user->isAuthenticated() && $this->getPage() != dmDb::table('DmPage')->getTree()->fetchRoot())
    {
      return $this->redirect('@homepage');
    }

    if ($request->isMethod('post') && $request->hasParameter($form->getName()))
    {
      if ($form->bindAndValid($request))
      {
        $user->signin($form->getValue('user'), $form->getValue('remember'));

        $this->redirectSignedInUser($request);
      }
    }
    else
    {
      if ($request->isXmlHttpRequest())
      {
        $this->getResponse()->setStatusCode(401);
        $this->getResponse()->setHeaderOnly(true);
        return sfView::NONE;
      }

      // if we have been forwarded, then the referer is the current URL
      // if not, this is the referer of the current request
      $user->setReferer($this->getContext()->getActionStack()->getSize() > 1 ? $request->getUri() : $request->getReferer());
    }
    
    $this->forms['DmSigninFront'] = $form;
  }

  /**
   * Override this method to redirect the user to some page
   * just after he(she) successfully signed in.
   */
  protected function redirectSignedInUser(dmWebRequest $request)
  {
    $redirectUrl = $this->getUser()->getReferer($request->getReferer());

    $this->redirect('' != $redirectUrl ? $redirectUrl : '@homepage');
  }

  /**
   * Handle dmUser/form form validation and creates the user account, then authenticates the user
   */
  public function executeFormWidget(dmWebRequest $request)
  {
    $form = new DmUserForm();

    if ($request->isMethod('post') && $request->hasParameter($form->getName()))
    {
      $data = $request->getParameter($form->getName());
      
      if($form->isCaptchaEnabled())
      {
        $data = array_merge($data, array('captcha' => array(
          'recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'),
          'recaptcha_response_field'  => $request->getParameter('recaptcha_response_field'),
        )));
      }

      $form->bind($data, $request->getFiles($form->getName()));
      
      if ($form->isValid())
      {
        $user = $form->save();

        $this->getUser()->signin($user);

        $this->redirectRegisteredUser($request);
      }
    }

    $this->forms['DmUser'] = $form;
  }

  /**
   * Override this method to redirect the user to some page
   * just after he(she) successfully registered.
   */
{'fraction_non_alphanumeric': 0.16440166100415252, 'fraction_numerical': 0.001887504718761797, 'mean_word_length': 3.0605363984674328, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 105, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6892538', 'n_tokens_mistral': 1613, 'n_tokens_neox': 1561, 'n_words': 311}