function brukar_client_login($data) { global $user; $edit = array('name' => t(variable_get('brukar_name', '!name'), array('!name' => $data['name'], '!sident' => substr($data['id'], 0, 4), '!ident' => $data['id'])), 'mail' => $data['mail'], 'status' => 1, 'data' => array('brukar' => $data)); if ($user->uid != 0) { user_save($user, $edit); user_set_authmaps($user, array('authname_brukar' => $data['id'])); drupal_goto('user'); } $authmap_user = db_query('SELECT uid FROM {authmap} WHERE module = :module AND authname = :ident', array(':ident' => $data['id'], ':module' => 'brukar'))->fetch(); if ($authmap_user === FALSE) { $provided = module_invoke_all('brukar_client_user', $edit); $user = !empty($provided) ? $provided[0] : user_save(user_load_by_mail($data['mail']), $edit); user_set_authmaps($user, array('authname_brukar' => $data['id'])); } else { $user = user_save(user_load($authmap_user->uid), $edit); } $form_state = (array) $user; user_login_submit(array(), $form_state); // Better solution available? $query = $_GET; unset($query['q']); drupal_goto($_GET['q'] == variable_get('site_frontpage') ? '<front>' : url($_GET['q'], array('absolute' => TRUE, 'query' => $query))); }
/** * Login * User can login via username or email * @param string $email, username or email adddress * @return bool $success */ public function login($email, $password) { $sucess = 0; try { if ($this->isEmail($email)) { $username = $this->getUserName($email); } else { $username = $email; } if (\user_authenticate($username, $password)) { $userObj = \user_load_by_name($username); $this->setUserData($userObj); $this->setUserId($userObj->uid); $formState = array(); $formState['uid'] = $userObj->uid; \user_login_submit(array(), $formState); $sucess = 1; } else { $this->setError("login failed, bad username or password."); } } catch (\Exception $e) { $this->setError($e->getMessage()); } return $sucess; }
function asf_ajax_login_callback($form, &$form_state) { // if errors, return the form if (form_get_errors()) { $msg = 'Sorry, unrecognized username or password.'; for ($i = 0; $i < count($_SESSION['messages']['error']); $i++) { if (strpos($_SESSION['messages']['error'][$i], $msg) !== false) { $_SESSION['messages']['error'][$i] = $msg; break; } } $form_state['rebuild'] = TRUE; return $form; } // this performs the actual login user_login_submit($form, $form_state); // this performs a redirection $path = $form_state["redirect"] . "/subscriptions"; ctools_include('ajax'); ctools_add_js('ajax-responder'); $commands[] = ctools_ajax_command_redirect($path); print ajax_render($commands); exit; }
/** * Form API submit for the site configuration form. */ function install_configure_form_submit($form, &$form_state) { global $user; variable_set('site_name', $form_state['values']['site_name']); variable_set('site_mail', $form_state['values']['site_mail']); variable_set('date_default_timezone', $form_state['values']['date_default_timezone']); variable_set('site_default_country', $form_state['values']['site_default_country']); // Enable update.module if this option was selected. if ($form_state['values']['update_status_module'][1]) { drupal_install_modules(array('update')); } // Turn this off temporarily so that we can pass a password through. variable_set('user_email_verification', FALSE); $form_state['old_values'] = $form_state['values']; $form_state['values'] = $form_state['values']['account']; // We precreated user 1 with placeholder values. Let's save the real values. $account = user_load(1); $merge_data = array('init' => $form_state['values']['mail'], 'roles' => array(), 'status' => 1); user_save($account, array_merge($form_state['values'], $merge_data)); // Load global $user and perform final login tasks. $form_state['uid'] = 1; user_login_submit(array(), $form_state); $form_state['values'] = $form_state['old_values']; unset($form_state['old_values']); variable_set('user_email_verification', TRUE); if (isset($form_state['values']['clean_url'])) { variable_set('clean_url', $form_state['values']['clean_url']); } // Record when this install ran. variable_set('install_time', $_SERVER['REQUEST_TIME']); }