Drupal 7 开发内部培训资料, 分头诗人

user_login_final_validate该怎么复写?

赞成!
0
否决!
function user_login_final_validate($form, &$form_state) {
  if (empty($form_state['uid'])) {
    // Always register an IP-based failed login event.
    flood_register_event('failed_login_attempt_ip', variable_get('user_failed_login_ip_window', 3600));
    // Register a per-user failed login event.
    if (isset($form_state['flood_control_user_identifier'])) {
      flood_register_event('failed_login_attempt_user', variable_get('user_failed_login_user_window', 21600), $form_state['flood_control_user_identifier']);
    }

    if (isset($form_state['flood_control_triggered'])) {
      if ($form_state['flood_control_triggered'] == 'user') {
        form_set_error('name', format_plural(variable_get('user_failed_login_user_limit', 5), 'Sorry, there has been more than one failed login attempt for this account. It is temporarily blocked. Try again later or <a href="@url">request a new password</a>.', 'Sorry, there have been more than @count failed login attempts for this account. It is temporarily blocked. Try again later or <a href="@url">request a new password</a>.', array('@url' => url('user/password'))));
      }
      else {
        // We did not find a uid, so the limit is IP-based.
        form_set_error('name', t('Sorry, too many failed login attempts from your IP address. This IP address is temporarily blocked. Try again later or <a href="@url">request a new password</a>.', array('@url' => url('user/password'))));
      }
    }
    else {
      form_set_error('name', t('Sorry, unrecognized username or password. <a href="@password">Have you forgotten your password?</a>', array('@password' => url('user/password'))));
      watchdog('user', 'Login attempt failed for %user.', array('%user' => $form_state['values']['name']));
    }
  }
  elseif (isset($form_state['flood_control_user_identifier'])) {
    // Clear past failures for this user so as not to block a user who might
    // log in and out more than once in an hour.
    flood_clear_event('failed_login_attempt_user', $form_state['flood_control_user_identifier']);
  }
}

上面为user.module的2176行

我想复写它,模块名为user_message_override

但是

function user_message_override_user_login_final_validate_alter(&$form, &$form_state, $form_id){

function hook_user_login_final_validate_alter(&$form, &$form_state) {

function user_message_override_user_login_final_validate_alter(&$form, &$form_state) {

都没效果?请问改怎么写才正确呢?

4 个回答

赞成!
0
否决!

只有表单有alter,所以你改错了。应该在对应的form上面改。这个是form的验证函数。

赞成!
0
否决!

请问如果我想改这个函数的话该怎么改呢?

赞成!
0
否决!

他是一个验证函数而不是一个表单函数,验证函数应该是有一个对应的表单的,你找到他对应的表单,然后重写这个表单,把验证函数改成指向你的验证函数,或者增加一个自己的验证函数。

赞成!
0
否决!

其实我只是想改下这个函数验证登陆表单后输出的内容,所以想改这个函数,如果重新给表单指定验证函数的话改,几乎每个涉及登陆注册的表单验证函数都要重新指给新函数(那我还得复写相关的表单),比较的话成本高了一些