You are here

function security_questions_user in Security Questions 6

Same name and namespace in other branches
  1. 6.2 security_questions.module \security_questions_user()

Implements hook_user().

File

./security_questions.module, line 402
Main module file for security_questions.

Code

function security_questions_user($op, &$edit, $account, $category) {
  switch ($op) {
    case 'insert':

      // During registration, the user will have no answers in the database,
      // so we can loop through all required questions.
      $number = variable_get('security_questions_number_required', 3);
      $i = 1;

      // Insert the questions and answers into the database.
      while ($i <= $number) {
        if ($edit['security_question_id_' . $i] == 'other') {
          db_query("INSERT INTO {security_questions} (security_question, uid, admin) VALUES\n                    ('%s', %d, 0)", $edit['security_question_user_question_' . $i], $account->uid);

          // Get the question id for the question we just put in, so we can store
          // the user's answer.
          $qid = db_result(db_query("SELECT security_question_id FROM {security_questions}\n                           WHERE security_question = '%s'", $edit['security_question_user_question_' . $i]));

          // Reset the question id for input into the answers table.
          $edit['security_question_id_' . $i] = $qid;
        }
        db_query("INSERT INTO {security_questions_answers} (uid, security_question_id, user_answer) VALUES\n                  (%d, '%s', '%s')", $account->uid, $edit['security_question_id_' . $i], $edit['security_question_user_answer_' . $i]);
        $i++;
      }
      break;
  }
}